passing layer config in control constructor
This commit is contained in:
parent
50e36cc2cb
commit
95e0e6345c
@ -26,15 +26,21 @@
|
||||
|
||||
var map = new L.Map('map').addLayer(cloudmade).setView(new L.LatLng(50.5, 30.51), 15);
|
||||
|
||||
var marker = new L.Marker(map.getCenter());
|
||||
var marker = new L.Marker(new L.LatLng(50.5, 30.505));
|
||||
map.addLayer(marker);
|
||||
|
||||
var layersControl = new L.Control.Layers();
|
||||
map.addControl(layersControl);
|
||||
var marker2 = new L.Marker(new L.LatLng(50.502, 30.515));
|
||||
map.addLayer(marker2);
|
||||
|
||||
layersControl.addBaseLayer(cloudmade, 'CloudMade Fresh');
|
||||
layersControl.addBaseLayer(cloudmade2, 'CloudMade Pale Dawn');
|
||||
layersControl.addOverlay(marker, 'Some marker');
|
||||
var layersControl = new L.Control.Layers({
|
||||
'CloudMade Fresh': cloudmade,
|
||||
'CloudMade Pale Dawn': cloudmade2,
|
||||
}, {
|
||||
'Some marker': marker,
|
||||
'Another marker': marker2
|
||||
});
|
||||
|
||||
map.addControl(layersControl);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
@ -4,10 +4,22 @@ L.Control.Layers = L.Class.extend({
|
||||
collapsed: true
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
initialize: function(baseLayers, overlays, options) {
|
||||
L.Util.setOptions(this, options);
|
||||
|
||||
this._layers = {};
|
||||
|
||||
for (var i in baseLayers) {
|
||||
if (baseLayers.hasOwnProperty(i)) {
|
||||
this._addLayer(baseLayers[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
for (i in overlays) {
|
||||
if (overlays.hasOwnProperty(i)) {
|
||||
this._addLayer(overlays[i], i, true);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onAdd: function(map) {
|
||||
@ -28,17 +40,20 @@ L.Control.Layers = L.Class.extend({
|
||||
addBaseLayer: function(layer, name) {
|
||||
this._addLayer(layer, name);
|
||||
this._update();
|
||||
return this;
|
||||
},
|
||||
|
||||
addOverlay: function(layer, name) {
|
||||
this._addLayer(layer, name, true);
|
||||
this._update();
|
||||
return this;
|
||||
},
|
||||
|
||||
removeLayer: function(layer) {
|
||||
var id = L.Util.stamp(layer);
|
||||
delete this._layers[id];
|
||||
this._update();
|
||||
return this;
|
||||
},
|
||||
|
||||
_initLayout: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user