Select to view content in your preferred language

JimuMapView will not zoom

669
10
Jump to solution
05-17-2024 05:23 AM
AngelaSchirck
Frequent Contributor

Hi all,

I'm creating a widget and want it to zoom to a particular lat/lon.  All functionality of the widgit works great except the zoom.  It will pan to the point but not zoom in no matter what zoom level I put. There are no zoom restrictions on the map itself, whatever zoom level the map is in, it stays at and pans to the point.  I've tried several different ways to do this, here is my latest relevant code.  Here mapViewRef refers to a JimuMapView instance.

```

const searchAndZoomToLocation = () => {
    if (mapViewRef.current && inputLatitude && inputLongitude) {
      const lat = parseFloat(inputLatitude);
      const lon = parseFloat(inputLongitude);
      if (!isNaN(lat) && !isNaN(lon)) {
        // Add point to the specified location
        const point = new Point({
          longitude: lon,
          latitude: lat
        });
        const pointGraphic = new Graphic({
          geometry: point,
          symbol: pointSymbol.current
        });
       
        mapViewRef.current.view.goTo({target: point, zoom: 14}); // Zoom to point
        mapViewRef.current.view.graphics.removeAll(); // Remove existing graphics
        mapViewRef.current.view.graphics.add(pointGraphic);

      }
    }
```
 
Any ideas why this only pans and doesn't zoom? What ever number I set zoom to, it doesn't change the result.
0 Kudos
10 Replies
AngelaSchirck
Frequent Contributor

Okay, solved my own problem....

Instead of setting mapViewRef.current.view.zoom = 14; I used mapViewRef.current.view.scale = 1000; and it now zooms to the point.

0 Kudos