Mapbox-gl-js: TypeError: Cannot set property '2' of undefined

Created on 15 Feb 2016  路  4Comments  路  Source: mapbox/mapbox-gl-js

Hi!

I get "TypeError: Cannot set property '2' of undefined" error when I have this style in my script. How do I debug this error?

var style = {
"version": 8,
"sources" : {
"terrain-data" : {
"type" : "geojson",
"data" : "http://localhost:8000/ogr_out.json"
}
},
"layers" : [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "#41afa5"
}
}, {
'id': 'terrain-data-layer',
'type': 'fill',
'source': 'terrain-data',
'paint': {
'fill-color': '#ff69b4',
'fill-opacity': 0.8
}
}]
};

var map = new mapboxgl.Map({
container: 'map',
style : style,
zoom: 10,
center: [-122.447303, 37.753574]
});

Thanks!

Most helpful comment

In case anyone ends up here via google with this error, I believe it relates to invalid GeoJSON of the form:

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[]]
  }
}

All 4 comments

The way I do it is first remove things until you don't have a error anymore and then put them back one by one.

@divya1c I was not able to reproduce your error. Here is a working map using the code you provided: http://jsbin.com/bubivayuki/edit?html,output. Please ensure you are using the latest version of mapbox-gl-js and your GeoJSON data is properly formatted.

In case anyone ends up here via google with this error, I believe it relates to invalid GeoJSON of the form:

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[]]
  }
}

thanks so much @drewbo,
"coordinates": [[]]
was the problem, my geoJSON had got simplified down to nothing. Ignoring empty polygons or a more meaningful error message would be great.

Was this page helpful?
0 / 5 - 0 ratings