I have an OpenLayers.Layer.Vector layer that I allow the user to create, modify and delete features and feature attributes. The changes are saved when they hit a "Save Changes" button. If the user creates a new feature, then zooms the map out a ways, this causes OpenLayers to remove all features from the layer and only add in features saved to the GeoServer db. I have tried hanging onto the newly created features and adding them back to the layer on the "loadend" event but OpenLayers has destroyed the geometry of the new features so they are useless. How do I prevent OpenLayers from nuking the new features when zooming out?
Asked
Active
Viewed 1,030 times
0

Christophe Roussy
- 16,299
- 4
- 85
- 85

Hilo
- 869
- 2
- 9
- 24
-
Here's the workaround I'm currently using: in the layer "loadstart" handler, remove all of the new features and in the layer "loadend" handler, re-add all of the new features. OpenLayers should not remove features with a state of INSERT when requerying the db imho. – Hilo May 14 '13 at 16:08
-
How do you add features to openlayers? It sounds like you're drawing them by hand instead of adding them to the map. – mrówa May 15 '13 at 23:16
-
The new features are drawn by the user using the OpenLayers drawing controls which adds them to the layer. – Hilo May 17 '13 at 02:58
-
I don't know why OpenLayers is removing your new features, it does not do so out of the box. Please refer to the http://openlayers.org/dev/examples/draw-feature.html <- it works here. Could you try stripping the code to the minimum and post it here? – mrówa May 17 '13 at 11:06
-
If you look at the code for OpenLayers.Strategy.BBOX you'll see that it does do so "out of the box". When you zoom out, the layer is requeried with the new BBOX and calls OpenLayers.Strategy.BBOX.merge() which calls this.layer.destroyFeatures() thus removing/destroying all current features and adding back only those features saved to the database. – Hilo May 20 '13 at 21:09
-
Hmm haven't thought about that. In application I'm working on we're not using BBOX while letting do map editing. Another solution is to save just the x & y and to recreate the geometry from them on loadend. Application I work on has funny use case for OpenLayers, so I do server queries and vector addition/deletion by hand to get more control over the process. – mrówa May 20 '13 at 21:26