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);
1 Answer 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
-
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 matchmyExtent
, not just includemyExtent
.Corey– Corey2016年10月31日 16:06:09 +00:00Commented Oct 31, 2016 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– john gravois2016年11月03日 20:43:29 +00:00Commented Nov 3, 2016 at 20:43
-
I calculate myExtent to match the aspect ratio of the map element.Corey– Corey2016年11月04日 20:20:08 +00:00Commented Nov 4, 2016 at 20:20
Explore related questions
See similar questions with these tags.
setExtent
I get the currentMap.extent
, clone it withangular.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?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/…