如何更改世界地图json文件的中心子午线

How to change central meridian of world map json file?

本文关键字:子午线 文件 何更改 世界地图 json      更新时间:2023-09-26

我已经加载了一个世界地图的json文件,并且正在使用d3。然而,俄罗斯的一部分在地图的另一边,紧挨着阿拉斯加。

json文件是从我导出为未投影(WGS84)的shapefile创建的

有没有办法改变中央子午线,这样俄罗斯就不会分裂?我试过在d3中改变中心,但没有成功。

参考代码:

d3.json("data/world.json", function (error, myMap) {
    if (error) return console.error(errorMap);
    var myMapFeatures = topojson.feature(myMap, myMap.objects.world);
    var projection = d3.geo.mercator()
        .center([30,39])
        .scale(width*.10)
        .translate([width/2, height/2]);
    var geoProjectionPath = d3.geo.path()
        .projection(projection);
svg.selectAll("path")
    .data(myMapFeatures.features)
    .enter()
    .append("path")
    .attr("class", function(d) { 
        return "country " + d.properties.Terr_Name; 
        })
    .attr("d", geoProjectionPath);

})

您可以借助投影上的rotate来处理此问题

var projection = d3.geo.equirectangular()
 .center([30,39])
.scale(100)
.rotate([-90,0]);//this will make Russia unsplit

此处的工作代码