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