3

Is there a way to display specific layers in layer list when exporting map with qgis2web plugin? I have created a map with bunch of layers like roads, names of places, rivers etc. but i don't want this layers to appear on layer list. On the other hand I have layers like coffee shops, fast food restaurants, nightclubs and I want these layers on my layer list so I can toggle them on/off. I'm using OpenLayers for export.

2
  • 2
    I don't think it is possible using qgis2web. A solution would be to adjust the code in the html file. If this is an option, I could explain how to do it.
    – gHupf
    Sep 3 '19 at 8:57
  • @gHupf Yes, I would like that, if it's no trouble for you. Sep 4 '19 at 18:41
2

There is an option to do, but you have to enter in the code.

In your file layers.js you can have a list of all your layers included in your map.

Let me explain on my example. If you take a look on my legend key below:

enter image description here

You have got the same legend with one object removed as you want. Obviously, the object is still visible on the map.

Now, the bounded object - chamber appears as a separate layer in the layers.js file as per below:

   var format_Area5chamber_14 = new ol.format.GeoJSON();
   var features_Area5chamber_14 = 
   format_Area5chamber_14.readFeatures(json_Area5chamber_14, 
        {dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857'});
   var jsonSource_Area5chamber_14 = new ol.source.Vector({
   attributions: ' ',
    });
   jsonSource_Area5chamber_14.addFeatures(features_Area5chamber_14);
   var lyr_Area5chamber_14 = new ol.layer.Vector({
            declutter: true,
            source:jsonSource_Area5chamber_14, 
    maxResolution:0.42006699228392946,

            style: style_Area5chamber_14,
            interactive: true,
           title: 'Chamber<br />\
         <img src="styles/legend/Area5chamber_14_0.png" /> <br />\
         <img src="styles/legend/Area5chamber_14_1.png" /> <br />'
        });

Now, the most important section here is the title:

If you wish to have this layer removed from the layer list you have to remove all entry in the title: section, remaining it simple as title: ''.

Your final code will look as follows:

   var format_Area5chamber_14 = new ol.format.GeoJSON();
   var features_Area5chamber_14 = 
   format_Area5chamber_14.readFeatures(json_Area5chamber_14, 
        {dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857'});
    var jsonSource_Area5chamber_14 = new ol.source.Vector({
    attributions: ' ',
    });
    jsonSource_Area5chamber_14.addFeatures(features_Area5chamber_14);
    var lyr_Area5chamber_14 = new ol.layer.Vector({
            declutter: true,
            source:jsonSource_Area5chamber_14, 
     maxResolution:0.42006699228392946,

            style: style_Area5chamber_14,
            interactive: true,
           title: ''
        });

The layer is still visible on the map, as you wish, but not visible in your legend key. If you want to bring the layer back to your legend key anytime, just put something between the ''.

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.