WFS图层未显示在地图上

问题描述 投票:1回答:1

我使用openlayers 6。我在地图上显示图层时遇到问题。我以GML格式将图层加载为XML并尝试显示,但该图层未在地图上显示。

这里是向量定义:

function createLayer(layer, strategy, extent, projection) {

    if (!strategy) strategy = allStrategy;
    let vsource = createSourceLayer(strategy, layer, extent, projection);
    var vector = new VectorLayer({
        source: vsource,
        visible: true,
        style: new Style({
            image: new Icon({
                src: '/images/icon-alert-blue.png',
                size: [30, 30],
            })
        })
    });
    return vector;
}

这里是向量源定义:

function createSourceLayer(strategy, layer, extent, projection) {

    let url = "url resources";
    let vectorSource = new VectorSource({
        format: new WFS({
            gmlFormat: new GML({
                featureType: "WW_MONITOR",
                featureNS: "http://www.opengis.net/wfs",
                srsName: "EPSG:2039"
            })
        }),
        loader: function (extent, resolution, projection) { 
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url);
            xhr.onload = function () {
                if (xhr.status === 200) {
                    vectorSource.addFeatures(
                        vectorSource.getFormat().readFeatures(xhr.responseText, {
                            dataProjection: projection,
                            extent: [195380.430213, 739554.42288, 207900.538587, 750611.382494]
                        })
                    );
                } else {
                    console.log("loader fail");
                }
            },
            xhr.send();
        },
        strategy: strategy
    });

    return vectorSource;
}

这里是地图定义:

    map = new Map({
        layers: [baseLayer,layer],
        view: view,
        target: 'map',
    });

这里是视图定义:

    view = new View({
        extent: [195380.430213, 739554.42288, 207900.538587, 750611.382494],
        maxResolution: 80000,
        center: [201640.48440000002, 745082.902687],
        projection: israeliTM,
        zoom: 0
    });

UPDATE:

这是我从服务器获得的GML中的单个功能示例:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xsi:schemaLocation="http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ns216630453="http://fdo.osgeo.org/schemas/feature/ns216630453"
    xmlns:wfs="http://www.opengis.net/wfs"
    xmlns:gml="http://www.opengis.net/gml">
    <!-- Feature 1 -->
    <gml:featureMember>
        <ns216630453:WW_MONITOR>
            <ns216630453:FeatId>1</ns216630453:FeatId>
            <ns216630453:Name>Donald garage</ns216630453:Name>
            <ns216630453:Street>Dundas str </ns216630453:Street>
            <ns216630453:Building>128</ns216630453:Building>
            <ns216630453:StreetCode>354</ns216630453:StreetCode>
            <ns216630453:FK_Category>11</ns216630453:FK_Category>
            <ns216630453:WaterUsing>27</ns216630453:WaterUsing>
            <ns216630453:Exceptions>0</ns216630453:Exceptions>
            <ns216630453:Geometry>
                <gml:Point>
                    <gml:coordinates>199480.000000,747711.000000</gml:coordinates>
                </gml:Point>
            </ns216630453:Geometry>
        </ns216630453:WW_MONITOR>
    </gml:featureMember>
    <!-- Feature 2 -->
    .
    .
    .
    </wfs:FeatureCollection>

以及解析后的外观:

0: Feature
    dispatching_: {}
        disposed_: false
    geometryChangeKey_: null
    geometryName_: "geometry"
    id_: undefined
    listeners_: {change: geometry: Array(1)}
    ol_uid: "130"
    pendingRemovals_: {}
    revision_: 0
    styleFunction_: undefined
    style_: null
    target_: undefined
    values_:
        Building: "128"
        Exceptions: "0"
        FK_Category: "11"
        FeatId: "1"
        Geometry:
            Point:
                coordinates: "199480.000000,747711.000000"
            __proto__: Object
        __proto__: Object
        Name: "Donald garage"
        Street: "Dundas str"
        StreetCode: "354"
        WaterUsing: "27"
    __proto__: Object
__proto__: BaseObject   

我在矢量层中使用的投影与我在视图中使用的投影相同。这里是投影的定义:

proj4.defs("EPSG:2039", "+proj=tmerc +lat_0=31.73439361111111 +lon_0=35.20451694444445 +k=1.0000067 +x_0=219529.584 +y_0=626907.39 +ellps=GRS80 +towgs84=-48,55,52,0,0,0,0 +units=m +no_defs");
register(proj4);

let israeliTM = getProjection('EPSG:2039');

知道为什么不显示地图?

gis openlayers openlayers-6
1个回答
0
投票

来源是使用GML 2.1.2的WFS 1.0.0

<wfs:FeatureCollection xsi:schemaLocation="http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd"

因此解析器格式必须指定为GML2

    format: new WFS({
        gmlFormat: new GML2({
            featureType: "WW_MONITOR",
            featureNS: "http://www.opengis.net/wfs",
            srsName: "EPSG:2039"
        })
    }),
© www.soinside.com 2019 - 2024. All rights reserved.