「Openlayers入門」Featureの使い方のメモ

1.selectFeatureクラスの作成
var select_feature_control=new Openlayers.Control.SelectFeature(vector_layer,{
multiple:false,
toggle:true,
multipleKey:’shiftKey’
});
map.addControl(select_feature_control);
select_feature_control.activate();

2.featureselectedイベント関数の定義
function select_feature(event){
document.getElmentById(‘map_feature_log’).innerHTML=”;
//Show the current selected feature (passed in from the
event object)
var display_text = ‘Clicked on: ‘
+ ‘<strong>’ + event.feature.attributes.location + ‘</
strong>’
+ ‘: ‘ + event.feature.attributes.description + ‘<hr
/>’;
document.getElementById(‘map_feature_log’).innerHTML =
display_text;

//Show all the selected features
document.getElementById(‘map_feature_log’).innerHTML += ‘All
selected features: ‘;
//Now, loop through the selected feature array
for(var i=0; i<vector_layer.selectedFeatures.length; i++){
document.getElementById(‘map_feature_log’).innerHTML
+=
vector_layer.selectedFeatures[i].attributes.
location + ‘ | ‘;
}
}
}

3.イベントの登録
vector_layer.events.register(‘featureselected’,this,selected_feature);

Comments are closed.