Ошибка типа: не удается прочитать свойство 'lat' из неопределенного после того, как я пытаюсь добавить кнопку - PullRequest
0 голосов
/ 20 февраля 2020

привет тем, кто видит это, я новичок в разработке машинописи, поэтому я стараюсь изо всех сил Я получил эту ошибку после попытки добавить кнопку " const btnItinerair " в мое всплывающее окно на другой странице, которую я не было никаких проблем, но звук блокируется, я думаю, что это связано с маркером, но я не вижу, как это сделать. вот код:

import { Component, OnInit, AfterViewInit } from '@angular/core';
import { LieuService, Lieu } from 'src/app/services/lieu.service';
import { AdresseService, Adresse } from 'src/app/services/adresse.service';
import { ActivatedRoute } from '@angular/router';
import { LaunchNavigator, LaunchNavigatorOptions } from '@ionic-native/launch-navigator/ngx';
import * as L from 'leaflet';


@Component({
  selector: 'app-carte',
  templateUrl: './carte.page.html',
  styleUrls: ['./carte.page.scss'],
  })
export class CartePage implements OnInit {
  adresseList = [];
  map: L.Map;
  lieux: Lieu[];

  adresseComp = null;

constructor(private route: ActivatedRoute,
         private lieuService: LieuService,
         private adresseService: AdresseService,
         private launchNavigator: LaunchNavigator
        ) { }

 ngOnInit() {
  console.log('ngOnInit');
  }

 ionViewDidEnter() {
    console.log('ionViewDidEnter');

    // In setView add latLng and zoom
    this.map = L.map('mapId').setView([46.325666, -0.467819], 10);
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
     attribution: '© <a href="http://www.openstreetmap.org/copyright',
    }).addTo(this.map);
     this.map.on('mouseover', function(ev) {
     ev.target.openPopup(); });


this.lieuService.getLieux().subscribe(lieux => {
lieux.forEach(lieu => {
      // address loading
      this.adresseService.getAdresse(lieu.adresse.id).subscribe(adresse => {
          lieu.adresse = adresse;

          // set the link to see more
          const btnVoirPlus = '<a href="/details-lieux/' + lieu.id + '" ><button>see more</button></a>';

          // allows to have the complete address
          this.adresseComp = adresse.numero + ' ' + adresse.rue + ' ' + adresse.ville + ' ' + adresse.cp ;

          // allows you to launch a route
          const btnItineraire = '<button ion-button block (click)=this.LaunchRoute(' + lieu.nom + ')>Itinéraire</button>' ;

          // affichage des info dans la popup
          // tslint:disable-next-line: max-line-length
          const popupContent = '<h2>' + lieu.nom + '</a></h2></br>' + adresse.numero + ' ' + adresse.rue + '<div><tr><td>' + btnVoirPlus + ' </td><td> ' + btnItineraire + '</td></tr></div>';
          // creeer des Markers
          L.marker([adresse.latitude, adresse.longitude])
          .addTo(this.map)
          .bindPopup(popupContent);
        });
      this.lieux = lieux;
    });
  });

/** Remove map when we have multiple map object */
ionViewWillLeave() {
  this.map.remove();
}

 LaunchRoute() {
   console.log('ADRESSE:', this.adresseComp);
   this.launchNavigator.navigate(this.adresseComp)
   .then(success => console.log('Launched navigator'),
   error => console.log('Error launching navigator', this.adresseComp, error)
   );
  }
}

полный журнал:

core.js:9110 ERROR TypeError: Cannot read property 'lat' of undefined
    at Object.project (leaflet-src.js:1661)
    at Object.latLngToPoint (leaflet-src.js:1498)
    at NewClass.project (leaflet-src.js:4005)
    at NewClass.latLngToLayerPoint (leaflet-src.js:4027)
    at NewClass._updatePosition (leaflet-src.js:9669)
    at NewClass.update (leaflet-src.js:9574)
    at NewClass.onAdd (leaflet-src.js:9509)
    at NewClass.onAdd (leaflet-src.js:9795)
    at NewClass._layerAdd (leaflet-src.js:6617)
    at NewClass.whenReady (leaflet-src.js:4477)

все, что я хочу, - это иметь возможность запускать собственные приложения пользователя, чтобы у них был маршрут к «выбранным местам» маркер.

...