【问题标题】:Leaflet: Error in geoJson overlay at Russia Finland border传单:俄罗斯芬兰边境的 geoJson 覆盖错误
【发布时间】:2014-02-28 23:33:24
【问题描述】:

我正在使用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 文件。两者都给了我在芬兰边境反转的俄罗斯部分。

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

【问题讨论】:

  • 解决了吗?怎么样?

标签: leaflet geojson topojson


【解决方案1】:

如果你使用 geoJson 会发生什么?对于像这样的管理员 0 级地理(国家级),就详细信息而言,geoJson 可能就足够了。当您从 geo -> topo 出发时,听起来好像有些东西丢失了?

【讨论】:

  • 当我转换为 topo 时发生的问题你可能是对的。拓扑文件非常小,因此值得多做一步。作为一个临时解决方案,我已经过滤掉了俄罗斯和斐济(有同样的问题),因为我不需要他们的形状来进行这个项目。
  • 直接从shp转topojson也有这个问题。
  • 使用geojson文件修复它。
  • 很高兴听到!祝你好运。
【解决方案2】:

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

    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,
    });

我知道这很老套……但这是我找到的最好方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    相关资源
    最近更新 更多