簡體   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