繁体   English   中英

具有多边形形状文件源的 OpenLayers 3 框选择

[英]OpenLayers 3 Box Selection With Polygon Shapefile Source

我试图从由 MS4W 提供服务并在 OpenLayers3 中查看的 WMS Shapefile 图层中的要素中获取属性信息。

有没有办法像使用下面的矢量源方法一样在一个命令中获取多个特征信息?

vectorSource.forEachFeatureIntersectingExtent(extent, function(feature) {
          selectedFeatures.push(feature);
          info.push(feature.get('name'));

对于由任何 wms/wfs 服务器提供的 WMS 图层,您可以使用以下内容执行 wms get 功能请求:

         var url = myWMSLayer
            .getSource()
            .getGetFeatureInfoUrl(
                evt.coordinate,
                map.getView().getResolution(),
                map.getView().getProjection(),
                {
                    'INFO_FORMAT': 'application/json',
                    'propertyName': 'ATTR1,ATTR2,ATTR3'
                }
            );

这应该为您提供传递的event.coordinate存在的任何功能。 因此,您可能会取回给定点内存在的所有功能。 如果您只能访问服务器上的 WMS 请求,我认为这是您唯一的选择。

但是如果您的服务器支持 WFS 请求并且您可以访问它们,您可以执行 wfs 请求来获取您想要的功能。 类似于以下内容:

  //here is the rectangle to search for fetaures
  var extent [-8876804.07807116, 5368955.976007851, -8866790.827365803, 5374688.75312924];
  $.ajax('http://demo.opengeo.org/geoserver/wfs', {
        type: 'GET',
        data: {
            service: 'WFS',
            version: '1.1.0',
            request: 'GetFeature',
            typename: 'mylayer',
            srsname: 'EPSG:3857',
            bbox: extent.join(',') + ',EPSG:3857'
        }
    }).done(function(resp){
    //you may parse the responce back here 
    var formatWFS = new ol.format.WFS();
    var feats = formatWFS.readFeatures(resp);
    //now you can iterate through your features and get the attrs
    for (var i=0;i<feats.length;i++){
    console.log(feats[i].get('ATTR1'));
    }    
    }).fail(function () {
        alert("fail loading features");
    });

对于 WMS 地图图层,我们可以使用下面的函数在单击具有 WMS 图层的地图时获取特征:

map.forEachFeatureAtPixel(evt.pixel, function(feature, layer)
{
//Do your logic 
}

注意:evt = 点击事件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM