Hi Andreas, Thanks a lot for the solution using callbacks. I was wondering if you could suggest how that might be adapted to give the measurements on a draw feature. It's much easier than what I was previously doing for measure and drawFeature (passing a customized modifyFeature function in the options, where the new function was the same as the original, but also had the requisite getLength statements - functional, but it seems like this should be far more version dependent than the callback solution).
When I try to use callbacks-modify on a drawFeature (as below), my modify callback doesn't seem to get used (the console.log(this) never fires). I assume this is because measureControls didn't already use a modify callback, whereas drawFeature does, and as such drawFeature overrides any modify callback I might try to pass in? Is there any way to append to the normal modify callback? Am I missing something obvious? Thanks! Josh broken: uses callbacks - modify: selectDrawCircle = new OpenLayers.Control.DrawFeature(selectLayerPoly, OpenLayers.Handler.RegularPolygon,{ displayClass:"olControlSelectDrawCircle", element:document.getElementById('SelectControl_Distance'), unitElement:document.getElementById('SelectControl_mapUnit'), callbacks:{ modify: function (point,feature) { console.log(this); this.element.value=this.radius.toFixed(2); this.unitElement.innerHTML=this.map.getUnits(); } }, handlerOptions:{ sides:40 } }); functional: uses slightly customized modifyGeometry function passed in as an option selectDrawCircle = new OpenLayers.Control.DrawFeature(selectLayerPoly, OpenLayers.Handler.RegularPolygon,{ displayClass:"olControlSelectDrawCircle", handlerOptions:{ sides:40, element:document.getElementById('SelectControl_Distance'), unitElement:document.getElementById('SelectControl_mapUnit'), modifyGeometry: function() { var angle, dx, dy, point; var ring = this.feature.geometry.components[0]; // if the number of sides ever changes, create a new geometry if(ring.components.length != (this.sides + 1)) { this.createGeometry(); ring = this.feature.geometry.components[0]; } for(var i=0; i<this.sides; ++i) { point = ring.components[i]; angle = this.angle + (i * 2 * Math.PI / this.sides); point.x = this.origin.x + (this.radius * Math.cos(angle)); point.y = this.origin.y + (this.radius * Math.sin(angle)); point.clearBounds(); } // note, only val b/c this is an input field. this.element.value=this.radius.toFixed(2); this.unitElement.innerHTML=this.map.getUnits(); } }}); On Wed, Apr 22, 2009 at 8:22 AM, Andreas Hocevar <ahoce...@opengeo.org>wrote: > Hi, > > the solution (if you're using trunk or 2.8) is quite simple. The snippet > below replaces the definition of measureControls in the measure example > (starting around L65) > > measureControls = { > line: new OpenLayers.Control.Measure( > OpenLayers.Handler.Path, { > callbacks: { > modify: function(point, feature) { > measureControls.line.measurePartial(point, > feature.geometry); > } > }, > persist: true, > handlerOptions: { > layerOptions: {styleMap: styleMap} > } > } > ), > polygon: new OpenLayers.Control.Measure( > OpenLayers.Handler.Polygon, { > callbacks: { > modify: function(point, feature) { > > measureControls.polygon.measurePartial(point, > feature.geometry); > } > }, > persist: true, > handlerOptions: { > layerOptions: {styleMap: styleMap} > } > } > ) > }; > > As you can see, the trick is to add a modify callback to the handler, > calling the control's measurePartial method. > > Regards, > Andreas. > > pribram pribram wrote: > > Hi, > > Is there anything new about measuring + getting distance on mousemove? > > > http://n2.nabble.com/Measure-Control---get-distance-on-mouse-move-td2503580.html > > If there is a solution, please publish it. > > > > Thanks, > > Pribram > > _______________________________________________ > > Users mailing list > > Users@openlayers.org > > http://openlayers.org/mailman/listinfo/users > > > > > -- > Andreas Hocevar > OpenGeo - http://opengeo.org/ > Expert service straight from the developers. > > _______________________________________________ > Users mailing list > Users@openlayers.org > http://openlayers.org/mailman/listinfo/users >
_______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users