Search code examples
javascriptopenlayers-3geojson

openlayers3 undefined is not a constructor error on ol.source.StaticVector


I am learning openlayers3 with ol v3.20.1
I've got to the point in the book, where I can read/write GeoJSON with StaticVector, but the following code:

var statVec = new ol.layer.Vector({
	source: new ol.source.StaticVector({
		format: new ol.format.GeoJSON(),
		projection: 'EPSG:3857'
	})
});

errors out with:

TypeError: undefined is not a constructor (evaluating 'new ol.source.StaticVector({
            format: new ol.format.GeoJSON(),
            projection: 'EPSG:3857'
        })')
    global code

I realize, there was an API change, since the book came out, but I can't find what StaticVector was replaced with.


Solution

  • ol.source.StaticVector along with other similar experimental Vector sources were removed in v3.5.0. Regarding your question ol.source.StaticVector is replaced with ol.source.Vector.

    See this release details

    https://github.com/openlayers/openlayers/releases/tag/v3.5.0