1

I want to set maxZoom and minZoom at runtime.

Initially I set maxZoom and minZoom as shown in below code

new this.Map("map1", {
    basemap: "streets",
    center: new this.Point3(-98.35, 39.50),
    zoom: 5,
    maxZoom: 20,
    minZoom: 5
});

After some time user want to change the Min and Max zoom levels at runtime. So I tried as below code, but not workout.

this.selMapObj.setView(new this.MapView({
    maxZoom: 20,
    minZoom: 9,
}));

1 Answer 1

0

Your problem is that you need to use constraint object property of the MapView, that is were minZoom and maxZoom are set.

Here is an example I made for you,

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>Zoom Constraints</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
    <link rel="stylesheet" href="https://js.arcgis.com/4.14/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.14/"></script>
    <script>
      require(["esri/Map", "esri/views/MapView"], function(Map, MapView) {
        var map = new Map({
          basemap: "streets"
        });
        var view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 4,
          center: [15, 65]
        });
        document.getElementById("min").value = view.constraints.minZoom;
        document.getElementById("max").value = view.constraints.maxZoom;
        document.getElementById("updateButton").onclick = function updateZoomConstraints() {
          var min = document.getElementById("min").value;
          var max = document.getElementById("max").value;
          console.log(`min:${min} max:${max}`)
          if (min < max) {
            view.constraints.minZoom = min;
            view.constraints.maxZoom = max;
          }
        }
      });
    </script>
  </head>
  <body>
    <div>
      <label for="min">Min Zoom:</label>
      <input id="min" type="number" min="2" max="18">
      <label for="max">Max Zoom:</label>
      <input id="max" type="number" min="0" max="17">
      <button id="updateButton">Update Zoom Constraints</button>
    </div>
    <div id="viewDiv"></div>
  </body>
</html>

ArcGIS API - MapView consraints

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.