File

map/map.ts

Extends

CoordinateHandler

Metadata

moduleId module.id.toString()
providers MapService
selector leaf-element
styleUrls map.css
templateUrl map.html

Inputs

crs

Type: any

Defined in map/map.ts:21
lat

Type: number

Default value: 52.6

Defined in map/map.ts:15
layerControl

Type: boolean

Default value: false

Defined in map/map.ts:20
lon

Type: number

Defined in map/map.ts:16
maxBounds

Type: LatLngBounds

Defined in map/map.ts:23
maxZoom

Type: number

Default value: 19

Defined in map/map.ts:19
minZoom

Type: number

Default value: 4

Defined in map/map.ts:18
zoom

Type: number

Default value: 12

Defined in map/map.ts:17
zoomControl

Type: boolean

Defined in map/map.ts:22

Constructor

constructor(mapService: MapService)
Defined in map/map.ts:26

Methods

ngOnInit
ngOnInit()
Defined in map/map.ts:32
Returns: void
ngAfterViewInit
ngAfterViewInit()
Defined in map/map.ts:66
Returns: void
setLayerControl
setLayerControl()
Defined in map/map.ts:69
Returns: void

Properties

layerControlObject
layerControlObject: any
Defined in map/map.ts:26
mapElement
mapElement: ElementRef
Defined in map/map.ts:24
import { Component, Input, ViewChild, ElementRef, EventEmitter } from '@angular/core';
import { MapService } from '../services/map.service';
import { CoordinateHandler } from '../helpers/coodinateHandler';
import * as L from 'leaflet';

@Component({
  moduleId: module.id.toString(),
  selector: 'leaf-element',
  templateUrl: 'map.html',
  styleUrls: ['map.css'],
  providers: [MapService]
})

export class LeafletElement extends CoordinateHandler {
  @Input() lat: number = 52.6;
  @Input() lon: number = -1.1;
  @Input() zoom: number = 12;
  @Input() minZoom: number = 4;
  @Input() maxZoom: number = 19;
  @Input() layerControl: boolean = false;
  @Input() crs: any = L.CRS.EPSG3857;
  @Input() zoomControl: boolean;
  @Input() maxBounds: L.LatLngBounds = null;
  @ViewChild('map') mapElement: ElementRef;

  layerControlObject = null;

  constructor(private mapService: MapService) {
    super();
  }

  ngOnInit() {
    super.assignCartesianPointToLeafletsLatLngSchema();

    if (typeof (this.crs) === "string") {
      var splitCrs = this.crs.split(".");
      if (splitCrs[0] === "L") {
        this.crs = L[splitCrs[1]][splitCrs[2]];
      } else {
        console.warn("something is not right, reverting to default EPSG3857");
        this.crs = L.CRS.EPSG3857;
      }
    }

    super.transformPointCoordinates(this.crs);

    let map = L.map(this.mapElement.nativeElement, {
      crs: this.crs,
      zoomControl: this.zoomControl,
      center: L.latLng(this.lat, this.lon),
      zoom: this.zoom,
      minZoom: this.minZoom,
      maxZoom: this.maxZoom,
      maxBounds: this.maxBounds,
      layers: [],
      closePopupOnClick: false,
      attributionControl: false
    });
    this.mapElement.nativeElement.myMapProperty = map;

    //set variables for childrent components
    this.mapService.setMap(map);
    this.mapService.setLayerControl(this.layerControl);
  }

  ngAfterViewInit() {
  }

  setLayerControl() {
    if (this.layerControl) {
      let map = this.mapService.getMap();
      if (this.layerControlObject !== null) {
        this.layerControlObject.getContainer().innerHTML = '';
      }
      this.layerControlObject = L.control.layers(this.mapService.getBasemaps(), this.mapService.getOverlays()).addTo(map);
    }
  }
}
<div class="page-background map-container" layout-padding>
	<div #map></div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""