It's my first webmapping application using GEOSERVER & LEAFLET. I have 5 overlay layers and i want to show features of each layer using this code :
map.addEventListener('click', onMapClick);
popup = new L.Popup({maxWidth: 1000});
function onMapClick(e) {
var latlngStr = '(' + e.latlng.lat.toFixed(3) + ', ' + e.latlng.lng.toFixed(3) + ')';
var BBOX = map.getBounds()._southWest.lng+","+map.getBounds()._southWest.lat+","+map.getBounds()._northEast.lng+","
+map.getBounds()._northEast.lat;
var WIDTH= map.getSize().x;
var HEIGHT = map.getSize().y;
var X = map.layerPointToContainerPoint(e.layerPoint).x;
var Y = map.layerPointToContainerPoint(e.layerPoint).y;
var URL = 'http://localhost:8082/geoserver/test_layer/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=test_layer:Imm_Coll_Lot_ALHOUDA_wgs84,test_layer:Villa_Lot_ALHOUDA_wgs84,test_layer:Eco_Lot_ALHOUDA_wgs84,test_layer:Equip_Lot_ALHOUDA_wgs84,test_layer:Rec_Lot_ALHOUDA_wgs84&QUERY_LAYERS=test_layer:Imm_Coll_Lot_ALHOUDA_wgs84,test_layer:Villa_Lot_ALHOUDA_wgs84,test_layer:Eco_Lot_ALHOUDA_wgs84,test_layer:Equip_Lot_ALHOUDA_wgs84,test_layer:Rec_Lot_ALHOUDA_wgs84&propertyName=Zone_Urb,Type_Urb&STYLES=&BBOX='+BBOX+'&FEATURE_COUNT=5&HEIGHT='+HEIGHT+'&WIDTH='+WIDTH+'&FORMAT=image%2Fpng&INFO_FORMAT=text%2fhtml&SRS=EPSG%3A4326&X='+X+'&Y='+Y;
popup.setLatLng(e.latlng);
popup.setContent("<iframe src='"+URL+"' width='400' height='100' frameborder='0'></iframe>");
map.openPopup(popup);
}
This is what i get as result :
My problem is that even if i don't select a layer and i click on the map i get the popup featured data :