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

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

问题描述

我对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 Layer 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!

推荐答案

可以,但是必须复制图层

You can, but you have to duplicate the layers

// 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天全站免登陆