有人可以向我解释以下情况吗?
假设我有一个 GeoJSON 文件,其中一个多边形特征只包含四个坐标:
var json = {
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
6.55757,
45.4283625
],
[
6.50925565,
45.3728949
],
[
6.5249137,
45.3728329
],
[
6.52511385,
45.37276325
]
]
]
},
"type": "Feature",
"properties": {
"uid": "fb3f3081-c6cf-4f64-8ccb-67918a3dbe84"
}
}
]
}
现在我想把它投影到墨卡托并得到边界框:
var projection = d3.geo.mercator()
.scale(1)
.precision(0);
var path = d3.geo.path()
.projection(projection);
var pathBounds = path.bounds(json.features[0]);
var geoBounds = d3.geo.bounds(json.features[0]);
json.features[0].geometry.coordinates[0].map(function(d) {
console.log("projection:", projection(d)[0], projection(d)[1]);
});
console.log('path.bounds:', pathBounds[0][0], pathBounds[0][1])
console.log('path.bounds:', pathBounds[1][0], pathBounds[1][1])
console.log('d3.geo.bounds:', geoBounds[0][0], geoBounds[0][1])
console.log('d3.geo.bounds:', geoBounds[1][0], geoBounds[1][1])
结果不太直观。路径的边界框比任何投影点都大,地理边界框为[[-180,-90],[180,90]]
.
看起来多边形被解释为多边形之外的整个世界。这是预期的吗?为什么这样做而不是将多边形仅视为列出点内的区域?
Fiddle(打开调试器查看控制台日志):