【问题标题】:WFS layer not displayed on the mapWFS 图层未显示在地图上
【发布时间】:2019-10-28 11:24:07
【问题描述】:

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

更新:

这是我从服务器获取的 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');

知道为什么地图不显示吗​​?

【问题讨论】:

  • 如果不访问您的数据,很难知道它是否正在被解析,例如它可能与“简单功能”要求不兼容,或者它是否已加载但显示在错误的位置 -传递给加载器的投影是视图投影,因此您需要featureProjection: projection(在您的情况下,它与 dataProjection 相同)。您只需要基于像素的矢量切片的范围,但指定它应该不是问题。
  • @Mike,感谢您的帖子。我添加了有关我的问题的其他信息。请参阅更新。
  • 您有 WFS 1.0.0 和 GML 2.1.2,因此您需要将 new GML({ 替换为 new GML2({
  • @Mike,谢谢它的工作。如果你发帖,我会接受它作为答案。

标签: gis openlayers openlayers-6


【解决方案1】:

来源是使用 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"
        })
    }),

【讨论】:

    猜你喜欢
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2015-08-03
    • 1970-01-01
    • 2019-03-26
    • 2019-08-06
    相关资源
    最近更新 更多