I want to know how can I set a "selector layer" (L.Control.Layers) outside the container in Leaflet. Like this screenshot of an OpenLayers application:
Asked
Active
Viewed 2,265 times
0
-
I see that you commented on my question, there is an answer that is working. here – Albert van Niekerk May 29 '18 at 09:07
1 Answers
0
My solution is like this:
Since you want to place it outside the map. you have to create a div and give it an id so that it can be called later.
Create a div e.g.
<div id='jpt'></div>in the body of HTML and use css to position it.<style> #jpt { position : absolute; top : 10px; right : 200px; } </style
After that in the scripts
- Initialize layer control.
c=L.control.layers(baseLayers, overlays)and then - Add to map
c.addTo(map) - Append it to previous div
$('#jpt').append(c.onAdd(map))
this will show 2 controls so
- Hide Control inside map by adding
$('.leaflet-top.leaflet-right').hidden = trueat the end of script just before</script>
neogeomat
- 8,380
- 3
- 52
- 91
-
Still error. I don't know where I set the jquery code, where I referencing it, do your reply but I have error still... Thank you so much – Basi Montes May 28 '18 at 14:24
-
-
-
-
Yes, but I want to know how can I set a "selector layer" (L.Control.Layers) outside the container in Leaflet, but I don't know how can do it – Basi Montes May 28 '18 at 16:03
-
place a div ided jpt outside the map where you want to display the selector. the code will put selector in that div. the div can be positioned anywhere using css. – neogeomat May 28 '18 at 16:09
-
How? What jpt? I have changed the code. In this link ( https://jsfiddle.net/BasiMontes/z70s44d7/ ) doesn't appear jpt. Thank you so much for your reply – Basi Montes May 28 '18 at 16:19
-
-
I'm very confused. I don't understand you well. I'm somewhat saturated, could you give me an example of code? Thanks so much – Basi Montes May 28 '18 at 17:58
-
https://jsfiddle.net/BasiMontes/spj2b0b2/ Nothing. Is it possible speaks by mail? basi_montes@hotmail.com – Basi Montes May 29 '18 at 07:45
