1

I'm having some problems setting the Map extent using ArcGIS API for JavaScript 3.18.

Whenever I call setExtent with myExtent, the Map ends up at some extent that is close to, but significantly different than myExtent. For example I call setExtent with:

myExtent = Object {type: "extent", xmin: -13486723.42416174, ymin: 6046817, xmax: -11828314.857440159, ymax: 8563452}

Then I handle the extent-change event to log the actual extent:

actualExtent = Object {type: "extent", xmin: -13334853.828803658, ymin: 6277279.110955888, xmax: -11980184.45279824, ymax: 8332989.889044112}

In this example the actualExtent is significantly more zoomed in than myExtent. But sometimes it's more zoomed out, sometimes it's more north, etc. Basically the Map seems to be snapping myExtent to certain zoom levels and positions.

Our server is ArcGIS Server 10.4.1. I have an ArcGIS API for Silverlight client connected to the same server doing the same work but it doesn't have this snapping problem. Can anyone suggest why this is happening and how to stop it?

UPDATE: To clarify how I build and set myExtent, it goes a little like this:

let myExtent = angular.copy(this.map.extent);
myExtent.xmin = -13486723.42416174;  // calculated
myExtent.ymin = 6046817;  // calculated
myExtent.xmax = -11828314.857440159;  // calculated
myExtent.ymax = 8563452;  // calculated
this.map.setExtent(myExtent);
  • Are you using a Cached service? – Midavalo Oct 28 '16 at 17:57
  • @Midavalo, no I'm not. – Corey Oct 28 '16 at 18:03
  • Have you tried setting the extent with the spatial reference defined in the extent object? – Brian Oct 28 '16 at 19:12
  • Great questions. I should have clarified in my original post. @Brian, before I call setExtent I get the current Map.extent, clone it with angular.copy, then set the xmin, xmax, ymin, ymax properties. I figured this was the safest way not to break anything. Could this actually be causing a problem? – Corey Oct 31 '16 at 15:54
  • I found this snapToZoom setting in [version 4.1][2] that defaults to true. I'm pretty sure this is exactly what I'd like to set to false to fix my problem. But version 3.18 doesn't have this setting so I think I'm out of luck. [2]: developers.arcgis.com/javascript/latest/api-reference/… – Corey Nov 4 '16 at 20:38
1

If you'd like a guarantee that the input extent will be shown completely on the map when calling setExtent() you should pass the value true as the second (optional) fit parameter.

map.setExtent(myExtent, true);

https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#setextent

|improve this answer|||||
  • Thanks, but the docs say that is for Tiled map layers. I'm using Dynamic (I should have mentioned this in my original post). Also, that wouldn't really help as I'm trying to get actualExtent to match myExtent, not just include myExtent. – Corey Oct 31 '16 at 16:06
  • perhaps im missing something, but there's no way to guarantee that ratio of height x width of a passed extent is going to align exactly with the ratio of the window in which the map is being displayed. – John Gravois Nov 3 '16 at 20:43
  • I calculate myExtent to match the aspect ratio of the map element. – Corey Nov 4 '16 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.