如何更改世界地图 json 文件的中央子午线?
How to change central meridian of world map json file?
我已经加载了一个 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
工作代码here
我已经加载了一个 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
工作代码here