Make leaflet layers control with checkboxes, not radio buttons? - javascript

Is there an easy way to make a leaflet layers control (L.control.layers) use checkboxes rather than radio buttons?
I have multiple WMS tile layers, and I'd like to be able to have more than one on the map at the same time. For context, the WMS tile layers include bathymetry and contours (topo lines), so it'd be more informative to visualize both at the same time, rather than just having some lines floating in the ocean.
In the leaflet example it says the layers control is "smart enough" to know which to assign radio buttons and which checkboxes, but it'd be nice to have more customized control.
Relevant code:
L.control.layers(WMS, null, {collapsed: false}).addTo(map);
where WMS is multiple L.tileLayer.wms layers.

Pass your WMS as the 2nd argument (i.e. as overlays) instead of the 1st (basemaps) of L.control.layers.
Overlays use check boxes, whereas basemaps use radio buttons.

Here i create an example to demonstrate what ghybs said.
L.control.layers(null, mixed).addTo(map);
Checkout my jsfiddle http://jsfiddle.net/iofirag/Ltub5bgv/18/.

Related

Leaflet widgets blocking bind PopUP

On my leaflet Map, I have two widgets that i want to combined together in the same map. Ive tried many things when combining my two codes but it seems that D3SvgOverlay always 'block' my Map bind PopUp.
As you can see, If I use this code "alone", the bindPOPUp are working fine.
http://blockbuilder.org/renauld94/4a704ff30993fe35e019f3184aa31399
But when Im adding my other widget http://blockbuilder.org/renauld94/81500a71a32adaa4ee09a0b26d21ee89, the bindPOPup are not working. I think I'm superposing layers (Geojson layers) and its blocking the PopUp.
Anyways to make the bind POP working by combining my two widgets 'leaflet control search' and GeoJson D3SvgOverlay?
How I combined widgets in leaflet without effecting each others? Any example will be appreciated.

How show legend(s) only for toggled layers on map?

I create map using Mapox with 7 layers thanks to this example. This layers I can switch on and switch off on the map thanks to buttons for each layers.
At the same time I don't have any spetial knowledge in Javascript. It's restrict me to create legends (div element) for each layers. The particular legend(s) must show on the fly when particular layer(s) switched on.
I found function L.mapbox.legendControl. But how it applies for my purpose?
Where and which code have to use for make legend like pictured here

Add multiple tilesets of same area to same style in mapbox

I am working on a project to show variation in NDVI values of a district in India on a fortnightly basis on Mapbox. For that I need to overlay a layer of tileset showing NDVI values of that district upon a map of India. The problem is that I have to do it for a couple of tilesets (Around 50) of the same district. One way is to use different styles for different tilesets. But it is limited to 20 styles for a free account. Other way is to use same style and overlay the different layers of 'NDVI maps' one upon other. But in that case I'm only able to see the topmost layer. Rest of the layers of same district are not visible. I see that there are two possible solutions.
Find a method to put/show a particular layer on top at a time. Rest of the layers would be below the current layer, hence would not be visible.
Find a method to automate the addition of a tileset to a style and reset the style (means delete or hide the previous added layer) and add a new layer and show it.
Please help. If the question is not clear, please inform.

Google maps styling query

I've played around with the FusionTablesLayer Wizard (http://gmaps-samples.googlecode.com/svn/trunk/fusiontables/fusiontableslayer_builder.html) to create a map of wind turbines in North Devon.
http://www.thisisnorthdevon.co.uk/images/localpeople/ugc-images/275834/binaries/WindTurbines.html
But there are two problems.
The first is that the styling that I'd created within the Fusion Table layers has not carried through. Is there a switch to force the layer to take on this styling?
The second is that I don't want the shapefile layer to be clickable. How do I turn this off?
But there are two problems.
The first is that the styling that I'd created within the Fusion Table layers has not
carried through. Is there a switch to force the layer to take on this styling?
Not sure what styling you are asking about. Is it styling defined in the FusionTable? By the FusionTables Wizard? It looks like you may be missing the application of the styles to the map this or the equivalent:
map.setOptions({styles: styles});
You might want to review the documentation on styling the map
The second is that I don't want the shapefile layer to be clickable. How do I turn this off?
To disable clicks on that FusionTablesLayer, use the suppressInfoWindows option when you construct it.
your page with infowindows suppressed on the polygon layer and styling, note that your html is invalid (no body).

Grouping layers with groext - openlayer overlays menu

i can't find out how to grup layers like in this example
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/controls.html
press the upper + button
as you can see there's a checkbox and two radio buttons
anyone knows a way to group layers so that they are displayed under the same group and it's possible to choose only one among them? (radio button)
thank you
You can try using GeoExt tree to do this, like this:
http://api.geoext.org/1.0/examples/tree.html
At this time OpenLayers does not support grouping beyond those mentioned by Brian above.
What are you trying to display on the layers? Vectors can be combined with styleMap. You might want to try is to make your layers base layers instead of overlays.
In OpenLayers there are 2 types of layers: base layers and overlays. When you add more than one of either of these to a map you get slightly different behaviour.
Base layers can only be displayed one at a time and a radio box is displayed to select which one is displayed. Check boxes are displayed for Overlays because any number of overlays can be displayed on top of a base layer. More information and examples are available on the wiki.
You

Categories