It's my first web mapping app and I want to show features for multiple layers added to my map, I'm using Leaflet/Geoserver.

    var OpenStreetMap = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
    var WorldImagery = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}');

    var map = L.map('map', {
            layers: [OpenStreetMap], /// fond de base
            center: [30.412647, -9.579837],/// coordonnées
            zoom: 13    //// zoom par defaut

    var baseLayers = {
        "Open Street Map": OpenStreetMap,
        "World Imagery": WorldImagery

    var parcelle_layer = L.tileLayer.wms("http://localhost:8082/geoserver/test_layer/wms", {
        layers: 'test_layer:PARCELLE',
        format: 'image/png',
        transparent: true,
        version: '1.1.0',
        attribution: "myattribution"
    var cadastr_layer = L.tileLayer.wms("http://localhost:8082/geoserver/test_layer/wms", {
        layers: 'test_layer:mappe_cadastrale',
        format: 'image/png',
        transparent: true,
        version: '1.1.0',
        attribution: "myattribution"

    var overlays = {
        "PARCELLE": parcelle_layer,
        "mappe_cadastrale_": cadastr_layer,
        "Districts": district_layer,
        "Quartiers": quartier_layer,

The problem I have is that I'm trying to get the name of the activated layer "lyr_active", for example when I select "parcelle_layer" I could get features for only this layer not for all layers when I click on map.

    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='+lyr_active+'&QUERY_LAYERS='+lyr_active+'&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='450' height='500'                 frameborder='0'></iframe>");
| improve this question | | | | |
  • 1
    How do you determine which layer is "active", since you use overlays, i.e. several of them can be shown at the same time? – ghybs Oct 3 '17 at 16:22
  • that's what I'm searching about, when i select a layer to dispaly it on the map, i could get features just for this layer and when i change the selected layer i have to get features of the second layer etc.. – O. Amina Oct 4 '17 at 7:44

if I put all layers names on the URL, when i click on the map i get all features for all layers at the same time

    var URL = ',test_layer:Districts_Agadir,test_layer:Quartier_Agadir,test_layer:mappe_cadastrale_Agadir&QUERY_LAYERS=test_layer:PARCELLE,test_layer:Districts_Agadir,test_layer:Quartier_Agadir,test_layer:mappe_cadastrale_Agadir&STYLES=&BBOX='+BBOX+'&FEATURE_COUNT=5&HEIGHT='+HEIGHT+'&WIDTH='+WIDTH+'&FORMAT=image%2Fpng&INFO_FORMAT=text%2fhtml&SRS=EPSG%3A4326&X='+X+'&Y='+Y;   

enter image description here

| improve this answer | | | | |

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