Leaflet: Error in geoJson overlay at Russia Finland border

前端 未结 2 1784
故里飘歌
故里飘歌 2021-01-19 23:35

I\'m using the 1:50m Cultural Vectors shape file from naturalearthdata.com.

I use ogr2ogr to create a geoJson file with the following command:

ogr2og         


        
相关标签:
2条回答
  • 2021-01-19 23:59

    What happens if you use the geoJson? For admin 0 level geographies like this (country level) a geoJson might suffice in terms of detail. It sounds like something is being lost when you go from geo -> topo?

    0 讨论(0)
  • 2021-01-20 00:03

    So... this is a known issue on leaflet, I solved this way:

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

    I know that is hacky... but was the best way I found.

    0 讨论(0)
提交回复
热议问题