[英]Load markers before map
I'm trying to reproduce Foursquare's web user interface. 我正在尝试重现Foursquare的Web用户界面。
What I noticed is that on the tip map, the markers are load way before the map was loaded. 我注意到的是,在地图上,标记是在加载地图之前的加载方式。
is this possible with leaflet ? 传单有可能吗? With this piece of code, I don't think it's possible 有了这段代码,我认为这是不可能的
L.marker([lat, lng], {icon: iconMarker}).addTo(map);
How are they doing it? 他们是怎么做到的?
I think I know how: They're loading the Tiles after positioning the markers, something like : 我想我知道如何:他们在定位标记后加载瓷砖,例如:
markers = L.marker([lat, lng], {icon: iconMarker}).addTo(map);
L.tileLayer('https://{s}.tiles.mapbox.com/v4/MapID/{z}/{x}/{y}.png?access_token=Token').addTo(map);
Ofcourse, just as long as the Leaflet library is loaded, you can create markers, layers, polygons, whatever. 当然,只要加载Leaflet库,您就可以创建标记,图层,多边形等等。 There doesn't have to be an instance of L.Map
to do this. 没有L.Map
的实例可以做到这一点。
// Define marker first
var marker = L.marker([0,0]);
// Define map later
var map = L.map('map', {
'center': [0, 0],
'zoom': 1,
'layers': [
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
'attribution': 'Map data © OpenStreetMap contributors'
})
]
});
// Add afterwards
marker.addTo(map);
Working example on Plunker: http://plnkr.co/edit/0zaogf?p=preview 关于Plunker的工作示例: http ://plnkr.co/edit/0zaogf?p = preview
Or include the marker when defining the map: 或者在定义地图时包含标记:
// Define marker first
var marker = L.marker([0,0]);
// Define map later include marker
var map = L.map('map', {
'center': [0, 0],
'zoom': 1,
'layers': [
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
'attribution': 'Map data © OpenStreetMap contributors'
}),
marker
]
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.