[OpenLayers-Users] RE : Measure Control - get distance on mouse
move
Josh Rosenthal
maric423 at gmail.com
Mon Apr 20 16:46:11 EDT 2009
Oops.
After posting, I saw Chris' post about 2.8-rc1, and decided to take a look
at the upcoming release. Needless to say, Handler.Path has changed, and
while the code I posted works in 2.7, it fails in 2.8 rc1 Not a great
solution. I'm still trying to puzzle through the changes in 2.8 to see how
I'd implement the same in the new version. I'm now doubly curious if anyone
is willing to share a way of doing this in 2.8 (or point me in the direction
of a more stable solution).
Thanks!
Josh
Josh Rosenthal wrote:
>
> Hi Ryan,
> I realize its a bit late, but I ran into the same need as you've
> described.
> If you've (or anyone else) has solved it, I'd be curious to see your
> solution if you feel like sharing. My solution is to play with the
> handlerOptions to overwrite the modifyFeature method of the path handler.
> For a basic measure demo based off of the example, I'd alter the Control
> definition to be roughly as follows:
>
> measurePath = new OpenLayers.Control.Measure(
> OpenLayers.Handler.Path, {
> persist: true,
> handlerOptions: {
> modifyFeature: function() {
> var index = this.line.geometry.components.length - 1;
> this.line.geometry.components[index].x = this.point.geometry.x;
> this.line.geometry.components[index].y = this.point.geometry.y;
> this.line.geometry.components[index].clearBounds();
> this.element.innerHTML=this.line.geometry.getLength().toFixed(2) + "
> meters";
> },
> element: document.getElementById('measureOutput'),
> layerOptions: {styleMap: styleMap}
> }
> }
> );
>
> Similar logic should work for Polygon areas (haven't tried it yet). I
> also
> want to do it for Circle (Regular poly, ~ 40 sides) radius, which is a bit
> trickier, as there is no getRadius function, but calculating that should
> be
> tolerable. In theory, one should probably include some sort of
> granularity
> check (as per mouseposition) to slow down the obsessive overwriting of
> measureOutput, but this does appear to work. Note that because there is
> always a modifyFeature before a click (addPoint), or doubleClick, there is
> no need to overwrite the other methods.
>
> As I said, I'm curious to hear any feedback or suggestions on better
> solutions.
>
> Thanks,
> Josh
>
> On Thu, Mar 19, 2009 at 12:47 PM, RFeagin <
> ryan.feagin at peachtreegeographics.com> wrote:
>
>>
>> Unless I'm missing something, that looks exactly like what I'm already
>> doing
>> and gets me an updated distance each time the user clicks to add another
>> point to the polyline. What I'm looking for is to get the distance to
>> the
>> current mouse location (without having to click to add the current
>> location). The drawing of the polyline already tracks the cursor
>> location
>> because it is drawing the line as you move the mouse.
>>
>> So the user will click to create the starting point and as they move
>> their
>> mouse, the distance will update. Clicking again will still add another
>> point to the polyline. The only difference is using the current cursor
>> location as a 'moving' point at the end of the polyline to give a 'real
>> time' distance.
>> --
>> View this message in context:
>> http://n2.nabble.com/Measure-Control---get-distance-on-mouse-move-tp2503580p2504004.html
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
--
View this message in context: http://n2.nabble.com/Re%3A-RE-%3A-Measure-Control---get-distance-on-mouse-move-tp2665698p2666160.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list