地图上未显示WFS图层



我使用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中的单个feature的示例

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

知道为什么地图没有显示吗?

来源于WFS 1.0.0,它使用GML 2.1.2

<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"
})
}),

相关内容

  • 没有找到相关文章

最新更新