我正在尝试按照HERE的说明进行操作: https://developer.here.com/documentation/maps/topics/quick-start.html 我尝试像这样将.js脚本添加到index.html中:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>See720</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var platform = new H.service.Platform({
'app_id': '****',
'app_code': '****',
useCIT: true
});
</script>
</head>
<body>
<app-root></app-root>
</body>
</html>
我是一名有用的助手,可以为您进行翻译。以下是需要翻译的内容:
我试图以某种方式将 .js 文件注入到组件或服务中,以便使用 .js 文件中包含的类。但我无法使其正常工作。
我希望将这部分放入:
var platform = new H.service.Platform({
'app_id': '****',
'app_code': '****',
useCIT: true
});
以某种方式将其转换为OnInit()方法。但是,"H"对象从未被识别。使用普通JavaScript和Html,我可以让它工作。
在Angular 4中导入此类JavaScript文件的正确方法是什么,如何访问其类和方法?
更新
我的代码目前看起来像这样:
<div style="text-align:center">
<!--<div><font color="white">This is some text!</font></div>-->
<div id="mapContainer" style="width: 900px; height: 600px"></div>
</div>
组件:
import {AfterViewInit, Component} from '@angular/core';
declare var H: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
title = 'C720';
ngAfterViewInit() {
// Initialize the platform object:
let platform = new H.service.Platform({
'app_id': '****',
'app_code': '****',
useCIT: true
});
// Obtain the default map types from the platform object
let defaultLayers = platform.createDefaultLayers();
// Instantiate (and display) a map object:
let map = new H.Map(
document.getElementById('mapContainer'),
defaultLayers.normal.map,
{
zoom: 5,
center: { lat: 52.5, lng: 13.5 }
}
);
}
}
index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>See720</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
<script src="http://js.api.here.com/v3/3.0/mapsjs-mapevents.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
地图正在显示,但现在我需要添加一个事件监听器,但第三方包(“mapjs-mapevents.js”)中的 H.mapevent 类未被识别。如何告诉 Angular 在第三个脚本中查找其他类?
scripts
:https://dev59.com/UVkT5IYBdhLWcg3wRNUR - t3__rry