Select to view content in your preferred language

Setting scale for map works incorrectly

2465
4
06-04-2010 05:43 AM
JanKlosinski
Emerging Contributor
hello,

I'm using a tiled layer and graphics layer. My tiled layer displays a background, and graphics layer displays thematic polygons. What I'm trying to do is zoom to show all features existing on the graphics layer. To do this, I calculate the extent of all features, then calculate a scale based on this extent, and then loop through all LODs to find the first one which is big enough to contain my extent. Then, I set the map's scale to the scale of the LOD I found. It seems that the map applies a different scale to what I try to set. Below is a sample trace:

 uk.co.informed.mapping.view.helper.IS_ExtentWizzard calcContainingExtent : calculated scale 1640465.5337176886
 uk.co.informed.mapping.view.helper.IS_ExtentWizzard calcContainingScale : containing LOD (com.esri.ags.layers::LOD)#0
  level = 2
  resolution = 705.556966669489
  scale = 2000000
 uk.co.informed.mapping.view.helper.IS_ExtentWizzard zoomToExtent : set map scale: 2000000
 uk.co.informed.mapping.view.helper.IS_ExtentWizzard onExtentChanged : (com.esri.ags.layers::LOD)#0
  level = 3
  resolution = 352.778483334745
  scale = 1000000
Extent[xmin=359546.6472328053,ymin=284198.9608246544,xmax=623424.9527671945,ymax=456707.63917534467]


Clearly, the map should set the scale to 2000000, and not 1000000. The map supports the following scales:
6400000
4200000
2000000
1000000
600000
400000
200000
100000
50000
25000

It happens using both 1.2 and 1.3 versions of the API.

Any thoughts?

cheers,
Jan
Tags (2)
0 Kudos
4 Replies
DasaPaddock
Esri Regular Contributor
I'll look at the issue of setting the map's scale separately, but I think this is a simpler way to do what you want:
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html?sample=SelectAndZoom
See the zoomToGraphics() function.
0 Kudos
DasaPaddock
Esri Regular Contributor
I'm not able to reproduce an issue with setting the map's scale with this test case. Can you try this code against your service?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags">

    <mx:Number id="testScale">4617149.97766929</mx:Number>

    <mx:HBox>
        <mx:Button label="Set Map Scale to: {testScale}" click="map.scale = testScale"/>
        <mx:Label text="Map Scale: {map.scale}"/>
    </mx:HBox>
    
    <esri:Map id="map" extentChange="trace(event)">
        <esri:ArcGISTiledMapServiceLayer
                url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
    </esri:Map>

</mx:Application>
0 Kudos
JanKlosinski
Emerging Contributor
Hi Dasa,

I tried our map service with your example and was unable to programmatically set the scale to 2M. Using the zoom control, however, updates the scale correctly. Could it be something with the config of our map server?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags">
    
    <mx:Script><![CDATA[
        import com.esri.ags.layers.LOD;

        import mx.formatters.NumberFormatter;

        private function onMapLoaded( event : MapEvent ) : void
        {
            var dp : Array = [];
            for each ( var lod : LOD in map.lods )
            {
                dp.push( lod.scale );
            }
            scaleCbx.dataProvider = dp;
        }
        import com.esri.ags.events.MapEvent;

        var formatter : NumberFormatter = new NumberFormatter();

        private function scaleLabelFunction( item : * ) : String
        {
            return formatter.format( item );
        }

        ]]>
    </mx:Script>
    
    <mx:Number id="testScale">4200000</mx:Number>

    <mx:HBox>
        <mx:ComboBox id="scaleCbx" change="map.scale = scaleCbx.selectedItem as Number"
            labelFunction="scaleLabelFunction"/>
        <mx:Label text="Map Scale: {map.scale}"/>
    </mx:HBox>

    <esri:Map id="map" extentChange="trace(event)" load="onMapLoaded( event )">
        <esri:ArcGISTiledMapServiceLayer
                url="http://213.225.144.91/arcgis_gps_staging/rest/services/PlacesIMFMapping/MapServer"/>
    </esri:Map>

</mx:Application>
0 Kudos
DasaPaddock
Esri Regular Contributor
Thanks for this test case. This does appear to be a bug in the Map. The zoom control is actually setting the map's level. Did my earlier solution work? Here's a workaround if you still want to use scale.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags">

    <mx:Script>
        <![CDATA[
            import com.esri.ags.layers.supportClasses.LOD;
            
            protected function setMapScale(value:Number):void
            {
                for each (var lod:LOD in map.lods)
                {
                    if (lod.scale == value)
                    {
                        map.level = lod.level;
                        break;
                    }
                }
            }
        ]]>
    </mx:Script>

    <mx:Number id="testScale">2000000</mx:Number>
    
    <mx:HBox>
        <mx:Button label="Set Map Scale to: {testScale}" click="setMapScale(testScale)"/>
        <mx:Label text="Map Scale: {map.scale}"/>
    </mx:HBox>
    
    <esri:Map id="map" extentChange="trace(event)">
        <esri:ArcGISTiledMapServiceLayer
            url="http://213.225.144.91/arcgis_gps_staging/rest/services/PlacesIMFMapping/MapServer"/>
    </esri:Map>
    
</mx:Application>
0 Kudos