【发布时间】:2019-05-03 14:51:31
【问题描述】:
我正在尝试创建一个 d3 SVG 来绘制纽约州的地图并对其进行缩放以适合我的 SVG 的大小,我遇到的问题是当我使用 .fitSize([height, width], mapObject) 时它只返回一个 @ 987654324@控制台报错。
我正在使用的topoJSON file of NYS
我可以在不缩放的情况下显示地图,但当然,它没有优化,需要缩放
我已经尝试过post 中所说的内容,但我还没有找到正确的解决方案
var map = d3.json('./ny.json')
Promise.all([map]).then(data => {
var height = 800;
var width = 800;
var mapData = data[0]
// original geoJSON to that works without scaling
// var geoData = topojson.feature(mapData, mapData.objects["cb_2015_new_york_county_20m"]).features
//
var geoData = topojson.feature(mapData, {
type:"GeometryCollection",
geometries: mapData.objects["cb_2015_new_york_county_20m"].geometries,
})
var projection = d3.geoMercator()
.fitSize([width, height], geoData)
var path = d3.geoPath()
.projection(projection)
d3.select('svg')
.attr('height', height)
.attr('width', width)
.selectAll('.county')
.data(geoData)
.enter()
.append('path')
.classed('.county', true)
.attr('d', path)
})
我很确定这是我的格式错误,但我不确定 .fitSize() 或 .fitExtent() 试图与哪些数据进行比较。
现在代码站点的方式我没有收到错误输出到控制台,但我也没有数据附加到 SVG
【问题讨论】:
标签: html d3.js svg geojson topojson