[Users] GeoExt2: Problem adding multiple Features to FeatureStore and VectorLayer

Lukas Vonlanthen voli at students.unibe.ch
Tue May 29 08:32:50 CEST 2012


Dear list,

Using ExtJS 4 (4.0.7) and GeoExt 2, I am having troubles synchronizing  
the FeatureStore with a VectorLayer. When I try to add a second  
Feature to the FeatureStore (or the VectorLayer), it appears only in  
the FeatureStore but NOT in the VectorLayer (and therefore not on the  
map).

<File: Project.store.ActivityPoints>
Ext.define('Project.store.ActivityPoints', {
                 extend: 'GeoExt.data.FeatureStore',
                 model: 'Project.model.Activity',
                 autoLoad: false
});

<File: Project.controller.Map>
...
onPanelRendered: function(comp) {
         var layer = comp.getMap().getLayersByName('vector')[0];
         var store = Ext.data.StoreManager.lookup('ActivityPoints');
         store.bind(layer);
}
...

<File: Project.view.map.MapPanel>
...
map: {
         displayProjection: new OpenLayers.Projection("EPSG:4326"),
         layers: [
                 new OpenLayers.Layer.OSM('Mapnik'),
                 new OpenLayers.Layer.Vector("vector")
         ],
         projection: new OpenLayers.Projection("EPSG:900913")
     },
tbar: {
         items: [{
                 text: 'click',
                 handler: function() {
                     var layer = map.getLayersByName('vector')[0];
                     var store =  
Ext.data.StoreManager.lookup('ActivityPoints');
                     var point1 = new OpenLayers.Feature.Vector(new  
OpenLayers.Geometry.Point(9446238, 746333), {
                         id: 'point1'
                     });
                     var point2 = new OpenLayers.Feature.Vector(new  
OpenLayers.Geometry.Point(9447238, 747333), {
                         id: 'point2'
                     });
                     layer.addFeatures([point1]);
                     console.log(store.count()); // 1
                     console.log(layer.features.length); // 1
                     console.log(layer.features[0] == point1); // true
                     layer.addFeatures([point2]);
                     console.log(store.count()); // 2
                     console.log(layer.features.length); // 1 (!!!)
                     console.log(layer.features[0] == point2); // true
                 }
             }]
         }
...

As you can see, the VectorLayer just does not seem to take more than  
one Feature and always contains just the last added Feature. It also  
does not make any difference if I change to  
store.addFeatures([point1]) or if I try to add Features directly (not  
in an array).

It would work if I add all the Features at once:  
layer.addFeatures([point1, point2]), but I would like to add the  
Features one at a time.

What am I doing wrong here? Any help is very much appreciated. Thanks!  
With best regards, Lukas.




More information about the Users mailing list