2016-09-12 3 views
2

MS4Wがサービスを受け、OpenLayers3で表示されているWMSシェイプファイルレイヤのフィーチャから属性情報を取得しようとしています。OpenLayers 3 Box Selection with Polygon Shapefile Source

以下のベクターソースメソッドでできるように、1つのコマンドで複数の機能情報を取得する方法はありますか?あなたがWMSを実行する可能性のあるWMS/WFSサーバが提供するWMSレイヤの場合

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

'vectorSource'変数はOpenlayerの' Map'オブジェクトを指していますか? –

答えて

0

には、次のようなものを使用して機能要求を取得:

  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"); 
    }); 
関連する問題