マップ外のリンクからポップアップを表示できるようにするための基本的な関数を作成しました。ポップアップを開く機能は正常に機能していますが、閉じることができません。
デモリンク:http ://www.catchingtherain.com/bikestats/stations.php-左側のタブ付きパネルのリンクをクリックします。
ここにもう少し詳細があります...
典型的な地図には、kmlから読み込まれたベクトルレイヤー「ステーション」に約300のフィーチャがあります。これらは、を使用してオンロードでアクティブ化されます
select = new OpenLayers.Control.SelectFeature(stations);
stations.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addLayer(stations);
map.addControl(select);
select.activate();
これは正常に機能します-ポップアップを開いたり閉じたりできます。
マップ外のリンクを使用して、onclick = "showMyPopup([x])を呼び出しています。[x]はkmlから読み込まれたID属性です。showMyPopup関数は次のとおりです。
function showMyPopup(myID){
for(var a = 0; a < stations.features.length; a++){ //loop through all the features
var feature = stations.features[a];
if (feature.attributes.ID.value == myID) { //until it finds the one with the matching ID attribute
var content = "<h4>" + feature.attributes.name + "</h4>" + feature.attributes.description;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(200,200),
content,
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
}
}
これにより、ステーションレイヤーから期待どおりに正しいポップアップが開き、マップ機能をクリックしてロードした場合と同じように、ステーションレイヤーのDOMインスペクターを使用してポップアップを表示できますが、閉じる方法がないようです。ただし、ステーションレイヤーの元の機能は正常に機能しています(開閉)。
どんな助けでも大歓迎です(多分これに取り組むより簡単な方法がありますか?)
ありがとう、ジェームズ
PSと念のため、これがonFeatureUnselect関数です...
function onFeatureUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}