JavaScript 4.x - looking to have the map scale update on Extent Change

1049
2
Jump to solution
04-04-2019 01:29 PM
IanPeebles
Regular Contributor

Has anyone been successful getting the map scale to update in console.log when an extent change is performed (through zooming with the mouse event: "zoom-end")?

I am looking for a method in the 4.x API that is similar to the following methods using the 3.x API:

will update when "zoom-end" is completed.

getScale()

getZoom()

I do have this working in the 3.x environment, but not having much luck using the 4.x API reference.

Here is a block of code I used for the 3.x API and it works well:

// Return Map Scale Results to Application - Calculation (/12) based on Feet NOT Meters
  map.on("zoom-end", function() {
  var returnZoomResult = document.getElementById("zoomToScaleResults");
  var scale = map.getScale()/12;
  var roundScale = Math.round(scale);
  returnZoomResult.innerHTML = roundScale + " feet";
});

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor
2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor
IanPeebles
Regular Contributor

Robert,

Thanks you for the input:  I did try the following:

// Watch for the Scale on the Extent Change
   mapView.watch('extent', function(){
   console.log("Watch for the current scale: ", mapView.scale);
});

This is what I am wanting .  Each time the extent changes, the scale refreshes.