[OpenLayers-Dev] mousemove on edit polygon

Richard Duivenvoorde rdmailings at duif.net
Thu Mar 13 11:38:23 EDT 2008


Hi list,
I needed a simple measurement tool for an application, and found the 
measurement patch of tim: 
http://trac.openlayers.org/attachment/ticket/1241/measure.patch

But because I already used the 'point'-callback:

var drawoptions = {handlerOptions: {freehand:false}, callbacks: { 
point:linePointAdded }};
         lineControl = new OpenLayers.Control.DrawFeature(drawinglayer, 
OpenLayers.Handler.Path, drawoptions);

I thought: shouldn't there be some mousemove callback also? I couldn't 
find it but after 'patching' OpenLayers.Handler.Path with something like:

  mousemove: function (evt) {
         if(this.drawing) {
             var lonlat = this.map.getLonLatFromPixel(evt.xy);
             this.point.geometry.x = lonlat.lon;
             this.point.geometry.y = lonlat.lat;
             if(this.mouseDown && this.freehandMode(evt)) {
                 this.addPoint();
             } else {
                 this.modifyFeature();
             }
             this.drawFeature();
// THE LINE BELOW IS ADDED:
             this.callback("mousemove", [this.point.geometry]);
         }
         return true;
     },

I could happily use it for a making my measurement tool:

var rulerOptions = {handlerOptions: {freehand:false}, callbacks: { 
mmove:rulerMove } };
         rulerControl = new OpenLayers.Control.DrawFeature(drawinglayer, 
OpenLayers.Handler.Path, rulerOptions);

So my questions:

Is this a good idea to do? Or am I messing up some stuff if I do this. 
I'm aware of some performance consequences using this kind of 
events/callbacks.

Is there another (preferred) way for doing this kind of things?
(I'm aware of all the measurement discussions, but for me the length 
given by the geometry is ok.)

If this is usefull for anybody? If it is, is it an idea to add it in trunk?

Regards,
Richard Duivenvoorde




More information about the Dev mailing list