同一页面上的多个传单地图具有相同的选项 [英] Multiple Leaflet maps on same page with same options

查看:12
本文介绍了同一页面上的多个传单地图具有相同的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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/

这篇关于同一页面上的多个传单地图具有相同的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆