1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
//variable globale:
var selectedFeature;
//fonction de création de popup:
function createPopup(feature) {
feature.createPopup= function() {
var popupContent= 'contenu';
var popup= new OpenLayers.Popup.Anchored("chicken",
this.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(250,150),
popupContent, null, true, onPopupClose);
this.popup= popup;
}.bind(feature);
}
//fonction de fermeture de popup:
//stop propagation de l'évènement
//cache la popup
//redessine l'objet
//nettoyage
//émission évènement desélection
function onPopupClose(evt) {
OpenLayers.Event.stop(evt);
this.hide();
selectedFeature.layer.drawFeature(selectedFeature, "default");
OpenLayers.Util.removeItem(selectedFeature.layer.selectedFeatures, selectedFeature);
selectedFeature.layer.events.triggerEvent("featureunselected", {feature: selectedFeature});
onFeatureUnselect(selectedFeature);
}// onPopupClose
//callback de l'évènement "featureselected" :
function onFeatureSelect(feature) {
selectedFeature= feature;
if (!selectedFeature.popup) {
selectedFeature.createPopup();
}
viewer.getMap().addPopup(selectedFeature.popup);
}// onFeatureSelect
//callback de l'évènement "featureunselected" :
function onFeatureUnselect(feature) {
viewer.getMap().removePopup(feature.popup);
feature.popup.destroy();
feature.popup= null;
}// onFeatureUnselect
//création de la couche KML/GPX :
var l= MAP.getMap().addLayer(
new OpenLayers.Layer.Vector(
"nom de la couche",
{
projection: MAP.getMap().getProjection(),
onFeatureInsert: createPopup,
format: OpenLayers.Format.KML,
formatOptions:{
internalProjection: MAP.getMap().getProjection()
}
}
)
); |
Partager