我用传单和瓷砖制作了离线地图。这些瓷砖不包含国家边界或州边界。我想在这些瓷砖中添加所有国家边界以及国家边界。这是建筑地图的代码。
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);这是没有任何边界线的贴图。如何使用传单添加边框层。

我希望输出应该看起来像

发布于 2014-09-05 14:49:10
首先,您需要定义“边界层”的点的纬度/经度对。如果您在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
https://stackoverflow.com/questions/25686961
复制相似问题