This must be an easy one, but i am having a hard time with this.
How do i read the linear distance units of a feature layer or a dynamic map service using the javascript API?
for e.g., wkid 4326 it is degrees, 102100 it is meters and for some it is feet etc.,
what about spatial references which have only a WKT (custom) and no WKID?
i need to display the linear units of a layer (feature/dynamic) programatically to show the units in which the areas and lengths are being displayed in a popup.
Solved! Go to Solution.
All,
They have added getUnitValueForSR(sr) ability in 3.13
esri/geometry/scaleUtils | API Reference | ArcGIS API for JavaScript
If you are referring to the feature attributes then the values will be in the coordinate system of the source data.
When working with a map service you can access the spatialReference property. However the SpatialReference class does not contain a property for linear units.
If you need the linear units then you could create a function to lookup the value based on a WKID. The following links contain all supported coordinate systems and includes the linear unit values:
Hi Owen, thank you so much for the response, but seriously,
Something as fundamental as this is not provided out of the box in the API?
maybe i dont understand the complexity of the problem that the API team may have in providing this OOTB.
As you say, we'l have to create a function to read the WKT value based on a WKID from the links you posted and then extract the units from the WKT and convert them to esriLinearUnits, correct?
I was also very surprised to see how little information was contained in the JS API SpatialReference object.
If you know the WKID you can look up the WKT on EPSG Geodetic Parameter Registry.
E.g., http://www.epsg-registry.org/export.htm?wkt=urn:ogc:def:crs:EPSG::2927
All,
They have added getUnitValueForSR(sr) ability in 3.13
esri/geometry/scaleUtils | API Reference | ArcGIS API for JavaScript