一、引言
之前在Angular4使用过百度地图,记录一下踩过的坑
二、实现
1.安装
npm install angular2-baidu-map
2.在app.module.ts配置
ak key在http://lbsyun.baidu.com/apiconsole/key中创建
import { BrowserModule } from '@angular/platform-browser' import { NgModule } from '@angular/core' import { AppComponent } from './app.component' import { BaiduMapModule } from 'angular2-baidu-map' @NgModule({ declarations: [AppComponent], imports: [BrowserModule, BaiduMapModule.forRoot({ ak: 'your ak' })], providers: [], bootstrap: [AppComponent] }) export class AppModule {}
3.在app.component.html使用
<div style="height: 500px;width: 900px;" > <baidu-map [options]="opts" > <!--<marker [point]="point" [options]="markOpts" (loaded)="" (clicked)=""></marker>--> <marker *ngFor="let marker of markers" [point]="marker.point" [options]="marker.options"></marker> <!--导航控件--> <control type="navigation" [options]="controlOpts"></control> <!--地图全景控件--> <control type="overviewmap" [options]="overviewmapOpts"></control> <!--比例尺--> <control type="scale" [options]="scaleOpts"></control> <!--地图类型--> <control type="maptype" [options]="mapTypeOpts"></control> <control type="geolocation" [options]="geolocationOpts"></control> </baidu-map> </div>
4.在app.component.ts
import {Component, OnInit} from '@angular/core'; import { MapOptions, Point, MarkerOptions, NavigationControlOptions, ControlAnchor, NavigationControlType, OverviewMapControlOptions, ScaleControlOptions, MapTypeControlOptions, MapTypeControlType, GeolocationControlOptions } from 'angular2-baidu-map'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.sass'] }) export class AppComponent { public opts: MapOptions; public markers: Array<{ point: Point; options"text-align: center">总结
以上所述是小编给大家介绍的详解在Angular4中使用ng2-baidu-map的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!