Layers and Initial Visibility

1,191 views
Skip to first unread message

Arnie Shore

unread,
Jul 22, 2013, 4:38:26 PM7/22/13
to leafl...@googlegroups.com
All,I have a number of overlay layers in my application, and these
show up fine. But now I'd like some of these not to be shown in the
initial map load, but then made visible by using the standard layer
control (I.e., those layers unchecked as the default.)

(Please be gentle; it's not my first time, but I'm still new at this.
(;-}) Thanks, all.

Arnie Shore

unread,
Jul 22, 2013, 4:42:38 PM7/22/13
to leafl...@googlegroups.com
To clarify: In the tutorial at
http://leafletjs.com/examples/layers-control.html, how wd I set, say,
Cities, not to show on page load, but Motorways to do so. AS

Bryan McBride

unread,
Jul 22, 2013, 10:48:35 PM7/22/13
to leafl...@googlegroups.com
Hi Arnie,

You're not the first to struggle with this;) Fortunately, the solution is easy- simply add the layer to the layer control, but NOT the map layer array.

var map = L.map('map', {
    center: [39.73, -104.99],
    zoom: 10,
    layers: [minimal, motorways]
});

var baseLayers = {
    "Minimal": minimal,
    "Night View": midnight
};

var overlays = {
    "Motorways": motorways,
    "Cities": cities
};

L.control.layers(baseLayers, overlays).addTo(map);

BRYAN

Michelinho

unread,
Jul 23, 2013, 4:58:03 AM7/23/13
to leafl...@googlegroups.com
Hi Bryan,
o.k., but then the order of the overlays is changed -> first all on's then all off's (logical...). Is there a way to keep the original order as they would be all on?
In my example: Wanderungen Band 1 - Band 2 - Band 3 - Band 4 - Band5?

keep order_overlay

thxalot...Michelinho

Bryan McBride

unread,
Jul 23, 2013, 10:57:11 AM7/23/13
to leafl...@googlegroups.com
Try adding them initially and then immediately removing them to preserve the layer order:

var map = L.map('map', {
center: [49.36807, 7.0697],
zoom: 8,
zoomControl: false,
layers: [landscape, iconsBd1, iconsBd2, iconsBd3, iconsBd4, iconsBd5]
});
map.removeLayer(iconsBd2).removeLayer(iconsBd4);


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "Leaflet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leaflet-js/WB54bBnQg3U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Bryan R. McBride, GISP
bryanmcbride.com

Michelinho

unread,
Jul 23, 2013, 11:27:54 AM7/23/13
to leafl...@googlegroups.com
yes, that's exact what I wanted...muchas gracias, Michelinho

Bryan McBride

unread,
Jul 23, 2013, 11:30:13 AM7/23/13
to leafl...@googlegroups.com
de nada!
Reply all
Reply to author
Forward
0 new messages