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.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to