Select to view content in your preferred language

How to zoom to a non-Web Mercator extent?

2987
12
Jump to solution
08-14-2013 03:56 AM
StephenLead
Honored Contributor
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>
0 Kudos
12 Replies
JohnGravois
Deactivated User
@Jason.

thanks for the feedback.  i took a look at the documentation for some other popular classes and it seems that in most other similar instances, the description makes it a little clearer when a property is determined by the service itself.

i'm under the impression that we don't denote "read-only" for properties in the API because the concept is not actually enforced, but i agree with you that providing additional information to developers regarding individual properties is warranted.

the only other potential candidate i have found so far is Layer.capabilities.  can you think of any others for me to include in my request to the development team?
0 Kudos
JasonZou
Frequent Contributor
Thanks John for looking into this issue. To be honest, I am not good at documenting the issues I've experienced. I know maxRecordCount is a read-only property since we tried to control how many features can be returned at the feature layer level and failed. It cannot be even controlled at the map service level via JS api. The only way to control is to change the settings via ArcGIS Server Manager or ArcCatalog (maybe?). In general, I know Javascript allows modifying any property of an object. The only issue is whether JS API will honor the change or not. I can easily tell a property is read-write if there is a setter method for it. Otherwise, I will need to guess.
0 Kudos
JohnGravois
Deactivated User
you are correct.  maxRecordCount is a property set at the map service level at the time of publishing.

i found a couple other properties whose description seems to be a little ambiguous about the fact that the property is determined by the service itself.  if anyone else was confused by another one.  id love to hear about it.

FeatureLayer.hasAttachments
FeatureLayer.hasAttributionData
FeatureLayer.supportsStatistics
FeatureLayer.supportsAdvancedQueries
0 Kudos