Python Folium Topojson 文件未呈现

Python Folium Topojson file not rendering

您好,我正在尝试在 jupyter 笔记本中使用 Folium 渲染这张地图。

https://github.com/kthotav/TopoJSON-Maps/blob/master/usa/usa-states/colorado/colorado-counties.json

因为这是 TopoJson,所以应该很简单

m = folium.Map([39, -105], zoom_start=7)
folium.TopoJson(
    open('./data/colorado-counties.json'),
    object_path='objects.colorado-counties'
).add_to(m)
m

这会渲染基础层,但不会绘制县的多边形。

我发现 并且它使用基本相同的代码呈现得很好。

m = folium.Map(location=[40.7,-74], zoom_start=10)
folium.TopoJson(
    open('./data/nyc_census_tracts_2010.geojson'),
    object_path='objects.nyct2010',
).add_to(m)
m

我找不到这两个文件之间的任何大尺度差异。是不是有些topojson版本不兼容?

好的,明白了。 folium 无法解析其中包含 - 的对象名称。可能是 javascript 翻译的东西?

趣味测试

有效

m = folium.Map([0, 0], zoom_start=7)
folium.TopoJson(
    {
      "type":"Topology",
      "transform":{
        "scale": [1,1],
        "translate": [0,0]
      },
      "objects":{ 
        "two_squares":{
          "type": "GeometryCollection",
          "geometries":[
            {"type": "Polygon", "arcs":[[0,1]],"properties": {"name": "Left_Polygon" }},
            {"type": "Polygon", "arcs":[[2,-1]],"properties": {"name": "Right_Polygon" }}
          ]
        }
      },
      "arcs": [
        [[1,2],[0,-2]],
        [[1,0],[-1,0],[0,2],[1,0]],
        [[1,2],[1,0],[0,-2],[-1,0]]
      ]
    },
    object_path='objects.two_squares'
).add_to(m)
m

无效

m = folium.Map([0, 0], zoom_start=7)
folium.TopoJson(
    {
      "type":"Topology",
      "transform":{
        "scale": [1,1],
        "translate": [0,0]
      },
      "objects":{ 
        "two-squares":{
          "type": "GeometryCollection",
          "geometries":[
            {"type": "Polygon", "arcs":[[0,1]],"properties": {"name": "Left_Polygon" }},
            {"type": "Polygon", "arcs":[[2,-1]],"properties": {"name": "Right_Polygon" }}
          ]
        }
      },
      "arcs": [
        [[1,2],[0,-2]],
        [[1,0],[-1,0],[0,2],[1,0]],
        [[1,2],[1,0],[0,-2],[-1,0]]
      ]
    },
    object_path='objects.two-squares'
).add_to(m)
m