缩放到没有 topoJSON 的边界框
Zoom to bounding box without topoJSON
Mike Bostock 'Zoom to bounding box' 示例假定您使用的是 topoJSON。
https://bl.ocks.org/mbostock/4699541
如何修改脚本以便您也可以将其用于 geoJSON 数据?具体来说,我的脚本不会使用以下内容:
.data(topojson.feature(us, us.objects.states).features)
但像这样:
.data(collection.features)
该块实际上已经使用了 geojson - d3 geoPath 不绘制 topojson 对象,它绘制 geojson 对象:
path(object[, arguments…]) <>
Renders the given object, which may be any GeoJSON feature or geometry
object
... (link)
让我们看看你的例子:
.data(topojson.feature(us, us.objects.states).features)
topojson.feature(us, us.objects.states)
returns一个特征集合,一个geojson特征集合。
.features
访问要素集合的要素(在本例中为多边形数组)。
被馈送到 .data()
的是 已经是 geojson。所以我们可以按照你的建议使用 .data(geojson.features)
(如果我们有一个特征集合,否则我们可以只使用一组 geojson 对象)。
我们可以用您的示例通过两种方式证明这一点 - 在浏览器中使用 topojson 将您的数据预先转换为 geojson here, or we can load a geojson file and drop the conversion from topojson altogether, as seen here。
Mike Bostock 'Zoom to bounding box' 示例假定您使用的是 topoJSON。
https://bl.ocks.org/mbostock/4699541
如何修改脚本以便您也可以将其用于 geoJSON 数据?具体来说,我的脚本不会使用以下内容:
.data(topojson.feature(us, us.objects.states).features)
但像这样:
.data(collection.features)
该块实际上已经使用了 geojson - d3 geoPath 不绘制 topojson 对象,它绘制 geojson 对象:
path(object[, arguments…]) <>
Renders the given object, which may be any GeoJSON feature or geometry object
... (link)
让我们看看你的例子:
.data(topojson.feature(us, us.objects.states).features)
topojson.feature(us, us.objects.states)
returns一个特征集合,一个geojson特征集合。
.features
访问要素集合的要素(在本例中为多边形数组)。
被馈送到 .data()
的是 已经是 geojson。所以我们可以按照你的建议使用 .data(geojson.features)
(如果我们有一个特征集合,否则我们可以只使用一组 geojson 对象)。
我们可以用您的示例通过两种方式证明这一点 - 在浏览器中使用 topojson 将您的数据预先转换为 geojson here, or we can load a geojson file and drop the conversion from topojson altogether, as seen here。