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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| var queryableLayers=viewer.getMap().getLayersByClass("OpenLayers.Layer.WMS");
for (var i=(queryableLayers.length-1);i>=0;i--){
if (queryableLayers[i].queryable!=true){
queryableLayers.splice(i);
}
}
var wiCntrl= new OpenLayers.Control.WMSGetFeatureInfo({
uiOptions:{title:'olControlWMSGetFeatureInfo.title'},
queryVisible: true,
layers: queryableLayers,
maxFeatures: 10,
infoFormat:'text/plain',
eventListeners: {
getfeatureinfo: function(evt) {
//this===control
var txt= '';
if (typeof(evt.features)!='undefined') {
for (var i= 0, l= evt.features.length; i<l; i++) {
var T= Geoportal.Control.renderFeatureAttributes(evt.features[i]);
txt+= '<div class="gpPopupHead">' + T[0] + '</div>' +
'<div class="gpPopupBody">' + T[1] + '</div>';
}
} else {
if (evt.text) {
var txt=
evt.object.infoFormat=='text/plain'?
'<div class="gpPopupBody">' +
evt.text.replace(/[\r\n]/g,'<br/>').replace(/ /g,' ') +
'</div>'
: evt.text;
}
}
if (txt) {
this.map.addPopup(new OpenLayers.Popup.FramedCloud(
"chicken",
this.map.getLonLatFromPixel(evt.xy),
null,
Geoportal.Util.cleanContent(txt),
null,
true));
}
}
}
});
//ce qui nous intéresse commence ici
var clickCtrlOpts= {
onSelect: selection,
onUnselect: deselection,
autoActivate: true
};
var vectorLayers= viewer.getMap().getLayersByClass('OpenLayers.Layer.Vector') ;
var hoverCtrl= new OpenLayers.Control.SelectFeature(vectorLayers, clickCtrlOpts);
viewer.getMap().addControl(hoverCtrl);
/**
* fonction appelée lors du click sur un objet vecteur
* f - objet sélectionné lors du click
*/
function selection(f) {
console.log(f.attributes);
f.popup= new OpenLayers.Popup.FramedCloud(
"id",
f.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(50,50),
f.attributes.description
);
viewer.getMap().addPopup(f.popup);
};
function deselection(f) {
if (f.popup) {
f.popup.destroy() ;
}
}; |
Partager