小册子由geojson画六角形

时间:2013-12-25 05:54:54

标签: polygon leaflet geojson

我正在绘制多边形使用geojson数据(传单库)。

代码 -

 var myPlic = {
            "type": "Polygon",
            "coordinates":  [
                [47.98, 55.52],
                [50.36, 56.55],
                [51.76, 55.92],
                [53.17, 56.31],
                [54.31, 55.77],
                [53.34, 54.97],
                [53.52, 54.16],
                [51.59, 54.57],
                [50.71, 54.31],
                [48.86, 54.87],
                [47.81, 54.67],
                [47.98, 55.52]
            ]
        };
        try{L.geoJson(myPlic, {
            style: {
                color: '#AAAAFF',
                weight: 4
            }
        }).addTo(map);
        }
        catch(e){
            console.log(e);
        }

问题 - 控制台输出 -

错误:无效的LatLng对象:(NaN,NaN)

抛出新错误('无效的LatLng对象:('+ lat +','+ lng +')');

请帮忙。感谢。

P.S。如果我使用5坐标就可以了。而且这个坐标的LineString也没有问题,但是Polygon不起作用。

2 个答案:

答案 0 :(得分:1)

如果有人想找答案,前面的代码中缺少[]

{
  "geometry": {
    "coordinates": [[
      [47.98, 55.52],
      [50.36, 56.55],
      [51.76, 55.92],
      [53.17, 56.31],
      [54.31, 55.77],
      [53.34, 54.97],
      [53.52, 54.16],
      [51.59, 54.57],
      [50.71, 54.31],
      [48.86, 54.87],
      [47.81, 54.67],
      [47.98, 55.52]
      ]],
    "type": "Polygon"
  }
}

答案 1 :(得分:0)

您没有传递有效的GeoJSON要素/ featurecollection对象。有效的要素对象如下所示:

{
    type: "feature",
    geometry: {
        "type": "Polygon",
        "coordinates":  [
            [47.98, 55.52],
            [50.36, 56.55],
            [51.76, 55.92],
            [53.17, 56.31],
            [54.31, 55.77],
            [53.34, 54.97],
            [53.52, 54.16],
            [51.59, 54.57],
            [50.71, 54.31],
            [48.86, 54.87],
            [47.81, 54.67],
            [47.98, 55.52]
        ]
    }
}

请参阅GeoJSON规范@ http://geojson.org/geojson-spec.html