0

I have a program which shows a map. If you drag the map, a class variable should change or i want to call a method to do something after map was dragged.
i use inonic3 with angular (ts) and have the following code:

loadmap() {
  // Define and add Leaflet Map with OSM TileLayer
  this.map = leaflet.map("map");
  leaflet.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attributions: 'OpenStreetMap',
  }).addTo(this.map);
  this.map.setZoom(25);
  this.map.setView([0,0])
  console.log('MapLoadSuccsess');

  this.map.on("dragend", function(e) {
      this.loconoff = false;
      console.log("post Drag: " + this.loconoff);
      dosomething();
  });
ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
Las
  • 1
  • Try defining the callback as an arrow function: `this.map.on("dragend", (e) => { ... })`. – ConnorsFan May 02 '20 at 01:17
  • Thank you @ConnorsFan. Your hint with https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback was great. Just had to add .bind(this) behind the this.map.on(..{..}..).bind(this); – Las May 02 '20 at 01:28
  • That also works. :-) – ConnorsFan May 02 '20 at 01:30

0 Answers0