ionic-framework - 此处地图未显示在 Ionic 选项卡中
问题描述
我在 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 选项卡中工作?
解决方案
请尝试以下代码片段:
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);
}
推荐阅读
- c# - 发生异常时如何获取 IL 指令偏移量?
- r - 如何获取R中二维表中元素的两个轴的名称
- android - 如何通过不同的资源获取引用资源的 ID?
- json - PowerShell - JSON 格式查询 - “收到无效的 JSON 有效负载”
- node.js - Firebase 根据所选项目动态初始化应用程序
- r - 使用 R 循环并创建列表
- java - Android YouTube 播放器 API
- java - androidx.gridlayout.widget.GridLayout 无法转换为 android.widget.GridLayout
- javascript - 使用 D3.js 时 defaultLocale_format 不是函数
- search - 在包含多个 .txt 文件 ahk 的文件夹中搜索单词