4

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

使用 ol.geom.Polygon.fromExtent 并将结果添加到矢量源似乎不起作用。请有人能说明如何做到这一点?

4

1 回答 1

2

经过大量的尝试和错误,终于找到了一种方法......

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]);
于 2017-09-29T10:36:58.987 回答