HERE Maps-动态加载标记和缩放问题

时间:2018-09-06 21:17:20

标签: javascript maps here-api

我正在尝试使用免费版本的HERE Maps,我想在地图上动态显示标记。即使我动态绑定数据,它也始终会加载首次加载的地图。另外,如果我放大地图,即使设置了缩放和居中值,它也不会返回默认版本。如果您遇到类似问题,请提供一些意见。谢谢。

1 个答案:

答案 0 :(得分:0)

请尝试使用以下代码段来初始化地图中的相应缩放级别

function moveMapToBerlin(map){
  map.setCenter({lat:52.5159, lng:13.3777});
  map.setZoom(14);
}

/**
 * Boilerplate map initialization code starts below:
 */

//Step 1: initialize communication with the platform
// In your own code, replace variable window.apikey with your own apikey
var platform = new H.service.Platform({
  apikey: window.apikey
});
var defaultLayers = platform.createDefaultLayers();

//Step 2: initialize a map - this map is centered over Europe
var map = new H.Map(document.getElementById('map'),
  defaultLayers.vector.normal.map,{
  center: {lat:50, lng:5},
  zoom: 4,
  pixelRatio: window.devicePixelRatio || 1
});
// add a resize listener to make sure that the map occupies the whole container
window.addEventListener('resize', () => map.getViewPort().resize());

//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));

// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);

// Now use the map as required...
window.onload = function () {
  moveMapToBerlin(map);
}