[OpenLayers-Users] how to cleanly remove a vector layer
Mike Quentel
mikequentel at yahoo.com
Wed May 30 19:22:48 EDT 2007
This might be of help to you...
OpenLayers.Control.EraseFeatures = OpenLayers.Class.create();
OpenLayers.Control.EraseFeatures.prototype =
OpenLayers.Class.inherit( OpenLayers.Control, {
/** @type OpenLayers.Control.TYPES */
type: OpenLayers.Control.TYPE_BUTTON,
trigger: function () {
if (this.map) {
var map = this.map;
for(i = 0; i < map.layers.length; i++) {
var currentLayer = map.layers[i];
if (currentLayer.isVector) {
if (currentLayer.selectedFeatures.length > 0) {
currentLayer.destroySelectedFeatures();
} else {
currentLayer.destroyFeatures();
} //if (currentLayer.selectedFeatures...
} //if (currentLayer.isVector...
} // for (i = 0...
} //if (this.map...
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Control.EraseFeatures"
});
Mike Quentel
----- Original Message ----
From: Roger Kunkel <rakunkel at ucdavis.edu>
To: Christopher Schmidt <crschmidt at metacarta.com>
Cc: users at openlayers.org
Sent: Wednesday, 30 May, 2007 3:35:07 PM
Subject: Re: [OpenLayers-Users] how to cleanly remove a vector layer
Thanks for your reply.
I was using the removeFeatures incorrectly.
On May 30, 2007, at 1:53 PM, Christopher Schmidt wrote:
> On Wed, May 30, 2007 at 01:36:41PM -0700, Roger Kunkel wrote:
>>
>> I'm having trouble using and then removing a vector layer.
>> removeFeatures() - produces errors saying that the feature is not
>> defined when feature.geometry is referenced.
>
> map.layers[1].removeFeatures(map.layers[1].features); works for me on
> http://openlayers.org/dev/examples/vector-features.html .
>
>> calling destroy on the layer causes continuous mouse event errors
>> - it seems that the getFeatureFromEvent method keeps getting called
>> even though I've destroyed the layer.
>
> Yep. That's a bug. The only piece of advice I have for that is to not
> destroy a layer if you have selectefatures handler on it :) I'll
> file it
> as a bug.
>
> Regards,
> --
> Christopher Schmidt
> MetaCarta
Roger Kunkel
CERES Program
Dept. of Land Air & Water Resources
UC Davis
rakunkel at ucdavis.edu
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
More information about the Users
mailing list