传单:俄罗斯芬兰边境的 geoJson 覆盖错误

标签 leaflet geojson topojson

我正在使用 1:50m Cultural Vectors shape file from naturalearthdata.com .

我使用 ogr2ogr 使用以下命令创建一个 geoJson 文件:

ogr2ogr -f GeoJSON geo_world_50m.json ne_50m_admin_0_countries.shp

然后我用这个命令创建一个 topoJson 文件:
topojson --id-property iso_n3 -p name=admin -p name -p iso_a3=iso_a3 -p iso_a3 -o topo_world_50m.json geo_world_50m.json

一旦我有了我的 topoJson 文件,我就将它加载到 Leaflet 中:
$.getJSON('topo_world_50m.json', function (data) {
    var country_geojson = topojson.feature(data, data.objects.geo_world_50m);
    country_layer.addData(country_geojson);
});

我已经尝试过 1:50m 文件以及来自 Natural Earth 的 1:10m 文件。两者都给了我在芬兰边境逆转的俄罗斯的这一部分。

section of Russia that is reversed at the Finland border

任何想法如何解决这个问题?谢谢

最佳答案

所以......这是传单上的一个已知问题,我是这样解决的:

    function onEachShapeFeature(feature, layer){
        var bounds = layer.getBounds && layer.getBounds();
        // The precision might need to be adjusted depending on your data
        if (bounds && (Math.abs(bounds.getEast() + bounds.getWest())) < 0.1) {
            var latlongs = layer.getLatLngs();
            latlongs.forEach(function (shape) {
                shape.forEach(function (cord) {
                    if (cord.lng < 0) {
                        cord.lng += 360;
                    }   
                }); 
            }); 
            layer.setLatLngs(latlongs);
        }
    }
    var countries = L.geoJson(data, {
            onEachFeature: onEachShapeFeature,
    });
我知道这很糟糕……但这是我找到的最好方法。

关于传单:俄罗斯芬兰边境的 geoJson 覆盖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21561960/

相关文章:

javascript - 使用 D3.js 只渲染 topojson map 的一部分

angular - 如何在 Angular 5 应用程序中使用传单(组件)

javascript - 传单 - 导入 Geojson - Angular 6

css - D3js SVG 打开线条显示填充伪影,如何修复?

javascript - 我的 geojson 数据文件创建正确吗?

python - 我如何用 Python 解析 GeoJSON

javascript - 如何找出页面加载时间缓慢的决定因素?

javascript - 带输入框的传单地理编码

javascript - 折叠具有独占层的 Leaflet GroupedLayerControl

删除 Shiny 仪表板标题和传单 map 之间的空白