Extents Problem

798
6
08-08-2012 04:33 PM
MarkPaulson
New Contributor III
This is driving me nuts. I'm a newbie to Javascript and started working on this during a course I am taking. I'm trying to limit my initial view to the second image attached. The tiled layer is causing my headaches. The code below is what I am using:

unction init() {
    //var map = new esri.Map("mapDiv");       
         var map = new esri.Map("mapDiv", {
           extent: new esri.geometry.Extent({xmin:-10719077,ymin:3177160,xmax:-11321168,ymax:3474629, "SpatialReference": {"wkid":102100}})
         });
     
         //create tiled map layer
        var tiled = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        //add layer to map
       map.addLayer(tiled);
       
        //create dynamic map layer

       var dynamic = new esri.layers.ArcGISDynamicMapServiceLayer("http://www.geoiddata.com/arcgis/rest/services/Hawk/MapServer") 
        //add layer to map
        map.addLayer(dynamic);
      
When I leave the tiled layer un-commented out I get the attached image one. When I comment it out I get image two which is what I am expecting with the street map as background.
0 Kudos
6 Replies
derekswingley1
Frequent Contributor
Is this what you're going for:  http://jsfiddle.net/Vhn45/

Also check out the help topic on working with extents.
0 Kudos
by Anonymous User
Not applicable
Original User: txrpls

Is this what you're going for:  http://jsfiddle.net/Vhn45/

Also check out the help topic on working with extents.


That is exactly what I was trying to do. I briefly scanned the link on extents before I went to bed. If it is not too much of an effort, would you tell me where I was going wrong?

Thanks again for the code I will disect it and studdy it in detail later today.

Mark
0 Kudos
derekswingley1
Frequent Contributor
I changed the values passed to esri.geometry.Extent. Instead of what you posted, I took the values from the default view of the map service here:  http://www.geoiddata.com/arcgis/rest/services/Hawk/MapServer?f=jsapi

Since that is a page built with the JS API, and the map is available via a global variable named "map", you can open the console and to this: 
dojo.toJson(map.extent.toJson());


Which gives you:
"{"xmin":-11216835.021871055,"ymin":3398518.1829228727,"xmax":-10843258.104015714,"ymax":3553770.9280056115,"spatialReference":{"wkid":102100}}"


Remove the leading and trailing double quotes and you can pass that to esri.geometry.Extent, as shown in the link I posted initially.
0 Kudos
by Anonymous User
Not applicable
Original User: txrpls


"{"xmin":-11216835.021871055,"ymin":3398518.1829228727,"xmax":-10843258.104015714,"ymax":3553770.9280056115,"spatialReference":{"wkid":102100}}"



Derek


I change my code to use your max and mins accordingly and my code worked although, not near as elegant as yours. I retreived my max/mins from my MXD as I wanted it smaller that the initial extents. Do you think the extents where not large enough and that was causing the problem?
0 Kudos
derekswingley1
Frequent Contributor
Taking a closer look at your original code, I see that xmin is actually larger than xmax. That's likely what was causing your issue.
0 Kudos
by Anonymous User
Not applicable
Original User: txrpls

Taking a closer look at your original code, I see that xmin is actually larger than xmax. That's likely what was causing your issue.


I must have looked at that a dozen times last night. I'll remove my head a move on. 🙂
0 Kudos