Hi,
The JS API samples show how to create a map, but the starting location/zoom is always based on a Lat,Lng pair along with a zoom level. Is it possible to override these parameter using a bounding box coordinate pair, or similar and the centre + zoom level is picked up automatically from there?
API Samples usually have:
map = new Map("map", { basemap: "topo", center: [-108.663, 42.68], zoom: 6 }
Whereas I would need something like:
map = new Map("map", { basemap: "topo", bounds: [-108.663, 42.68;-107.63, 43.68] }
So the zoom takes care of itself and it isn't required.
Thanks for any help you can offer. Used to doing this through Google Maps API, now trying to switch over to the JS API for the increased GIS functionality.
BC
Solved! Go to Solution.
You need to require any class you use in your code. So yes you need to add "esri/geometry/Extent"
BC,
Sure you can but it is not called bounds it is extent
var map = new Map("map", {
extent: new Extent({xmin:-20098296,ymin:-2804413,xmax:5920428,ymax:15813776,spatialReference:{wkid:54032}})
});
Thanks a lot Robert,
I'm definitely getting closer. But getting this error
Uncaught ReferenceError: Extent is not defined
at index.html:55
at fa (init.js:28)
at init.js:28
at ga (init.js:28)
at da (init.js:28)
at s (init.js:30)
at HTMLScriptElement.<anonymous> (init.js:35)
Do I need to declare Extent somewhere or should it be already available?
You need to require any class you use in your code. So yes you need to add "esri/geometry/Extent"
Ah haaaa...
I hadn't declared SpatialReference either!
All working great now.
Thanks a lot Robert, and so the adventure starts...
Thanks Robert,
Still no map, unfortunately. I am looking for a default load bounding box, and not the extents that a user can pan to.
Beginning to see how the API is working, but can't see the end result here.
<script src="https://js.arcgis.com/3.19/"></script>
<script>
var map;
require(["esri/map", "esri/geometry/Extent", "dojo/domReady!"], function(Map,Extent) {
map = new Map("map", {
extent: new Extent({xmin:-20098296,ymin:-2804413,xmax:5920428,ymax:15813776,spatialReference:{wkid:54032}})
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>