Closes #52 Add attribution to map.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';
|
||||
import { Component, OnInit, ElementRef, ViewChild, DoCheck } from '@angular/core';
|
||||
import * as L from 'leaflet';
|
||||
import { ResourceService } from '../services/resource.service';
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ResourceService } from '../services/resource.service';
|
||||
selector: 'app-tile-map',
|
||||
templateUrl: './tile-map.component.html'
|
||||
})
|
||||
export class TileMapComponent implements OnInit {
|
||||
export class TileMapComponent implements OnInit, DoCheck {
|
||||
|
||||
private static readonly DEFAULT_LOCATION = new L.LatLng(51.461663, 7.016645);
|
||||
private static readonly DEFAULT_ZOOM = 13;
|
||||
@@ -23,6 +23,7 @@ export class TileMapComponent implements OnInit {
|
||||
|
||||
map: L.Map;
|
||||
layer: L.TileLayer;
|
||||
attribution: L.Control;
|
||||
|
||||
readonly iconNormal: L.Icon;
|
||||
readonly iconSelected: L.Icon;
|
||||
@@ -35,6 +36,13 @@ export class TileMapComponent implements OnInit {
|
||||
|
||||
}
|
||||
|
||||
ngDoCheck() {
|
||||
this.map.removeControl(this.attribution);
|
||||
this.attribution = L.control.attribution({ position: 'bottomleft' });
|
||||
this.map.addControl(this.attribution);
|
||||
this.map.invalidateSize();
|
||||
}
|
||||
|
||||
getWidth(): number {
|
||||
if (this.mapElement) {
|
||||
return this.mapElement.nativeElement.clientWidth;
|
||||
@@ -52,12 +60,17 @@ export class TileMapComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.map = new L.Map('map');
|
||||
const object = this;
|
||||
this.map = new L.Map('map', { attributionControl: false });
|
||||
this.map.setView(TileMapComponent.DEFAULT_LOCATION, TileMapComponent.DEFAULT_ZOOM);
|
||||
this.attribution = L.control.attribution({ position: 'bottomleft' });
|
||||
this.map.addControl(this.attribution);
|
||||
this.layer = new L.TileLayer(TileMapComponent.DEFAULT_TILE_URL, {
|
||||
attribution: this.res.strings('tile_map_attribution'),
|
||||
maxZoom: 18
|
||||
}).addTo(this.map);
|
||||
this.layer.getAttribution = function(): string {
|
||||
return object.res.strings('tile_map_attribution');
|
||||
};
|
||||
}
|
||||
|
||||
private createMarkerIcon(url: string): L.Icon {
|
||||
|
||||
Reference in New Issue
Block a user