Getting IntialExtent of the ArcGISDynamicMapServiceLayer

939
3
Jump to solution
09-21-2014 09:36 PM
tejasnadkarni
New Contributor

I am using arcgis javascript api in my application and working with a dynamic map service resource exposed by the ArcGIS Server REST API . Hence I am making using of the ArcGISDynamicMapServiceLayer to load.

But after adding the layer of ArcGISDynamicMapServiceLayer to the map, the map is not taking projection of this layer.

So i tried using GeometryService.project by passing the ProjectParameters() and i am trying to set the  ArcGISDynamicMapServiceLayer.initialExtent and project toward it.

But i am getting ArcGISDynamicMapServiceLayer.initialExtent as

{

spatialReference: { wkid: 4326}

type: "extent"

xmax: 180

xmin: -180

ymax: 90

ymin: -90

}

on the first load and then after that works fine.

So what is the best way if i just want to load a map and then project towards ArcGISDynamicMapServiceLayer layer on the map?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

In your code, you're converting the the geographic extent to Web Mercator, but you're then trying to set the map's extent to the geographic extent. This is shown in Firebug's debugging console.

firebug.png

Use this code instead.

on(map, "layer-add-result", function () {

  var extent = webMercatorUtils.geographicToWebMercator(dynamicLayer.initialExtent);

  map.setExtent(extent, true);

});

Here's the updated Fiddle.

View solution in original post

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Tejas,

You can set the extent of the map to the dynamic service layer using the Map class setExtent method and the layer-add-result event. Here is an example.

0 Kudos
tejasnadkarni
New Contributor

Thanks Jake,

I tried setting the extent using the setExtent on the map but the problem is that its just showing me the world street map. Its like the my dynamic service layer is about a particular city/state and so i expect to display street view of that particular city/state when i first initialized the map.

http://jsfiddle.net/bqqof5yk/1/

Check this link. By default it shows the world map but if you zoom in towards the KANSAS you will see the graphics on the map.

I want to see that KANSAS state when the map is first initialized.

0 Kudos
KenBuja
MVP Esteemed Contributor

In your code, you're converting the the geographic extent to Web Mercator, but you're then trying to set the map's extent to the geographic extent. This is shown in Firebug's debugging console.

firebug.png

Use this code instead.

on(map, "layer-add-result", function () {

  var extent = webMercatorUtils.geographicToWebMercator(dynamicLayer.initialExtent);

  map.setExtent(extent, true);

});

Here's the updated Fiddle.

0 Kudos