html引入js文件
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AngularApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的key"></script>
<!-- <script type="text/javascript" src="http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script>-->
</head>
<body>
<app-root></app-root>
</body>
</html>
组件初始化地图
import { Component, OnInit } from '@angular/core';
declare var BMap: any;
declare var BMapLib: any;
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
constructor() { }
ngOnInit(): void {
var map = new BMap.Map("map");
var point = new BMap.Point(117.830586, 30.943465);
map.centerAndZoom(point, 13);
map.enableScrollWheelZoom();
}
}