Ilyas Fasikhov
Ilyas Fasikhov

Reputation: 103

leaflet draw hexagon by geojson

I'm draw polygon use geojson data (leaflet library).

code -

 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);
        }

problem - console out -

Error: Invalid LatLng object: (NaN, NaN)

throw new Error('Invalid LatLng object: (' + lat + ', ' + lng + ')');

Please help. Thanks.

P.S. If i'm used 5 coordinates it's ok. And LineString from this coordinates also no pronblem, but Polygon don't work.

Upvotes: 0

Views: 1623

Answers (2)

user3012122
user3012122

Reputation: 11

If anyone would look for the answer, there are missing [ ] in previous code

{
  "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"
  }
}

Upvotes: 1

iH8
iH8

Reputation: 28638

You're not passing a valid GeoJSON feature/featurecollection object. A valid feature object would look like this:

{
    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]
        ]
    }
}

See GeoJSON specification @ http://geojson.org/geojson-spec.html

Upvotes: 0

Related Questions