Search code examples
here-api

Here maps offset center on JS api


I need to offset the center of my here maps. I am using the Javascript api. I found a solution on the ios api with transformCenter property. Is there any similar function on the JS api ?

enter image description here


Solution

  • There are two options to offset map's center:

    1. add padding property when initializing the map:

    // assuming defaultLayers is defined
    map = new H.Map(document.getElementById('map'),
      defaultLayers.vector.normal.map, {
      center: {lat: 50, lng: 20},
      zoom: 15,
      pixelRatio: window.devicePixelRatio || 1
      padding: {top: 0, right: 200, bottom: 0, left: 0}
    }),
    

    2. set padding on map's ViewPort object on the fly:

    map.getViewPort().setPadding(0, 200, 0, 0);
    

    Here is a simple jsfiddle example: https://jsfiddle.net/vq5yazjL/

    For more details see documentation for H.Map#Options and H.map.ViewPort#setPadding