如何阅读vega的geojson

时间:2017-12-30 06:16:38

标签: geojson vega

这听起来非常简单,但我无法获得如何使用geojson而不是topojson作为我的多边形。

这是我目前的尝试:

"data": [
    {
      "name": "nabs",
      "url": "both_boundaries.geojson",
      "format": {"type": "json"},
      "transform": [
      {
        "type": "geopath", "projection": "mercator",
        "scale": 74, "center": [-73.99,40.72]
      }
    ]
    }
  ]

1 个答案:

答案 0 :(得分:3)

您必须使用格式中的属性解析功能:

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

完整示例规范:

{"$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"
        }
      ]
    }
  ]
}
相关问题