AnsweredAssumed Answered

How to zoom to a non-Web Mercator extent?

Question asked by stevel on Aug 14, 2013
Latest reply on Aug 15, 2013 by JGravois-esristaff
Given an ArcGIS Server service which is stored in non-Web Mercator coordinates, how can I zoom to its extent when the map is using Web Mercator?

There is a method geographicToWebMercator - but what if the original coordinates are not geographic?

Below is some sample code to illustrate the problem.

Thanks,
Steve

<!DOCTYPE html> <html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">     <title>Zoom to non-WM dynamic layer</title>     <link rel="stylesheet" href="http://js.arcgis.com/3.6/js/esri/css/esri.css"/>     <style>       html,body,#mapDiv{         padding:0;         margin:0;         height:100%;       }     </style>     <script src="http://js.arcgis.com/3.6/"></script>     <script>       dojo.require("esri.map");       var map;       var url = "http://loczy.mfgi.hu/ArcGIS/rest/services/TJAM/surf_ujfalu_t/MapServer/"         function init() {                  //Get the layer's extent from ArcGIS Server         esri.request({        url: url,   content: {f:  "json"},   handleAs: "json",   callbackParamName: "callback",   load: function(response) {                //Create the map. Since we're specifying the Gray basemap it'll use Web Mercator    map = new esri.Map("mapDiv", {basemap: "gray"});      //Add the dynamic layer. Although it's not stored in Web Mercator, it's automatically    //projected on-the-fly and displays in the correct location    var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(url);            map.addLayer(dynamicMapServiceLayer);                //Zoom the map to the new layer's extent. This fails, since the extent doesn't use WM    map.setExtent(response.initialExtent);               },       error: function (error) {          alert("Sorry, there was a problem zooming to the new layer");               }  });   }         dojo.ready(init);     </script>   </head>   <body>     <div id="mapDiv"></div>\   </body> </html>

Outcomes