简体   繁体   中英

Leaflet.js & Mapbox.js - Uncaught TypeError: Object [object Object] has no method 'on'

I'm using Mapbox, which is based on Leaflet.js to generate my maps. I'm trying to add a layer group to my map. But every time I call .addTo(map), I get

Uncaught TypeError: Object [object Object] has no method 'on' 

My code is as follows:

map = L.mapbox.map("map", "dannyvaughton.map-lmwtrr8k").setView([54.4, 0.43], 14)
markers = new L.LayerGroup().addTo(map)

Thanks.

try:

markers = L.layerGroup().addTo(map);

notice the lower camel case on layerGroup

You can't call .addTo on an object that isn't instantiated yet, you're alternative would be:

markers = new L.LayerGroup();
markers.addTo(map);

http://leafletjs.com/reference.html#layergroup

将您的MapBox.js版本更新为1.0.4-这是此更新中已修复的错误。

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