File

projects/ngx-neshan/src/lib/component/neshan-static/neshan-static.component.ts

Implements

OnInit OnChanges

Metadata

selector neshan-static
styleUrls ./neshan-static.component.css
templateUrl ./neshan-static.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(apiKey: string, baseUrl?: string)
Parameters :
Name Type Optional
apiKey string No
baseUrl string Yes

Inputs

height
Type : number
Default value : 300
location
Type : NsLocation
marker
Type : "red" | "green" | "blue" | "violet" | "none"
Default value : 'red'
type
Type : "dreamy" | "dreamy-gold" | "standard-day" | "standard-night" | "neshan" | "osm-bright"
Default value : 'neshan'
width
Type : number
Default value : 700
zoom
Type : number
Default value : 13

Methods

generateStaticMap
generateStaticMap()
Returns : void
ngOnChanges
ngOnChanges(changes)
Parameters :
Name Optional
changes No
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Private apiKey
Type : string
Private baseUrl
Type : string
imgUrl
Type : string
import { Component, OnInit, Input, Inject, Optional, OnChanges } from '@angular/core';
import { NsLocation } from '../../models/ns-location';
import { NESHAN_API_KEY, NESHAN_BASE_URL } from '../../ngx-neshan.service';

@Component({
  selector: 'neshan-static',
  templateUrl: './neshan-static.component.html',
  styleUrls: ['./neshan-static.component.css']
})
export class NeshanStaticComponent implements OnInit, OnChanges {

  imgUrl: string;

  @Input() location: NsLocation;
  @Input() type: 'dreamy' | 'dreamy-gold' | 'standard-day' | 'standard-night' | 'neshan' | 'osm-bright' = 'neshan'
  @Input() marker: 'red' | 'green' | 'blue' | 'violet' | 'none' = 'red'
  @Input() zoom: number = 13;
  @Input() width: number = 700;
  @Input() height: number = 300;

  private baseUrl: string;
  private apiKey: string;

  constructor(@Inject(NESHAN_API_KEY) apiKey: string, @Optional() @Inject(NESHAN_BASE_URL) baseUrl?: string) {
    this.baseUrl = baseUrl ? baseUrl : "https://api.neshan.org";

    if (apiKey === undefined || apiKey === null)
      throw new Error("The parameter 'NESHAN_API_KEY' must be define.");
    this.apiKey = apiKey;
  }
  ngOnChanges(changes: import("@angular/core").SimpleChanges): void {

    this.generateStaticMap();
  }

  ngOnInit(): void {
    this.generateStaticMap();
  }

  generateStaticMap() {
    console.log('generate static url');

    this.imgUrl = this.baseUrl
      + `/v2/static?key=${this.apiKey}&type=${this.type}`
      + `&zoom=${this.zoom}&center=${this.location.latitude},${this.location.longitude}`
      + `&width=${this.width}&height=${this.height}&marker=${this.marker}`;

    console.log(this.imgUrl);

  }

}
<img [src]="imgUrl" alt="Neshan Static Map" [width]="width" [height]="height">

./neshan-static.component.css

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""