【发布时间】:2020-02-10 19:35:34
【问题描述】:
我在 Ionic 水龙头中有一个非常基本的 Here Map,它使用此 JavaScript 加载到 Ionic 选项卡中。
var platform = new H.service.Platform({
useCIT: true,
'app_id': $(component).data('appid'),
'app_code': $(component).data('appcode'),
useHTTPS: true
});
// Obtain the default map types from the platform object
var maptypes = platform.createDefaultLayers();
// Instantiate (and display) a map object:
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.normal.map,
{
zoom: 10,
center: { lng: $(component).data('long'),
lat: $(component).data('lat')
}
});
// Enable the event system on the map instance:
var mapEvents = new H.mapevents.MapEvents(map);
// Add event listeners:
map.addEventListener('tap', function(evt) {
// Log 'tap' and 'mouse' events:
console.log(evt.type, evt.currentPointer.type);
当不在选项卡 1 中添加此地图时,地图未显示。我尝试并搜索了几件事,但它们仅适用于谷歌地图。我怎样才能让它在 Ionic 选项卡中工作?
【问题讨论】:
-
上述初始化地图的代码本身就很好。你能在日志中看到任何错误吗?我首先要检查
mapContainer元素在地图初始化时是否在选项卡视图的 DOM 中。然后,检查动态数据是否被正确检索。 -
在选项卡中显示 Google 地图似乎存在一个熟悉的问题,最终我找到了一种解决方法,即在地图选项卡打开时触发事件。
标签: ionic-framework tabs here-api