首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用vega阅读geojson

如何使用vega阅读geojson
EN

Stack Overflow用户
提问于 2017-12-30 14:16:38
回答 1查看 416关注 0票数 1

这听起来非常简单,但是我不明白如何为我的多边形使用geojson,而不是topojson。

这就是我目前的尝试:

代码语言:javascript
复制
"data": [
    {
      "name": "nabs",
      "url": "both_boundaries.geojson",
      "format": {"type": "json"},
      "transform": [
      {
        "type": "geopath", "projection": "mercator",
        "scale": 74, "center": [-73.99,40.72]
      }
    ]
    }
  ]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-04 04:55:11

您必须使用格式中的属性来解析要素:

代码语言:javascript
复制
   "format": {"type": "json", "property":"features"},

完整示例规范:

代码语言:javascript
复制
{"$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"
        }
      ]
    }
  ]
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48031542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档