Jus*_*tin 7 javascript geojson bounds d3.js
我已经成功加载了将要素集加载到的geoJSON文件中
d3.geo.path()
Run Code Online (Sandbox Code Playgroud)
我当前实现的问题是它开始缩放,使得路径是一个点,我必须每次放大.现在我知道有很多方法可以正确设置缩放级别,但我希望能够使用
d3.geo.bounds()
Run Code Online (Sandbox Code Playgroud)
鉴于以下geoJSON功能:
json.features[0]:
Object
geometry: Object
coordinates: Array[2]
0: -71.248913
1: 44.078426
length: 2
__proto__: Array[0]
type: "Point"
__proto__: Object
id: 2
type: "Feature"
__proto__: Object
Run Code Online (Sandbox Code Playgroud)
和
json.features[1]:
Object
geometry: Object
coordinates: Array[2]
0: -71.249021
1: 44.078387
length: 2
__proto__: Array[0]
type: "Point"
__proto__: Object
id: 3
type: "Feature"
__proto__: Object
Run Code Online (Sandbox Code Playgroud)
如果我执行
d3.geo.bounds(json.features)
Run Code Online (Sandbox Code Playgroud)
我得到无限的界限:
d3.geo.bounds(json.features)
[
Array[2]
0: Infinity
1: Infinity
length: 2
__proto__: Array[0]
,
Array[2]
0: -Infinity
1: -Infinity
length: 2
__proto__: Array[0]
]
Run Code Online (Sandbox Code Playgroud)
我不确定是什么问题,显然我有一个比上面更大的数据集,但我只是想了解输出.这个输出对我来说没有意义,显然缺少关于d3处理geoJSON数据的简单方法.任何帮助以获得工作的帮助都会有所帮助.
谢谢.
Lar*_*off 13
d3.geo.bounds
将单个Feature或FeatureCollection作为参数,而不是一系列要素.请参阅文档.你需要打个电话
d3.geo.bounds(json.features[0])
Run Code Online (Sandbox Code Playgroud)
如果你想要一个包含所有特征的边界框,你需要依次得到每个特征的边界框,然后计算它们的并集.