Select to view content in your preferred language

zoom level is not correct

667
1
12-18-2019 10:09 AM
RudySanchez
New Contributor

I am using view.zoom to get the current zoom level. while the map itself is zooming in and out correctly the value is incorrect. for example. The map starts at zoom level 9. I will scroll in and the value changes

10

11

12

13

14

15

16

17

then I scroll out and the zoom value increases instead of decreasing

18

Then after that initial zoom out, the value starts to decrease again.

17

16

This causes an issue because I am using that value to determine if I am going to display a parcel layer.

view.on('mouse-wheel', () => {
      const _coreLogicLayer = this.props.coreLogicLayer
      const _layer = map.layers.items.find(x => x.title === 'Core Logic')
      if (view.zoom >= 16 && !_layer) {
        map.add(_coreLogicLayer)
        const _layer0 = map.layers.items.find(x => x.title === 'Core Logic')
        map.reorder(_layer0, 0)
      } else if (view.zoom < 16 && _layer) map.remove(_coreLogicLayer)
    })

I am using 

"esri-loader": "^2.12.0"

in my react application.

1 Reply
Gianna_BBSRC
Regular Contributor

Hi Rudy, 

view.zoom only logs the current zoom level on mouse-wheel (i.e. the zoom level BEFORE the mouse-wheel action).

There is a way to log the current zoom level of the view with watchUtils.

watchUtils.watch(view, "zoom", function(zoom) {
    console.log(zoom);
};‍‍‍‍‍‍‍‍‍

Don't forget to add the require at the beginning of your script

require(["esri/core/watchUtils"], function(watchUtils) { /* code goes here */ });