[OpenLayers-Users] Extending callback function of Handler.Path

Mifan Careem mifan at opensource.lk
Tue Jun 17 03:22:05 EDT 2008


Hi All,

I'm trying to get the coordinates from line vectors drawn by users using
Control.storeFeature and store them in the database. I intend to do this
using a solution posted in the lists sometime back by using the "done"
callback of Handler.Path, and doing the required processing within it. 

My problem is that the drawn vector line disappears at the end of
drawing it. I'm assuming this is because I'm overriding the default
"done" handler with my own? - since it works OK when I do not have a
callback handler. Is there a way I can extend the default callback
handler instead of replacing it? (I hope the terminology I use is
correct here), so that the drawn vector lines do not disappear?

My code is attached below, and a hosted version is at:
http://talksahana.com/sandbox/ol-draw.html

Appreciate any help with this. Thanks.


Regards

Mifan

http://talksahana.com
http://techmania.wordpress.com 


---------
 var map, drawControls;
            OpenLayers.Util.onImageLoadErrorColor = "transparent";
            function init(){
                map = new OpenLayers.Map('map');
                var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers
WMS",
                    "http://labs.metacarta.com/wms/vmap0?", {layers:
'basic'});
                var lineLayer = new OpenLayers.Layer.Vector("Line
Layer");
                map.addLayers([wmsLayer, lineLayer]);
                map.addControl(new OpenLayers.Control.LayerSwitcher());
                map.addControl(new OpenLayers.Control.MousePosition());
                var options = {handlerOptions: {freehand: true}};
                //Callback
                var pathDrawFeatureOptions = {
                        callbacks : {"done": doneHandler},
                        handlerOptions: {freehand: true}
                };
                drawControls = {
                    line: new OpenLayers.Control.DrawFeature(lineLayer,
                                OpenLayers.Handler.Path,
pathDrawFeatureOptions)
                };
                for(var key in drawControls) {
                    map.addControl(drawControls[key]);
                }
                map.setCenter(new OpenLayers.LonLat(0, 0), 3);
                document.getElementById('noneToggle').checked = true;
            }


        function doneHandler(lineGeom) {
                // do processing ....
                //alert("doneHandler:" +
lineGeom.getComponentsString());
                //var linecontrol = drawControls['line'];
                //linecontrol.deactivate();
        }

            function toggleControl(element) {
                for(key in drawControls) {
                    var control = drawControls[key];
                    if(element.value == key && element.checked) {
                        control.activate();
                    } else {
                        control.deactivate();
                    }
                }
            }
------------




More information about the Users mailing list