src/app/component/amap/amap.component.ts
| selector | stbui-amap |
| styleUrls | ./amap.component.scss |
| templateUrl | ./amap.component.html |
Methods |
Inputs |
constructor(api: AmapService, elementRef: ElementRef)
|
|||||||||
|
Defined in src/app/component/amap/amap.component.ts:22
|
|||||||||
|
Parameters :
|
| height | |
Type : string
|
|
|
Defined in src/app/component/amap/amap.component.ts:18
|
|
| lat | |
Type : number
|
|
Default value : 116.397428
|
|
|
Defined in src/app/component/amap/amap.component.ts:19
|
|
| lng | |
Type : number
|
|
Default value : 39.90923
|
|
|
Defined in src/app/component/amap/amap.component.ts:20
|
|
| options | |
Type : object
|
|
Default value : {}
|
|
|
Defined in src/app/component/amap/amap.component.ts:22
|
|
| width | |
Type : string
|
|
|
Defined in src/app/component/amap/amap.component.ts:17
|
|
| zoom | |
Type : number
|
|
Default value : 11
|
|
|
Defined in src/app/component/amap/amap.component.ts:21
|
|
| getStyles |
getStyles()
|
|
Defined in src/app/component/amap/amap.component.ts:42
|
|
Returns :
{ width: string; height: string; }
|
| ngOnDestroy |
ngOnDestroy()
|
|
Defined in src/app/component/amap/amap.component.ts:49
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Defined in src/app/component/amap/amap.component.ts:26
|
|
Returns :
void
|
import { Component, Input, ElementRef, OnInit, OnDestroy } from '@angular/core';
import { AmapService } from './amap.service';
declare var AMap: any;
@Component({
selector: 'stbui-amap',
templateUrl: './amap.component.html',
styleUrls: ['./amap.component.scss']
})
export class AmapComponent implements OnInit, OnDestroy {
@Input() width: string;
@Input() height: string;
@Input() lat: number = 116.397428;
@Input() lng: number = 39.90923;
@Input() zoom: number = 11;
@Input() options: object = {};
constructor(private api: AmapService, private elementRef: ElementRef) {}
ngOnInit() {
const container = this.elementRef.nativeElement.querySelector(
'.amp-container'
);
let options = {
resizeEnable: true,
zoom: this.zoom,
center: [this.lat, this.lng]
};
options = Object.assign(options, this.options);
this.api.createMap(container, options).subscribe(map => console.log(map));
}
getStyles() {
return {
width: this.width,
height: this.height
};
}
ngOnDestroy() {
this.api.destroyMap();
}
}
<div class="amp-container" tabindex="0" [ngStyle]="getStyles()"></div>
./amap.component.scss
.amp-container {
height:600px;
}