Extent doesn't work when resolution changes?

1000
9
03-25-2011 07:01 AM
karldailey
New Contributor
I dont know if I am doing something wrong, but it seems the 'extent' attribute of a map doesnt work.  If I set the min/max x/y's, it zooms to the proper map (say the 48 continuous states), but if I open in a non-full screen browser, or computer with a different screen resolution, then much of the map will be off the screen.  how do i get this to work?

<esri:Extent id="initialExtent" xmin="-13001000" ymin="3292000" xmax="-8812000" ymax="6154000">
     <esri:SpatialReference wkid="102100"/>
</esri:Extent>

and onload: myMap.extent=initialExtent;
Tags (2)
0 Kudos
9 Replies
Drew
by
Occasional Contributor III
It should scale properly.
I would check that your Application width and height properties = 100% along with the maps parent containers.


Drew
0 Kudos
GregKnight
Occasional Contributor
im not sure where you have that extent definition in the page, but it looks incomplete.
id try dropping it inside the <map> element as follows:

 <esri:Map id="map">
  <esri:extent>
                    <esri:Extent id="initialExtent" xmin="-13001000" ymin="3292000" xmax="-8812000" ymax="6154000">
                    <esri:SpatialReference wkid="102100"/>
                    </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer id="tiledlayer"
       url="<someurl>"
  </esri:ArcGISTiledMapServiceLayer>
 </esri:Map>


then ditch the load event.  make sure you include the surrounding "esri:extent" tags.
0 Kudos
karldailey
New Contributor
cgishack, they are 100%, with height and width set at 100% for both the parent containers and the map itself.  but it still does not work.  gkknightk between the new API and version of flex, the extent tags have changed.  Even using the sample on ESRI's site, it STILL doesnt work.  So far, I havent been able to get scaling working, is there something I am doing wrong?  If not, this seems like a glaring bug thats been around from the beginning. 

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:esri="http://www.esri.com/2008/ags"
      pageTitle="World Topographic Map">

<fx:Declarations>
  <esri:Extent id="initialExtent" xmin="-13001000" ymin="3292000" xmax="-8812000" ymax="6154000">
   <esri:SpatialReference wkid="102100"/>
  </esri:Extent>
</fx:Declarations>

<esri:Map extent="{initialExtent}">
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
</esri:Map>
</s:Application>
0 Kudos
KenBuja
MVP Esteemed Contributor
This is more of an issue with resolution of the basemaps you're using and the size of their tiles. Tiled map services will show the data at a specific scale, which is dependent on the size of your map. If the extent you've designated doesn't match the tiled service's scale, I believe it zooms in to a smaller extent. You'll be able to have the precise extent when using a dynamic service, but tiles services are a bit more finicky.
0 Kudos
karldailey
New Contributor
im not sure that makes sense, the extent is with the Map tag, and inside that map tag it can have both dynamic and tiled maps.  Also that doesnt change the fact that the 'extent' feature doesnt work =|
0 Kudos
KenBuja
MVP Esteemed Contributor
Think of it this way. Say you've set the extent so the X difference is 100,000 units. You've set the size of your map to be 1 unit wide, which makes the scale of your displayed map 1:100,000. If the tiled layer is set up with the Web mercator standard levels of detail at 1:144,447.638572 and 1:72,223.819286, the extent of the map will have to change to fit one of those scale. When you're using tiled layers, you cannot set arbitary scales, but have to use the pre-determined scales. If you're using only dynamic layers, you can set any scale you'd like.
0 Kudos
karldailey
New Contributor
So far I have gotten around it by setting the scale with myMap.scale attributes based off the map size.  I had to use the creationComplete method of the map, because the map width is 0 when initialized.  then I used map method centerAt to center the map appropriately.

Still, it seems the extent feature is bugged.  it dosnt really make a difference if it doesnt work for one reason or another, it it doesnt set your extent for all screen sizes then it dont work.
0 Kudos
karldailey
New Contributor
Think of it this way. Say you've set the extent so the X difference is 100,000 units. You've set the size of your map to be 1 unit wide, which makes the scale of your displayed map 1:100,000. If the tiled layer is set up with the Web mercator standard levels of detail at 1:144,447.638572 and 1:72,223.819286, the extent of the map will have to change to fit one of those scale. When you're using tiled layers, you cannot set arbitary scales, but have to use the pre-determined scales. If you're using only dynamic layers, you can set any scale you'd like.


I tried with dynamic layers, one time i got the issue one time i didnt, will have to test more
0 Kudos
KenBuja
MVP Esteemed Contributor
I've run some tests using a slight modification of the Map Extent and Mouse Coordinates sample, using different browser sizes with either the dynamic or tiled version of the same service. The reports the X and Y min/max as well as the scale of the map. I changed the size and shape of the window for each test. You can run the same code, changing the dimensions of the browser for each one.

For each dynamic version, either the X Min/Max or the Y Min/Max are exactly what is used in the Extent tag. You'd have to get the browser proportions exactly right to get both X and Y extents to match up.

For the tiled versions, notice that while the X and Y extents are not what you put in, the scale of each window is what the scale is shown for the tile LODs (see the map service page for them).

<?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:esri="http://www.esri.com/2008/ags"
               pageTitle="Map Extent and Mouse Coordinates">
    <!--
    The current extent of the map is available directly through myMap.extent.
    Similarly, the current scale is myMap.scale.
    
    Other properties easily accessible is myMap.
    
    To get the current coordinates of the mouse cursor, you can add an event listener for "MOUSE_MOVE"
    on the map. In the listener you can access the current stage location using stageX and stageY.
    Then use the toMapFromStage method to easily get those stage coordinates into map coordinates.
    -->
    <fx:Script>
        <![CDATA[
            import com.esri.ags.events.ExtentEvent;
            import com.esri.ags.geometry.Extent;
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.utils.WebMercatorUtil;
            
            // when mouse (cursor) is on the map ...
            private function loadHandler():void
            {
                myMap.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
            }
            
            // ... show coordinates of current (mouse) location
            private function mouseMoveHandler(event:MouseEvent):void
            {
                const mapPoint:MapPoint = myMap.toMapFromStage(event.stageX, event.stageY);
                const latlong:MapPoint = WebMercatorUtil.webMercatorToGeographic(mapPoint) as MapPoint;
                mousecoords.text =
                    "x,y is " + mapPoint.x.toFixed(0) + "," + mapPoint.y.toFixed(0)
                    + " and Lat/Long is: " + latlong.y.toFixed(6)
                    + " / " + latlong.x.toFixed(6);
            }
            
            // convert current projected extent to geographic and show as such
            protected function showExtentInGeographic(extent:Extent):String
            {
                const geoExtent:Extent = WebMercatorUtil.webMercatorToGeographic(myMap.extent) as Extent;
                // return geoExtent.toString() + ".." ;
                return " " + geoExtent.xmin.toFixed(6)
                    + ", " + geoExtent.ymin.toFixed(6)
                    + ", " + geoExtent.xmax.toFixed(6)
                    + ", " + geoExtent.ymax.toFixed(6)
                    + "   (wkid: " + geoExtent.spatialReference.wkid + ")";
            }
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <esri:Extent id="initialExtent" xmin="-13001000" ymin="3292000" xmax="-8812000" ymax="6154000">
            <esri:SpatialReference wkid="102100"/>
        </esri:Extent>
            
    </fx:Declarations>
    <s:layout>
        <s:VerticalLayout paddingTop="6"/>
    </s:layout>
    
    <s:HGroup>
        <s:Label fontWeight="bold" text="Current map extent:"/>
        <s:RichEditableText editable="false" text='xmin="{myMap.extent.xmin.toFixed(0)}" ymin="{myMap.extent.ymin.toFixed(0)}" xmax="{myMap.extent.xmax.toFixed(0)}" ymax="{myMap.extent.ymax.toFixed(0)}"   (wkid="{myMap.spatialReference.wkid}")'/>
    </s:HGroup>
    <s:HGroup>
        <s:Label fontWeight="bold" text="Current map extent (in geographic):"/>
        <s:RichEditableText editable="false" text="{showExtentInGeographic(myMap.extent)}"/>
    </s:HGroup>
    <s:HGroup>
        <s:Label fontWeight="bold" text="Current Mouse Coordinates:"/>
        <s:RichEditableText id="mousecoords"
                            editable="false"
                            text="Move the mouse over the map to see its current coordinates..."/>
    </s:HGroup>
    <s:HGroup>
        <s:Label fontWeight="bold" text="Current map scale is"/>
        <s:RichEditableText editable="false" text="1:{myMap.scale.toFixed(0)} (level {myMap.level})"/>
    </s:HGroup>
    
    <esri:Map id="myMap" load="loadHandler()" extent="{initialExtent}">
<!--        <esri:extent>
            <esri:Extent xmin="3035000" ymin="4305000" xmax="3475000" ymax="10125000">
                <esri:SpatialReference wkid="102100"/>
            </esri:Extent>
        </esri:extent>-->
<!--        <esri:ArcGISDynamicMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
-->        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
    </esri:Map>
    
</s:Application>
0 Kudos