I checked measurement widget on following url. But it removes drawing on the map when you take measurement again. I want to retain the measurements on the map. Also, I want to show distance on each edge of the line drawn on the map. How can that be achieved?
http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=widget_measurementhttp://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=widget_measurement
Solved! Go to Solution.
The Measurement widget provides tools for calculating the current location (Get Location) and measuring distance (Measure Distance) and area (Measure Area). If the map's coordinate system is not Web Mercator or geographic or if complex polygons are drawn the measure widget will need to use the geometry service to project or simplify geometries. Use esri.config.defaults to specify the geometry service for your application.
It is recommended that you create a geometry service for use within your applications. View the Geometry Services help topic in the Server Resource Center for details on creating and publishing a geometry service. ESRI hosts a geometry service on sampleserver3 to support samples published in the Resource Center. You are welcome to use this service for development and testing purposes. ESRI also hosts a geometry service on tasks.arcgisonline.com; this service can be used for production applications however, we do not guarantee that the service will be available 24/7.
From: measurement | API Reference | ArcGIS API for JavaScript
Is there any formula to calculate measurement without firing request to geometry service?
It depends on what unit of measurement you are using and what the coordinate system of your map is.
The Measurement widget is designed to clear the previous measurement when a tool is selected to make a new measurement.
However, we can work around this by doing the following:
1) Listen to 'measure-end' event from the Measurement widget
2) Get and store the geometry from the event object
3) Create a graphic from the event geometry
4) Add that graphic to a separate graphics layer
Showing distance on each edge of the line drawn on the map is a bit trickier.
Instead of using the Measurement widget, I think it would be easier to use the Draw widget.
Under the hood, the Measurement widget functions similarly to the Draw widget.
In short, using events, you'd want to take the geometry of a particular line, use a task to measure it, then update your label layer with the result.
Ok, that sounds good! Only I didn't understand following:
"In short, using events, you'd want to take the geometry of a particular line, use a task to measure it, then update your label layer with the result."
Glad to help! Forget what I said about using a label layer... it is much easier to stick with Text Symbols.
1) Use a task to measure the line (distance)
"esri/tasks/DistanceParameters"
distanceparameters-amd | API Reference | ArcGIS API for JavaScript
2) Create a text symbol to show that distance
"esri/symbol/TextSymbol"
Tutorial: Use geometry service to measure distances | ArcGIS API for JavaScript
Example: Measure Distances
NOTEs
- The above sample is very similar to what you want to accomplish.
- The above sample does not use the draw toolbar, but can easily be fitted to do so
- The above sample is in legacy DOJO syntax (non-AMD)
Ok, will give a try as per suggestions.
One more thing - I want to show distance on the edge as line is drawn on the map. Similar to how it's done in Measurement widget for Distance tool. How that can be done? It doesn't seem that the widget code is firing request to geometry service on mouse move event.
Great question!
The distance tool is using the GeodesicUtils module ("esri/geometry/geodesicUtils").
For distance (polylines), it uses the following method: geodesicUtils.geodesicLengths();
For area, (polygons), it uses the following method: geodesicUtils.geodesicAreas();
esri | API Reference | geodesicUtils | ArcGIS API for JavaScript
esri | API Reference | geodesicUtils.geodesicLengths | ArcGIS API for JavaScript
It will only use an external GeometryService if the map's spatial reference is something other than webmercator (102100) or geographic (4326).
Why this geoDesicUtil is limited to webmercator/geographic? Is that something the accurate measurement comes only with geometry service when spatial reference is other than webmercator/geographic? Is there any formula to calculate measurement without firing request to geometry service?
The Measurement widget provides tools for calculating the current location (Get Location) and measuring distance (Measure Distance) and area (Measure Area). If the map's coordinate system is not Web Mercator or geographic or if complex polygons are drawn the measure widget will need to use the geometry service to project or simplify geometries. Use esri.config.defaults to specify the geometry service for your application.
It is recommended that you create a geometry service for use within your applications. View the Geometry Services help topic in the Server Resource Center for details on creating and publishing a geometry service. ESRI hosts a geometry service on sampleserver3 to support samples published in the Resource Center. You are welcome to use this service for development and testing purposes. ESRI also hosts a geometry service on tasks.arcgisonline.com; this service can be used for production applications however, we do not guarantee that the service will be available 24/7.
From: measurement | API Reference | ArcGIS API for JavaScript
Is there any formula to calculate measurement without firing request to geometry service?
It depends on what unit of measurement you are using and what the coordinate system of your map is.
How to display distance in the center of the edge? I am able to get distance using geometry service as you suggested before. But not sure how to position TextSymbol on the edge so, it doesn't overlap on line.