には、次のようなものを使用して機能要求を取得:
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");
});
'vectorSource'変数はOpenlayerの' Map'オブジェクトを指していますか? –