1

I have a GeoJSON file with different values for the "type" attribute and I am trying to open them depending on the zoom. I have tried several possibilities but I have not been able to.

The html is like this:

L.geoJson(river, {
      onEachFeature: function (feature, layer) {
                layer.setText(feature.properties.N, {center: true,offset: -5, attributes: { fill: 'blue' }});
            },          

        style: function (feature) {

        var type = feature.properties.T
                if (type == 1) {
                return {
                color: " #ff0000 ",
                weight: 5,
                opacity:1
                }
            }
                if (type == 2) {
                return {
                color: " #088da5 ",
                weight: 5,
                opacity:1
                }
            }

                if (type == 3) {
                return {
                color: " #FFA500 ",
                weight: 3,
                opacity:1
                }
            }

                if (type == 4 ) {
                return {
                color: " #00B200 ",
                weight: 2,
                dashArray: '4, 4',                                              
                opacity:1
                }

                };
           },

    }).addTo(map);
  • 1
    What have you tried? What would be the logic of showing features depending on zoom? – TomazicM Nov 28 at 9:57
  • It could be; Type 1 and 2 with zoom >10, type 3 zoom>12 and type 4 zoom>14 – luis Dec 2 at 16:34
  • You wrote you have tried several possibilities. Please add at least one of your attempts (if not more) to your question. – TomazicM Dec 2 at 17:20

Your Answer

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

Browse other questions tagged or ask your own question.