简体   繁体   中英

How to add map control with leaflet?

I'm struggling with turning on the Map Control in Leaflet.

Staring at the example doesn't seem to help. I know I must be making a stupid mistake, but I can't figure it out.

http://leaflet.cloudmade.com/examples/layers-control.html

I've got my map, and it loads, displays ok, but at the addTo(map) method I get the error:

Uncaught TypeError: Cannot call method 'addTo' of undefined

Any ideas what I'm missing?

var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var street_layer = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 18, attribution: osmAttrib});
map = new L.Map('map',{
                center: initial_center,
                zoom: initial_zoom,
                layers: mapLayersList    
});
var baseMaps = {"Streets": street_layer};
L.Control.Layers(baseMaps, null).addTo(map);
L.Control.Layers(baseMaps, null).addTo(map);

is wrong. It is

L.control.layers(baseMaps, null).addTo(map);

You can check out the script's jsfiddle here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM