D3.js未在topojson中显示所有地图元素
答:我已经下载了两个geojsons
- 地图
- 美国
。
世界 $ GEOJSON-MERGE GZ_2010_US_040_20M.JSON custom.geo.json> commined.json
C.我然后将world_map_with_usa_states.json
转换为mapshaper.org上的topojson,
加载world_map_with_with_usa_states.json.json
on https://mapshaper.org/ 向美国和其他国家/地区显示
,但D3.js并未显示美国州
d3.js代码
let mapURl = 'world_map_with_USA_states.json'
let countriesData
const width = 900
const height = 600
const svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height)
const projection = d3.geoMercator().scale(140)
.translate([width/2, height/1.4])
const path = d3.geoPath(projection)
const g = svg.append('g')
d3.json(mapURl)
.then((data, error) =>{
if (error){
console.log(error)
}else{
console.log(data)
countriesData = topojson.feature(data, data.objects.combined)
g.selectAll('path').data(countriesData.features).enter().append('path')
.attr('class', 'country')
.attr('d', path)
}
})
d3.js地图(顶部)与。 mapshaper.org map(底部)
“ alt =” mapshaper.org apojson的地图“
https://i.sstatic.net/znsk.png
A. I have downloaded two geojsons
- world map
- USA states
B. I then merge the two geojsons with geojson-merge
on the commandline to give me a world_map_with_USA_states.json
$ geojson-merge gz_2010_us_040_00_20m.json custom.geo.json > combined.json
C. I then convert the world_map_with_USA_states.json
to topojson on mapshaper.org
Loading the world_map_with_USA_states.json
on https://mapshaper.org/ shows USA states and other countries
But d3.js does not show the USA states
d3.js code
let mapURl = 'world_map_with_USA_states.json'
let countriesData
const width = 900
const height = 600
const svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height)
const projection = d3.geoMercator().scale(140)
.translate([width/2, height/1.4])
const path = d3.geoPath(projection)
const g = svg.append('g')
d3.json(mapURl)
.then((data, error) =>{
if (error){
console.log(error)
}else{
console.log(data)
countriesData = topojson.feature(data, data.objects.combined)
g.selectAll('path').data(countriesData.features).enter().append('path')
.attr('class', 'country')
.attr('d', path)
}
})
d3.js map (top) Vs. mapshaper.org map (bottom)
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论