map/map.ts
moduleId | module.id.toString() |
providers |
MapService
|
selector | leaf-element |
styleUrls | map.css |
templateUrl | map.html |
crs
|
Type: |
Defined in map/map.ts:21
|
lat
|
Type:
Default value: |
Defined in map/map.ts:15
|
layerControl
|
Type:
Default value: |
Defined in map/map.ts:20
|
lon
|
Type: |
Defined in map/map.ts:16
|
maxBounds
|
Type: |
Defined in map/map.ts:23
|
maxZoom
|
Type:
Default value: |
Defined in map/map.ts:19
|
minZoom
|
Type:
Default value: |
Defined in map/map.ts:18
|
zoom
|
Type:
Default value: |
Defined in map/map.ts:17
|
zoomControl
|
Type: |
Defined in map/map.ts:22
|
constructor(mapService: MapService)
|
Defined in map/map.ts:26
|
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
|
layerControlObject |
layerControlObject: |
Defined in map/map.ts:26
|
mapElement |
mapElement: |
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>