Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

Vega-Lite: Map from Amsterdam not show

Hi guys I'm trying to create a map from Amsterdam using a very basic code, but the map didn't show up:

{
 "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
 "width": 700,
 "height": 500,
 "config": {"view": {"stroke": "transparent"}},
 "data": {
   "url": "https://raw.githubusercontent.com/minhquan9408/gdv_1/main/data/map.topojson",
   "format": {"type": "topojson", "feature": "states"}
 },
 "mark": {"type": "geoshape", "stroke": "white", "strokeWidth": 2},
 "encoding": {"color": {"value": "#eee"}}
}

But when I use data from Berlin it worked as expected

{
 "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
 "width": 700,
 "height": 500,
 "config": {"view": {"stroke": "transparent"}},
 "data": {
   "url": "https://raw.githubusercontent.com/funkeinteraktiv/Berlin-Geodaten/master/berlin_bezirke.topojson",
   "format": {"type": "topojson", "feature": "states"}
 },
 "mark": {"type": "geoshape", "stroke": "white", "strokeWidth": 2},
 "encoding": {"color": {"value": "#eee"}}
}

here is the online Vega-Lite Editor

Anyone knows the anwser for this problem? I think it's probably because of the data. I really appreciate your help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your topojson file does not have a geometry collection named "states", but it does have one named "collection". Changing this makes the file load and display correctly:

{
 "width": 700,
 "height": 500,
 "config": {"view": {"stroke": "transparent"}},
 "data": {
   "url": "https://raw.githubusercontent.com/minhquan9408/gdv_1/main/data/map.topojson",
   "format": {"type": "topojson", "feature": "collection"}
 },
 "mark": {"type": "geoshape", "stroke": "white", "strokeWidth": 2}
}

enter image description here

The result is obviously not what was intended, but this appears to be a data quality issue rather than a Vega-Lite issue: other topojson viewers also show it to include a geometry that covers the entire map.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...