Javascript 使用传单将边界层添加到脱机地图

Javascript 使用传单将边界层添加到脱机地图,javascript,html,map,leaflet,openstreetmap,Javascript,Html,Map,Leaflet,Openstreetmap,我用传单和瓷砖制作了离线地图。这些平铺不包含国家边界或国家边界。我想添加所有国家的边界以及国家边界到这些瓷砖。这是构建地图的代码 var map = L.map('map').setView([33.705, -84.3900], 4); L.tileLayer('tiles/{z}/{x}/{y}.png', { attribution: '© <a>ABC</a>', maxZoom: 11,

我用传单和瓷砖制作了离线地图。这些平铺不包含国家边界或国家边界。我想添加所有国家的边界以及国家边界到这些瓷砖。这是构建地图的代码

 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);
var-map=L.map('map').setView([33.705,-84.3900],4);
L.tileLayer('tiles/{z}/{x}/{y}.png'{
归属:‘©ABC’,
maxZoom:11,
最小缩放:4
}).addTo(地图);
map.attributeControl.setPrefix(“”);
var london=新拉特宁(51.505,-0.09);
addLayer地图(伦敦);
这是没有任何边界线的地图分幅。如何使用传单添加边界层

我希望输出应该是这样的


首先,您需要定义“边界层”的点的纬度/经度对。最好是使用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);
当然,这些点需要进行逻辑分组,以便连接正确的点。请务必查看此链接