How to read geojson with vega

丶灬走出姿态 提交于 2019-12-06 14:58:09

You have to parse the features using property within your format:

   "format": {"type": "json", "property":"features"},

Full example spec:

{"$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "width": 500,
  "height": 600,
  "autosize": "none",
  "signals": [
    {
      "name": "translate0",
      "update": "width / 2"
    },
    {
      "name": "translate1",
      "update": "height / 2"
    }
  ],
  "projections": [
    {
      "name": "projection",
      "size": {"signal": "[width, height]"},
      "fit": {"signal": "data('netherlands')"}
    }
  ],
  "data": [
    {
      "name": "netherlands",
      "url": "https://raw.githubusercontent.com/mattijn/datasets/master/NL_outline_geo.json",
      "format": {
        "type": "json",
        "property": "features"
      }
    }
  ],
  "marks": [
    {
      "type": "shape",
      "from": {
        "data": "netherlands"
      },
      "encode": {
        "update": {
          "strokeWidth": {
            "value": 0.5
          },
          "stroke": { 
            "value": "darkblue"
          },
          "fill": {
            "value": "lightblue"
          },
          "fillOpacity": {
            "value": 0.5
          }
        },
        "hover": {
          "fill": {
            "value": "#66C2A5"
          },
          "strokeWidth": {
            "value": 2
          },
          "stroke": {
            "value": "#FC8D62"
          }
        }
      },
      "transform": [
        {
          "type": "geoshape",
          "projection": "projection"
        }
      ]
    }
  ]
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!