首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >构建查询以查找mapserver要素

构建查询以查找mapserver要素
EN

Stack Overflow用户
提问于 2019-02-03 01:43:09
回答 2查看 327关注 0票数 0

我使用的是openlayer 4.4.0,并且我正在尝试构建一个查询来查找mapserver特性并显示多边形。

我的灵感来自于这个没有成功的例子,收集了一个错误57 (我找不到在哪里可以找到openlayer 4.4的错误)。

https://openlayers.org/en/v4.6.5/examples/vector-wfs-getfeature.html

我怎样才能正确地构建这个请求?

我尝试了这个代码,得到了错误57

代码语言:javascript
运行
复制
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)
      });
EN

回答 2

Stack Overflow用户

发布于 2019-02-04 21:48:04

您正在使用and筛选器,它至少需要两个条件(正如您的错误所暗示的那样)。取消注释and函数中的第一个筛选器或仅使用equalTo筛选器。

代码语言:javascript
运行
复制
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。

票数 0
EN

Stack Overflow用户

发布于 2019-02-06 00:18:30

就目前而言,这是可行的

代码语言:javascript
运行
复制
    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());
        });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54495723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档