File

src/app/component/amap/amap.component.ts

Implements

OnInit OnDestroy

Metadata

selector stbui-amap
styleUrls ./amap.component.scss
templateUrl ./amap.component.html

Index

Methods
Inputs

Constructor

constructor(api: AmapService, elementRef: ElementRef)
Parameters :
Name Type Optional
api AmapService No
elementRef ElementRef No

Inputs

height
Type : string
lat
Type : number
Default value : 116.397428
lng
Type : number
Default value : 39.90923
options
Type : object
Default value : {}
width
Type : string
zoom
Type : number
Default value : 11

Methods

getStyles
getStyles()
Returns : { width: string; height: string; }
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
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;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""