vic*_*yso 5 javascript openlayers extent angular
在 openlayers 3 应用程序中,我能够检索边界范围并适合视图。不过,我现在想通过使用边界范围来创建要素/多边形。
let boundingExtent = ol.extent.boundingExtent([[left, bottom], [right, top]]);
//??/let polygon = ol.geom.Polygon.fromExtent(boundingExtent);
var view = this.map.getView();
view.fit(boundingExtent, null);
//let source = this.vectorSource.getSource();
//source.clear();
//feature.setStyle(this.VectorAltStyles);
//source.addFeatures(feature);
Run Code Online (Sandbox Code Playgroud)
使用 ol.geom.Polygon.fromExtent 并将结果添加到矢量源似乎不起作用。请问有人可以阐明如何实现这一目标吗?
经过多次尝试终于找到了方法...
let boundingExtent = ol.extent.boundingExtent([[left, bottom], [right, top]]),
polygon = ol.geom.Polygon.fromExtent(boundingExtent),
feature = new ol.Feature(polygon);
let source = this.vectorSource.getSource();
source.clear();
feature.setStyle(this.VectorStyles);
source.addFeatures([feature]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3271 次 |
| 最近记录: |