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

Mifan Careem mifan at opensource.lk
Mon Jun 23 07:52:55 EDT 2008


Hi Eric,

Thanks. I added the following within my handler after going through the
DrawFeature code - works fine now :-)

	var feature = new OpenLayers.Feature.Vector(lineGeom);
        lineLayer.addFeatures([feature]);


Regards

Mifan

http://talksahana.com
http://techmania.wordpress.com 
---
You'll feel devilish tonight.  Toss dynamite caps under a flamenco dancer's
heel.



On Wed, 2008-06-18 at 08:32 +0200, Eric Lemoine wrote:
> Hi. I haven't looked at your code but it's no surprise that the
> feature disappears once drawn - the point handler, which the path
> handler inherits from, uses a temporary vector layer. It is the
> responsibility of your control to actually add drawn features to a
> permanent layer, which control users will provide. Look at the draw
> feature control code to understand how this works. Hope this helps.
> Cheers. Eric
> 
> 2008/6/17, Mifan Careem <mifan at opensource.lk>:
> > 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();
> >                     }
> >                 }
> >             }
> > ------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >





More information about the Users mailing list