y values not honored in initial extent

1124
5
04-25-2017 07:36 AM
deleted-user-3QvhwBivZdaR
New Contributor III

I am trying to set the initial extent of a basemap, but for some reason I cant see, the x values are honored while the y values are ignored.  i am using 3.10 JS API.

var initialExtent = new esri.geometry.Extent({

"xmin":969819.213195 ,

"ymin":187672.422691 ,

"xmax":1035263.657639 ,

"ymax": 225505.756024,

"spatialReference": {
"wkid": 102718
}
});

the I add to map constructor:

map = new Map("map", {
zoom: 3,
sliderPosition: "top-right",
sliderStyle: "small",
extent: initialExtent,
infoWindow: infoWindowPopup
});

and I check it with:

dojo.connect(map, "onExtentChange", showExtent);
function showExtent(extent) {
var s = "";
s = "XMin: "+ extent.xmin.toFixed(6) + " "
+"YMin: " + extent.ymin.toFixed(6) + " "
+"XMax: " + extent.xmax.toFixed(6) + " "
+"YMax: " + extent.ymax.toFixed(6);
console.log('s: ' + s);

on the initial load, the x values are exactly what I have above, but the y values are both lower values.  Even if I move the map, and add the new extent given in console to the code, the map does not set to my y values after refresh.

What is happening here? I know the extent I am trying to set is well within the extent of the basemap.extent calculation javscript api 

0 Kudos
5 Replies
ThomasSolow
Occasional Contributor III

To start with, what happens if you remove the zoom: 3?  In general, I'm not sure if setting the zoom and the extent makes sense, since they should do the same thing.

I would suggest using a center and a zoom rather than an extent for this kind of thing.  So you could zoom to the perspective you like, and log the center and zoom and pass those in instead of using an extent.

Setting an extent can be a little tricky as I recall (been a while since I worked with 2D).  For an extent to be possible to fit exactly to a map, the ratio between its height and width must be the same as the ratio between the map div's height and width.

If your map is much wider than it is tall, it may not be possible to fix your xmin, xmax, ymin, ymin as the corners of the map div.  In these situations, it would be preferable (in my opinion) if the map guaranteed than the entire extent was fit and never cut anything off.   But this may not be done.  My bet is that the map takes whichever dimension is longer (in this case, x, or width) and cuts off the other dimension.  This would work perfectly if the map div was a square, but if it's not it may cause one dimension to get cut off a bit.

deleted-user-3QvhwBivZdaR
New Contributor III

ps I did try center and zoom but still cant set the initial extent the way I want...

0 Kudos
deleted-user-3QvhwBivZdaR
New Contributor III

ok Ill look at those things..I guess I assumed the map's extent in a web app would be tied to the size  / dimensions of the viewport...

one thing, the y values that change seem to both move 'down'...it doesnt appear to be resetting the extent based on a different proportion...but Ill try some other methods anyway

0 Kudos
KenBuja
MVP Esteemed Contributor

It's almost impossible to set the exact min and maxes of an extent when you're dealing with a tiled basemap. The zoom levels are set to specific scales which probably don't conform to the extent that you're attempting to set.

deleted-user-3QvhwBivZdaR
New Contributor III

that makes sense I suppose, but what is a workaround then? Do we need to make a basemap for every web app? It's so easy to set any extent and zoom level, basemap included, on ArcGIS Online, why cant it be so with a JS based web app?

0 Kudos