Select to view content in your preferred language

Get Maps DistanceUnit?

1284
2
06-02-2010 09:37 AM
RyanCoodey
Frequent Contributor
Is their a way to get a Map objects DistanceUnit?  I need to feed this to the MeasureAction.MapUnits... i don't want to hard code it because it can potentially change in my app.  Can i get more info, such as this, than just the WKID from the Spatial Reference?

Thanks a lot!
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
ArcGISTiledMapServiceLayer and ArcGISDynamicMapServiceLayer have both a method 'Units' which is a string such as 'esriDecimalDegrees'.
On the 'Initialized' event, you might convert this string to an esriUnits enum by using Enum.Parse. Something like :
esriUnits units = (esriUnits)Enum.Parse(typeof(esriUnits), myMapServiceLayer.Units, true);
0 Kudos
RyanCoodey
Frequent Contributor
Great, thanks a lot dbroux.  What i did is spin through the layers until I found the first occurance of this type and also where the Maps SpatialReference is equal to the Layers SpatialReference.

            if (MapUnit != DistanceUnit.Undefined)
                measureAction.MapUnits = MapUnit;
            else
            {
                //Try and get proper map units if not specified by user
                String sUnits = "";
                for (Int32 i = 0; i < Map.Layers.Count; i++)
                {
                    if (Map.SpatialReference.WKID == Map.Layers.SpatialReference.WKID)
                    {
                        if (Map.Layers is ArcGISDynamicMapServiceLayer)
                        {
                            sUnits = ((ArcGISDynamicMapServiceLayer)Map.Layers).Units;
                            break;
                        }
                        else if (Map.Layers is ArcGISTiledMapServiceLayer)
                        {
                            sUnits = ((ArcGISTiledMapServiceLayer)Map.Layers).Units;
                            break;
                        }
                    }
                }
                esriUnits units = (esriUnits)Enum.Parse(typeof(esriUnits), sUnits, true);
                DistanceUnit distanceUnit = Utility.Utility.esriUnitsToDistanceUnit(units);

                if (distanceUnit != DistanceUnit.Undefined)
                    measureAction.MapUnits = distanceUnit;
                //Default to DecimalDegrees if nothing else
                else
                    measureAction.MapUnits = DistanceUnit.DecimalDegrees;


Thank you!!!
0 Kudos