Closed geoek closed 8 years ago
What do you mean by 'checkbox position'?
Sorry for my english ! I only want to check or uncheck a legend checkbox thanks to a javascript command !
I'm confused. Your code toggle the checkbox which means it checks or unchecks it. Do you mean you want a layer to be visible but the checkbox uncheck for example? Can you explain the goal of what you want?
I need to create a button that display a layer :
In the second case, the toggle function will unselect the layer ! That's why, i'm looking for a function that display a layer whatever its initial state. (the aim is to create several button that control the display of the map, by selecting or unselecting several layers) (i think it can be done by using toggle function with conditions, but i'm sure a more simple solution should exist !)
It is a javascript/jQuery and CSS question. You should search the web for a way to create buttons and add events to them to toggle layers.
I have made a small example here http://demo.lizmap.com/lizmap_3_0/index.php/view/map/?repository=demo&project=lampadaires
A simple button is shown above the map which toggle the layer. See JS code here http://demo.lizmap.com/lizmap_3_0/index.php/view/media/getMedia?repository=demo&project=lampadaires&path=media%2Fjs%2Flampadaires%2FtoggleLayer.js
It could be improved with detection of OpenLayer layer redraw, but it does the job
Hi Mickael, Yes, i have already find your example and I try to improve it.
I can activate or deactivate a layer in the legend with this : document.querySelector("#layer-container_schematique button").className = "btn checkbox"; document.querySelector("#layer-container_schematique button").className = "btn checkbox checked";
But the layer must be refresh to update the map, and i cannot find the command to do this...
However, i manage to do what i want with conditionnal test :
// si layer1 active, on le desactive et active à la place la2 if ($('#layer-1 button.checkbox[value="1"]').hasClass('checked')) { $('#layer-1 button.checkbox[value="1"]').click(); //si layer2 non actif, on l'active if (!$('#layer-2 button.checkbox[value="2"]').hasClass('checked')) $('#layer-2 button.checkbox[value="2"]').click(); } else { // si layer1 n'est pas actif, on l'active $('#layer-1 button.checkbox[value="1"]').click(); // et on desactive layer2 if ($('#layer-2 button.checkbox[value="2"]').hasClass('checked')) $('#layer-2 button.checkbox[value="2"]').click(); }
Now, it is ok even if you activate a layer thanks to the legend.
Thanks for your help !
@geoek do you want a mutually exclusive display ? Like groups in QGIS ?
Yes, It will be perfect if the group mutually exclusive display of QGis was available in Lizmap !
Thanks :)
it is already a requested feature #37 Take a look at it
Is it possible to control the display of a layer thanks to additionnal JS code ?
I can toggle a layer thanks to the following fonction : $('#layer-xxx button.checkbox[value="xxx"]').click()
But i'd like to force the checkbox position (true or false). Is it possible ?
Thanks a lot !