【问题标题】:Openlayers wont show features in a layer when using loader使用加载器时,Openlayers 不会在图层中显示特征
【发布时间】:2021-01-25 08:25:26
【问题描述】:

所以我开始了这个:loadingstrategy bbox,所以当我平移和缩放时加载器会获取特征。但问题是,即使我从 http 请求中获取了这些功能,它也不会以某种方式显示出来。

我的逻辑:

       source = new VectorSource({

            loader: (extent, resolution, projection) => {
                let url ='api_url'
                let xhr = new XMLHttpRequest();
                xhr.open('GET', url);
                let onError = () => {
                    source.removeLoadedExtent(extent);
                    console.log('error');
                };
                xhr.onerror = onError;
                xhr.onload = () => {
                    if (xhr.status === 200) {
                        let features = new GeoJSON({
                            featureProjection: 'EPSG:32633',
                        }).readFeatures(xhr.responseText);
                        source.addFeatures(features);
                        source.changed();
                        console.log(
                            this.Map.getLayers().getArray(),
                            (this.Map.getLayers()
                                .getArray()
                                .find(
                                    (l) => l.get('name') === 'propertyLayer'
                                ) as VectorLayer)
                                .getSource()
                                .getFeatures()
                        );
                    } else {
                        console.log('error');
                    }
                };
                xhr.send();
            },
            strategy: bbox,
            format: new GeoJSON({
                featureProjection: GetProjection('EPSG:32633'),
                dataProjection: GetProjection('EPSG:32633'),
            }),
        });
        const styles = [
            new Style({
                stroke: new Stroke({
                    color: 'blue',
                    width: 3,
                }),
                fill: new Fill({
                    color: 'rgba(0, 0, 255, 0.1)',
                }),
            }),
            new Style({
                image: new CircleStyle({
                    radius: 6,
                    fill: new Fill({
                       color: '#3399CC',
                    }),
                    stroke: new Stroke({
                       color: '#fff',
                       width: 2,
                    }),
                }),
            }),
        ];
        let vLayer = new VectorLayer({
        source: source,
        style: styles,
        });
        this.Map.addLayer(vLayer);

我在 onload 函数中的 console.log 显示了很多功能,所以我知道它被获取了。 第一个日志以数组格式列出层。获得特征的层是最后一层,可能是其他层具有更高的 z-index 值吗?或者我可能需要刷新/重绘添加所有功能的图层?

【问题讨论】:

    标签: angular openlayers geojson


    【解决方案1】:

    代替

                        let features = new GeoJSON({
                            featureProjection: 'EPSG:32633',
                        }).readFeatures(xhr.responseText);
    

    也包括dataProjection,或者如果两个投影相同,也不要指定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 2023-04-06
      相关资源
      最近更新 更多