Popup with mouse movement, OpenLayers.Control.Measure measurement distance

Source: Internet
Author: User

Before a tool to measure distances was needed, the OpenLayers.Control.Measure was checked, and the acreage process realized the acreage of the distance or area on the vector layer by invoking the event handler Handler.

Here is the distance acreage, the click will pop up popup (openlayers.popup), the effect is to add popup after click to calculate the distance between the previous points, and delete the front of the popup (and did not make the same move with the mouse to change the distance of the effect).

Call Method Measurepath (); You can see the effect.

1 varMeasurepopup =NULL;2 varMessagelast =NULL;3 4 //Distance Measurement5 varMeasurecontrol =NewOpenLayers.Control.Measure (OpenLayers.Handler.Path, {6Persisttrue,7 eventlisteners: {8' Measure ': Measuredistance,9' Measurepartial ': MeasurepartialTen     } One }); A  -  - functionMeasurepath () { theMeasurecontrol.updatehandler (OpenLayers.Handler.Path, {persist:true }); - Map.addcontrol (Measurecontrol); - measurecontrol.activate (); - } + functionMeasuredistance (event) { -Messagelast = parsefloat (event.measure). toFixed (2) + "" +event.units; +     if(Event.order > 1) { AMessagelast + = "2"; at     } -     //get latitude and longitude at mouse click -     varPoints =event.geometry.components; -     varPoint = Points[points.length-1]; -     if(Measurepopup! =NULL) - Map.removepopup (measurepopup); inMeasurepopup =NewOpenlayers.popup ("Chicken", -     //pop-up box position to                    NewOpenlayers.lonlat (Point.x, point.y), +     //New Openlayers.lonlat (position.x, POSITION.Y), -                    NULL, the Messagelast, *                    true, $ CloseboxcallbackPanax Notoginseng                    ); -Measurepopup.autosize =true; theMeasurepopup.backgroundcolor = "#06a09f"; +Measurepopup.opacity = 0.8; A Map.addpopup (measurepopup); the } +  - functionMeasurepartial (event) { $     varMessage = parsefloat (event.measure). toFixed (2) + "" +event.units; $     varPoints =event.geometry.components; -     varPoint = Points[points.length-1]; -     if(Measurepopup! =NULL) the Map.removepopup (measurepopup); -Measurepopup =NewOpenlayers.popup ("Chicken",Wuyi     //pop-up box position the                    NewOpenlayers.lonlat (Point.x, point.y), -                    NULL, Wu message, -                    true, About Closeboxcallback $                    ); -Measurepopup.autosize =true; -Measurepopup.backgroundcolor = "#06a09f"; -Measurepopup.opacity = 0.8; A     if(Points.length > 2) + Map.addpopup (measurepopup); the } -  $ //function Changehandler (checked) { the //Measureclick (); the //    } the  the functionCloseboxcallback () { - Map.removepopup (measurepopup); in measurecontrol.deactivate (); the Map.removecontrol (Measurecontrol); theMessagelast =NULL; About}
View Code

Popup is a little ugly, haha. Double-click to end the measurement and click the popup's Close button (the Red fork in the upper right corner) to end the measurement event.

Popup with mouse movement, OpenLayers.Control.Measure measurement distance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.