我使用的是openlayer 4.4.0,并且我正在尝试构建一个查询来查找mapserver特性并显示多边形。
我的灵感来自于这个没有成功的例子,收集了一个错误57 (我找不到在哪里可以找到openlayer 4.4的错误)。
https://openlayers.org/en/v4.6.5/examples/vector-wfs-getfeature.html
我怎样才能正确地构建这个请求?
我尝试了这个代码,得到了错误57
var vectorSource = new ol.source.Vector();
// generate a GetFeature request
var featureRequest = new ol.format.WFS().writeGetFeature({
srsName: 'EPSG:3857',
featureNS: 'http://www.opengis.net/wfs',
featurePrefix: 'ms',
featureTypes: ['emprise'],
outputFormat: 'application/json',
filter: ol.format.filter.and(
//ol.format.filter.like('name', 'Mississippi*'),
ol.format.filter.equalTo('numope', 'FA11163001') //example numope=='FA11163001'
)
});
// then post the request and add the received features to a layer
fetch('http://10.210.1.32:8080/cgi-bin/mapserv.exe?map=C:/ms4w/map/fond_mapserver_wfs_ol4.map', {
method: 'POST',
body: new XMLSerializer().serializeToString(featureRequest)
}).then(function(response) {
return response.json();
}).then(function(json) {
var features = new ol.format.GeoJSON().readFeatures(json);
vectorSource.addFeatures(features);
//map.getView().fit(vectorSource.getExtent());
console.log ('featuresrequest',features)
});发布于 2019-02-04 21:48:04
您正在使用and筛选器,它至少需要两个条件(正如您的错误所暗示的那样)。取消注释and函数中的第一个筛选器或仅使用equalTo筛选器。
var featureRequest = new ol.format.WFS().writeGetFeature({
srsName: 'EPSG:3857',
featureNS: 'http://www.opengis.net/wfs',
featurePrefix: 'ms',
featureTypes: ['emprise'],
outputFormat: 'application/json',
filter: ol.format.filter.equalTo('numope', 'FA11163001')
});你可以在https://openlayers.org/en/latest/doc/errors/上找到错误代码,因为他们的评论中提到了geocodezip。
发布于 2019-02-06 00:18:30
就目前而言,这是可行的
var listeNumOpe = 'numope';//document.getElementById("listeNumOpe").value;
var choixNumOpe = 'FA11139401';//document.getElementById("choixNumOpe").value;
var searchOpeUrl = "http://10.210.1.32:8080/cgi-bin/mapserv.exe?map=C:/ms4w/map/fond_mapserver_wfs_ol4.map&SERVICE=WFS&version=1.0.0&request=GetFeature&typename=emprise&Filter=<Filter><PropertyIsEqualTo><PropertyName>" + listeNumOpe + "</PropertyName><Literal>" + choixNumOpe + "</Literal></PropertyIsEqualTo></Filter>&outputFormat=geojson"
;
//----------------------------------------------------------------------------------
var vectorSource = new ol.source.Vector();
// then post the request and add the received features to a layer
fetch(searchOpeUrl).then(function(response) {
return response.json();
}).then(function(json) {
var features = new ol.format.GeoJSON().readFeatures(json,{
dataProjection: 'EPSG:2154',
featureProjection:'EPSG:3857' });
vectorSource.addFeatures(features);
map.getView().fit(vectorSource.getExtent());
});https://stackoverflow.com/questions/54495723
复制相似问题