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+","
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.setContent("<iframe src='"+URL+"' width='400' height='100' frameborder='0'></iframe>");

This is what i get as result :

enter image description here

My problem is that even if i don't select a layer and i click on the map i get the popup featured data :

enter image description here


The layers to be queried is controlled by the query_layers parameter, in your code it is


and you never change it so you will always get all the layers being queried.

  • So what should i do to show data just for the selected layer not for all overlay layers – O. Amina Jan 10 '18 at 11:52
  • change that parameter to just the selected layer name – Ian Turton Jan 10 '18 at 11:54
  • I need to define the selected layer, and i don't know how to do that – O. Amina Jan 10 '18 at 12:06
  • that's just some javascript – Ian Turton Jan 10 '18 at 12:08
  • I tried with this if (map.hasLayer(alhouda7_layer)){QUERY_LAYERS = 'test_layer:Imm_Coll_Lot_ALHOUDA_wgs84' } but still show data of this layer even if it is not shown on the map – O. Amina Jan 12 '18 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.