Leaflet problem including all layers in Overlay

329 views
Skip to first unread message

Gorka Sanz Monllor

unread,
Sep 3, 2020, 12:53:40 PM9/3/20
to Leaflet
Hello , I am working with leaflet 1.3.1 in Angular2. In the overlays menu , I have tried to add a special options for viewing all the layers, but the main problem is how to check/uncheck the
checkboxes of the overlay menu. When I check view all layers and uncheck it the other layers are not checked/unchecked. I have to check/uncheck all the checkboxes by the code manually but I could not do it using
the following events :

this.map.on('overlayremove',function(e){....})
this.map.on('overlayadd',function(e){......})

Any idea on how to do it ?
thanks
Gorka

mahendher ma

unread,
Sep 3, 2020, 1:51:16 PM9/3/20
to Leaflet
how can i apply Geotiff raster image on different map its in australia region need to apply in canada this same raster image https://github.com/stuartmatthews/leaflet-geotiff   

Edwin Corrigan

unread,
Sep 4, 2020, 6:49:31 AM9/4/20
to leafl...@googlegroups.com
Hi Gorka, 

I think I understand what you would like to do, some options:

1) If you want to remove the layer from the layer control (I think this is what you mean by overlay menu) and the map:
    - You can use map.eachLayer https://leafletjs.com/reference-1.6.0.html#map-eachlayer) function within your 'overlayRemove' listener. 
    - Then you have access to remove each layer from the map with layer with remove layer - (https://leafletjs.com/reference-1.6.0.html#map-removelayer)

2) If you want a grouped layer control, you can pretty much interchange the default leaflet layer control (described here https://leafletjs.com/examples/layers-control/) with this grouped layer control plugin - https://github.com/ismyrnow/leaflet-groupedlayercontrol

AVISO LEGAL: Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario, 

pudiendo contener información confidencial sometida a secreto profesional. No está permitida su comunicación, reproducción o distribución sin la autorización expresa de PAVAPARK MOVILIDAD, S.L.. Si usted no es el destinatario final, por favor elimínelo e infórmenos por esta vía.




PROTECCIÓN DE DATOS: De conformidad con lo dispuesto en el Reglamento (UE) 2016/679 de 27 de abril (GDPR) y la Ley Orgánica 3/2018 de 5 de diciembre (LOPDGDD), le informamos que los datos personales y dirección de correo electrónico del interesado, serán tratados bajo la responsabilidad de PAVAPARK MOVILIDAD, S.L. por un interés legítimo y para el envío de comunicaciones sobre nuestros productos y servicios y se conservarán mientras ninguna de las partes se oponga a ello. Los datos no serán comunicados a terceros, salvo obligación legal. Le informamos que puede ejercer los derechos de acceso, rectificación, portabilidad y supresión de sus datos y los de limitación y oposición a su tratamiento dirigiéndose a C/ Tres Forques, 149 - 46014 Valencia (Valencia). Email: d...@pavasal.com. Si considera que el tratamiento no se ajusta a la normativa vigente, podrá presentar una reclamación ante la autoridad de control en www.aepd.es.


Antes de imprimir este correo electrónico piense bien si es necesario hacerlo. 

El medio ambiente es cosa de todos.


--

---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leaflet-js/a13150a0-7c9b-4511-9d1b-153349b567d4n%40googlegroups.com.

Gorka Sanz Monllor

unread,
Sep 4, 2020, 9:05:05 AM9/4/20
to Leaflet
Hello ai have tried the opition you said but I have the following problem :
when I try to access to the overlayremove method, I cannot access to the map inside it:


           this.map.on('overlayremove',function(e){  
            this.map.eachlayer(layer){
this.map.removeLayer(layer)
}
              

        })

Any idea ? Thanks 
Gorka

Edwin Corrigan

unread,
Sep 4, 2020, 9:39:30 AM9/4/20
to leafl...@googlegroups.com
I think the eachLayer is similar to a forEach() iterator, so you'd need to do something like this:        

   const self = this;
   this.map.on('overlayremove',function(e){  
      self.map.eachlayer(layer => {
  self.map.removeLayer(layer)
  })
  })

or use arrow functions: 

   this.map.on('overlayremove', (e) => {  
      this.map.eachlayer(layer => {
  this.map.removeLayer(layer)
  })
  })

FYI, haven't tested this. 



--

Edwin Corrigan

+353 (0)91 704 885
edwin.c...@siren.io
www.siren.io
Unit 3, GTC, Mervue Business Park, Galway, H91 CR20, Ireland
twitteryoutubelinkedin
Reply all
Reply to author
Forward
0 new messages