I have a big problem, I'm sure I had already did that and it worked perfectly...
Here is my code :
import { Component, OnInit } from '@angular/core';
import { Map, latLng, tileLayer, Layer, marker, icon, Icon } from 'leaflet';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
public m : Map;
public n : number = 3;
public markerIcon : Icon = icon({
iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/images/marker-icon.png'
});
constructor() { }
ngOnInit() {
this.initMap();
}
initMap(){
console.log(this.n);
//this.m = L.map('map').setView([44.8333, -0.5667], 5);
this.m = new Map('map').setView([44.8333, -0.5667], 5);
tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(this.m);
this.m.on('click', this.addDestination);
console.log(this.m);
}
addDestination(){
console.log(this.m);
}
}
The first console.log in "initMap" return me the instance of my map, BUT the second console.log in addDestination return me undefined.
I've did 10000000 tests. Spent too many times, please help me !