gpt4 book ai didi

leaflet - 如何在 leaflet.js 中切换初始层可见性

转载 作者:行者123 更新时间:2023-12-02 18:59:22 28 4
gpt4 key购买 nike

我在 leaflet.js 中创建了一个具有多个图层的 map ,但无法弄清楚如何切换一个图层以最初显示在 map 上。

Here is the link

我确信它相当简单,但就是无法弄清楚。

最佳答案

声明图层后,您需要向 map 添加一个图层,就像您对 Tilelayer 所做的那样。请参阅下面的代码。那应该有效。图层控件将计算出图层是否可见/添加到 map 中,并在列表中检查它。

var map = L.map('map').setView([52.814172, -2.079479], 9);

L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.jpg', {
maxZoom: 18,
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.'
}).addTo(map);

// Left out layer-declarations, they are HUGE

anti_soc.addTo(map); // here it is

var overlayMaps = {
"Anti-social behaviour" :anti_soc,
"Criminal damage and arson": crim_dam,
"Burglary": burg,
"Violence and sexual offences": viol,
"Other theft": other_theft,
"Vehicle crime": veh_crime,
"Shoplifting": shoplift,
"Public order": pub_ord,
"Robbery": robb,
"Bicycle theft": bikes,
"Drugs": drugs,
"Theft from the person": theft_person,
"Other crime": other_crime,
"Possession of weapons": weap
};

L.control.layers(null, overlayMaps).addTo(map);

关于leaflet - 如何在 leaflet.js 中切换初始层可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27056581/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com