同一页面上的多个传单地图具有相同的选项

2022-01-12 00:00:00 leaflet javascript openlayers

我对 Leaflet.js 很陌生,我正在尝试弄清楚如何将具有相同选项和图层集的相同地图分配给不同的 HTML 容器,而不必每次都删除和添加一个新容器时间?

I'm pretty new to leaflet.js and I'm trying to figure out how to assign the same map with the same set of options and layers to a different HTML container instead of having to remove and add a new one every time?

我曾经处理 Open layers 2.13,我有 map.render(div);每次我想将地图设置为另一个 div 时的选项.有没有类似的解决方案?非常感谢!

I used to deal with Open layers 2.13 and I had map.render(div); option every time I wanted to set map to another div. Is there a solution similar to this? Many thanks!

推荐答案

可以,但是要复制图层

// add an OpenStreetMap tile layer
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

// add the same OpenStreetMap tile layer to the second map
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map2);

http://jsfiddle.net/FranceImage/aj44r7v2/

相关文章