Set start location based on extents rather than a centre point and zoom

1101
5
Jump to solution
02-01-2017 06:22 AM
BrendanCunningham1
New Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

You need to require any class you use in your code. So yes you need to add "esri/geometry/Extent"

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

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}})
  });
BrendanCunningham1
New Contributor III

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?

RobertScheitlin__GISP
MVP Emeritus

You need to require any class you use in your code. So yes you need to add "esri/geometry/Extent"

0 Kudos
BrendanCunningham1
New Contributor III

Ah haaaa...

I hadn't declared SpatialReference either!

All working great now.

Thanks a lot Robert, and so the adventure starts...

0 Kudos
BrendanCunningham1
New Contributor III

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>

0 Kudos