There is a function in my map that works very nicely for zooming to a polygon (parcel) that has been selected:
_zoomToParcel: function(parcel) {
this.map.setExtent(parcel.geometry.getExtent().expand(1.5));
}
The end user has requested that the zoom level be restricted to no more than 18. If it's a very small parcel, the zoom level may be 19 or 20, and then they have to zoom back out to find enough surroundings to orient themselves. Fair enough. I thought this would be as simple as adding in a get/set zoom:
_zoomToParcel: function(parcel) {
this.map.setExtent(parcel.geometry.getExtent().expand(1.5));
if (this.map.getZoom() > 18) {
this.map.setZoom(18);
}
}
However, this appears to be getting the zoom level from before the application resets the extent to the parcel. When I console.log the results of this.map.getZoom()
, it tells me the initial zoom level (5), not the new zoom level (20) after the extent is reset. Running that function if the map starts off very zoomed-in (e.g. 20) will zoom it back out to 18, meaning the get/set logic works — I'm just not getting the "right" zoom.
How can I catch whether the map has zoomed in too far?