简体   繁体   English

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

[英]OpenLayers 3 Box Selection With Polygon Shapefile Source

I am trying to get attribute information from features in a WMS Shapefile layer being served by MS4W and viewed in OpenLayers3.我试图从由 MS4W 提供服务并在 OpenLayers3 中查看的 WMS Shapefile 图层中的要素中获取属性信息。

Is there a way to get multiple feature information in one command like you can with the vector source method below?有没有办法像使用下面的矢量源方法一样在一个命令中获取多个特征信息?

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

For WMS layers served by any wms/wfs server you may execute a wms get feature request using something like the following:对于由任何 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'
                }
            );

This should give you any feature exist within the event.coordinate passed.这应该为您提供传递的event.coordinate存在的任何功能。 So you may get back all features exist within the point given.因此,您可能会取回给定点内存在的所有功能。 I think this is your only option if you have access to just WMS requests on the server.如果您只能访问服务器上的 WMS 请求,我认为这是您唯一的选择。

But if your server supports WFS requests and you have access on them you may execute a wfs request to get the features you want.但是如果您的服务器支持 WFS 请求并且您可以访问它们,您可以执行 wfs 请求来获取您想要的功能。 Something like following:类似于以下内容:

  //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");
    });

For WMS map layer we can use the function below for getting the feature while clicking on map having WMS layer:对于 WMS 地图图层,我们可以使用下面的函数在单击具有 WMS 图层的地图时获取特征:

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

Note: evt = Event of click.注意:evt = 点击事件。

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

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