How to add base map with max and min zoom HereMaps JS Api

410 views Asked by At

I just started to use HereMaps and my adventure to mix JavaScript and Typescript with Angular. My maps render proper with other settings but I can't set the max and min zoom level. I read that I can set max and min levels of a Layer, but where are the properties to set max and min zoom for the map?

let defaultLayers = this.platform.createDefaultLayers();
let map = new H.Map(
    this.mapElement.nativeElement,
    defaultLayers.vector.normal.map,
    {
        zoom: 10,
        center: { lat: this.lat, lng: this.lng },
        renderBaseBackground: {lower: 2, higher: 2}
    }
);
map.getViewModel().setLookAtData({
    tilt: 30
});        
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
var ui = H.ui.UI.createDefault(map, defaultLayers);
map.addLayer(new H.map.layer.Layer({
    min: 3,
    max: 7
}));

Any ideas on how to set it?

1

There are 1 answers

0
AudioBubble On

You can achieve it (e.g. from 8 zoom to 10 zoom) with this code this code:

map.getBaseLayer()
    .setMin(8)
    .setMax(10);

or

map.addEventListener("mapviewchange", e => {
    if (!e.oldValue.lookAt) return;
  let newZoom = e.newValue.lookAt.zoom;
    //console.log("zoom:", e.modifiers, e.oldValue, e.newValue);
  if(newZoom > 10){
    map.setZoom(10);
  }
  if(newZoom < 8){
    map.setZoom(8);
  }

});