[OpenLayers-Users] DrawFeature: how to clear?
Kevin Kempfer
mail at kevinkempfer.de
Fri Jun 15 11:32:20 EDT 2007
Hello,
Christopher Schmidt schrieb:
>> how can I clear the map of all/specific drawed features?
>> example:
>> http://www.openlayers.org/dev/examples/draw-feature.html
>
> http://dev.openlayers.org/docs/OpenLayers/Layer/Vector.html#removeFeatures
Thanks. Works fine but I have a behaviour that is not clear to me. I can
reproduce it like this:
1. draw a feature (polygon, line, point)
2. select it (hover or click)
3. remove all features: vectors.removeFeatures(vectors.features);
- everything disappears as desired.
4. again, draw a feature
5. select it
What happens is the first (deleted) polygon re-appearing. Am I missing
something, here?
Here's the code:
var map, drawControls, vectors;
function createMap(){
map = new OpenLayers.Map('map', {controls: []});
var jpl = new OpenLayers.Layer.KaMap( "Satellite",
"http://dev/map.php", {g: "satellite", map: "world"});
jpl.displayOutsideMaxExtent = 1;
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([jpl, vectors]);
DrawControls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
line: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Path, options),
polygon: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Polygon, options),
select: new OpenLayers.Control.SelectFeature(vectors),
hover: new OpenLayers.Control.SelectFeature(vectors,
{hover: true})
};
for(var key in drawControls) {
map.addControl(drawControls[key]);
}
var start_point = new OpenLayers.LonLat(8,50);
map.setCenter(start_point,5);
}
}
function toggleControl(element) {
for(key in drawControls) {
var control = drawControls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
function clearall(){
vectors.removeFeatures(vectors.features);
}
function clearSelected(){
vectors.removeFeatures(vectors.selectedFeatures);
}
Regards,
Kevin.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3249 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20070615/18b61d5c/smime.bin
More information about the Users
mailing list