gpt4 book ai didi

javascript - 使用传单将边界图层添加到离线 map

转载 作者:行者123 更新时间:2023-12-02 17:01:16 25 4
gpt4 key购买 nike

我使用传单和图 block 制作了离线 map 。这些图 block 不包含国家边界或州边界。我想将所有国家边界以及州边界添加到这些图 block 中。这是构建 map 的代码。

 var map = L.map('map').setView([33.705, -84.3900], 4);
L.tileLayer('tiles/{z}/{x}/{y}.png', {
attribution: '© <a>ABC</a>',
maxZoom: 11,
minZoom: 4
}).addTo(map);

map.attributionControl.setPrefix('');
var london = new L.LatLng(51.505, -0.09);
map.addLayer(london);

这是没有任何边框线的 map 图 block 。如何使用传单添加边框层。

enter image description here

我期望输出应该是这样的

enter image description here

最佳答案

首先,您需要定义“边界层”的点的纬度/经度对。如果您有 geoJSON 格式的点,那就最好了。获得该数据后,您可以迭代这些点并将它们连接起来并创建一个图层。

var states = [{
"type": "Feature",
"properties": {"party": "Republican"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99]
]]
}
}, {
"type": "Feature",
"properties": {"party": "Democrat"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-109.05, 41.00],
[-102.06, 40.99],
[-102.03, 36.99],
[-109.04, 36.99],
[-109.05, 41.00]
]]
}
}];
L.geoJson(states, {
style: function(feature) {
switch (feature.properties.party) {
case 'Republican': return {color: "#ff0000"};
case 'Democrat': return {color: "#0000ff"};
}
}
}).addTo(map);

当然,这些点需要进行逻辑分组,以便您可以连接正确的点。请务必查看此链接 http://leafletjs.com/examples/choropleth.html

关于javascript - 使用传单将边界图层添加到离线 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25686961/

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