3

I am working on modify function for an Openlayers project. I define a vector layer for modify objects. (line, polygon etc.) But then I take an error like below while adding vector layer to map object. Why am i getting this?

Error

Uncaught TypeError: layer.getLayerStatesArray is not a function
at ol-debug.js:17395
at ol.Collection.forEach (ol-debug.js:8289)
at ol.layer.Group.getLayerStatesArray (ol-debug.js:17394)
at ol.Map.ol.PluggableMap.renderFrame_ (ol-debug.js:18670)
at ol.Map.<anonymous> (ol-debug.js:17624)

Source Code (core)

        init: function (Map) {
            var self = this;
            self.Map = Map;
            self.VectorSource = new ol.source.Vector({ wrapX: false });
            self.Map.olMap.addLayer(self.VectorSource);
            self.initialized = true;
        },

Source Code (UI)

var geo = (new ol.format.GeoJSON()).readFeatures(e, { featureProjection: 'EPSG:3857' })[0];
Max.Map.Draw.VectorSource.addFeature(geo);

Referenced example

7

You must give "ol.layer.Vector" object to addLayer method. For example:

var vectorLayer = new ol.layer.Vector({
      source: new ol.source.Vector()
});

self.Map.olMap.addLayer(vectorLayer);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.