map.units support in agslib-3.0pre-2012-03-15

1228
12
04-15-2012 08:40 PM
TomSchuller
Occasional Contributor III
Hy,
I just wanted to migrate some widgets to the FlexViewer3.0.
Unfortantly, I'm blocked by the property "units" in the "Map" class.

In the "What's new" and "Migrating 2.5 to 3.0", I dont' find anything about a change on that property:
  http://resourcesbeta.arcgis.com/en/help/flex-api/concepts/index.html#/What_s_new_in_ArcGIS_API_for_F...
  http://resourcesbeta.arcgis.com/en/help/flex-api/concepts/index.html#/Migrating_from_2_5_to_3_0/017p...

In the API reference, I don't find a description for units:
http://resourcesbeta.arcgis.com/en/help/flex-api/apiref/com/esri/ags/Map.html#units
On the other side, reading the doc of the scale property, there is a relation to "units":
http://resourcesbeta.arcgis.com/en/help/flex-api/apiref/com/esri/ags/Map.html#scale

Is this a bug of a missed property or an undocumented change in the 3.0 api.

Thanks,
Tom
Tags (2)
0 Kudos
12 Replies
IvanBespalov
Occasional Contributor III
Tom,
yes "units" property is not in reference (I do not know why), but it is String type property and it exists:
units property 
units:String
The units of the Map.
These units are used for calculating the map scale. The default value is the units of the first layer added to the map.
This property can be used as the source for data binding.


map.units = Units.METERS;


see com.esri.ags.Units
0 Kudos
TomSchuller
Occasional Contributor III
It's not only missed in the reference, it's also missed in the library itself.

I can't use:
map.units

in my code.

Tom
0 Kudos
IvanBespalov
Occasional Contributor III
:confused:

it's also missed in the library itself


[ATTACH=CONFIG]13541[/ATTACH]

test:
protected function onWidgetOpen(event:Event):void
{
    Alert.show("Map units are: '" + map.units + "'", "onWidgetOpen");
}

[ATTACH=CONFIG]13542[/ATTACH]




No comments.
0 Kudos
TomSchuller
Occasional Contributor III
I'm on agslib-3.0pre-2012-03-15

Your version is on: beta1 2011-12-16

Tom
0 Kudos
IvanBespalov
Occasional Contributor III
Your version is on: beta1 2011-12-16

Tom, you're right. I did not pay attention to it.
0 Kudos
IvanBespalov
Occasional Contributor III
Map units are the first loaded layer units.
Until ESRI developers complete reference (or fix bugs), you can use first layer units:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      xmlns:esri="http://www.esri.com/2008/ags">
 <s:layout>
  <s:VerticalLayout />
 </s:layout>
 <fx:Script>
  <![CDATA[
   import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
   import com.esri.ags.layers.Layer;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   
   
   protected function button1_clickHandler(event:MouseEvent):void
   {
    var layer:Layer = getMapFirstLayer();
    if (layer != null)
    {
     var message:String = "";
     if (layer is ArcGISTiledMapServiceLayer)
     {
      message = "Map units are: '" + ArcGISTiledMapServiceLayer(layer).units + "' - the first loaded layer units";
     }
     else if (layer is ArcGISDynamicMapServiceLayer)
     {
      message = "Map units are: '" + ArcGISDynamicMapServiceLayer(layer).units + "' - the first loaded layer units";
     }
     
     Alert.show(message, "Map units");
    }
   }
   
   private function getMapFirstLayer():Layer
   {
    if (map != null)
    {
     var mapLayers:ArrayCollection = map.layers as ArrayCollection;
     if (mapLayers != null && mapLayers.length > 0)
     {
      return mapLayers.getItemAt(0) as Layer;
     }
    }
    
    return null;
   }
   
  ]]>
 </fx:Script>
 <s:Button label="Show map units" click="button1_clickHandler(event)" />
 <esri:Map id="map">
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
 </esri:Map> 
</s:Application>
0 Kudos
BjornSvensson
Esri Regular Contributor
Is this a bug of a missed property or an undocumented change in the 3.0 api.


It's a yet-to-be documented change in the 3.0 API. Thanks for reminding us 🙂

We removed it because you no longer need to set it.  Based on the spatial reference, the API will now automatically figure out the units for you.
0 Kudos
TomSchuller
Occasional Contributor III
Bjorn,
i agree that it's not important to set that property.

But I think it's useful to read out the information, either as:

  • readonly map property like: map.units

  • or readonly spatialreference property like: map.spatialReference.units

The spatialReference class has currently also no-property defined to read it out:
http://resourcesbeta.arcgis.com/en/help/flex-api/apiref/com/esri/ags/SpatialReference.html

I hope you can re-implement it in your API or give some way to access it.
If it will not be exposed as property, I will have to create a lookup-table for each spatialReferece-wkid.

Thanks,
Tom
0 Kudos
BjornSvensson
Esri Regular Contributor
But I think it's useful to read out the information


Hi Tom,
I'm curious - what do you use it for?  Just to display it to end user (seems a little unnecessary) - or do you need it for something else?
0 Kudos