gpt4 book ai didi

javascript - 从 ol.extent.boundingExtent 创建特征?

转载 作者:行者123 更新时间:2023-11-29 23:35:38 24 4
gpt4 key购买 nike

在 openlayers 3 应用程序中,我能够检索边界范围并适合 View 。但是我现在想通过使用边界范围来创建要素/多边形。

    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);

使用 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]);

关于javascript - 从 ol.extent.boundingExtent 创建特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46414184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com