[Users] GeoExt2: Problem adding multiple Features to FeatureStore and VectorLayer
Alexandre Dube
adube at mapgears.com
Tue May 29 14:35:05 CEST 2012
Lukas,
This looks like a bug indeed. What seems to happen is the FeatureStore
[addFeatures] calls loadRawData, which fires the 'load' event, which
triggers [onLoad] that calls this.layer.removeAllFeatures() before
adding the new ones. Writing a test to replicate what your trying to do
should reproduce the issue.
Without testing it and from what I understand, here's what I think could
solve the problem. The [LayerStore] used to have that same issue and it
was changed. The LayerModel has a static method to build new [layer
model instances] that can then be added/inserted/removed with standard
store methods.
In brief, it should use the loadRawData method, but add instead. Would
you send a pull request with a fix and tests or simply create an issue
on github, please ?
[addFeatures]
https://github.com/geoext/geoext2/blob/master/src/GeoExt/data/FeatureStore.js#L206
[onLoad]
https://github.com/geoext/geoext2/blob/master/src/GeoExt/data/FeatureStore.js#L319
[LayerStore]
https://github.com/geoext/geoext2/commit/c2d5993714a4201d4c190f29eeae63b3e51d4d6e
[layer model instances]
https://github.com/geoext/geoext2/blob/master/src/GeoExt/data/LayerModel.js#L18
On 12-05-29 02:32 AM, Lukas Vonlanthen wrote:
> 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.
>
>
> _______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list