Ошибка Google Map Angular9 с открытием информационного окна, getAnchor () не найден - PullRequest
7 голосов
/ 11 июля 2020

Я использую этот google map angular компонент учебник, и он работает очень хорошо! НО открытие информационного окна вызывает исключение.

Вот мой код, который вызывает метод this.infoWindow.open для компонента «MapInfoWindow» из пакета npm.

import {
  MapInfoWindow,
  MapMarker,
  GoogleMap
} from '@angular/google-maps';

export class YogabandEventsComponent implements OnInit {
  @ViewChild(MapInfoWindow, {
    static: false
  }) infoWindow: MapInfoWindow;
  @ViewChild(GoogleMap, {
    static: false
  }) googleMap: GoogleMap;


  openInfo(marker: MapMarker, content) {
    this.infoContent = content;
    this.infoWindow.open(marker);
  }
}
<google-map [options]="options" [zoom]="zoom" [center]="center" class="h-100" height="100%" width="100%">
  <map-marker #markerElem *ngFor="let marker of markers" (mapClick)="openInfo(markerElem, marker.info)" [position]="marker.position" [label]="marker.label" [title]="marker.title" [options]="marker.options">
  </map-marker>
  <map-info-window>{{ infoContent }}</map-info-window>
</google-map>

Когда вызывается

infoWindow.open (маркер)

, он входит

google-maps. js // строка 1122

, но в строке 1122 появляется сообщение об ошибке, потому что нет метода getAnchor ()

this.infoWindow.open(this._googleMap.googleMap, anchor ? anchor.getAnchor() : undefined);

   // in google-maps.js 
open(anchor) {
  this._assertInitialized();
  this._elementRef.nativeElement.style.display = '';
  this.infoWindow.open(this._googleMap.googleMap, anchor ? anchor.getAnchor() : undefined); // line 1122
}

Я просмотрел документы Google и не нашел никакого метода "getAnchor".

Вот что я вижу в отладчике при установке точка останова в моем компоненте.

enter image description here

Here is what it shows in the debug console when I look at 'marker', so it has values and is instantiated!

enter image description here

I can copy and paste the whole thing but it's long.

Here is another pic of debug console, inside google-maps.js file, trying to call the getAnchor() with no luck becasue it doesn't exist.

введите описание изображения здесь

1 Ответ

10 голосов
/ 13 июля 2020

Нашел ответ.

Посмотрел репо на Github и пример. Он отличался от учебника из ссылки, которую я разместил выше.

https://github.com/angular/components/tree/master/src/google-maps#readme

Маркер карты, необходимый для этой опоры

<map-marker 
  #somemarker="mapMarker" // not #markerElem like from the link
  (mapClick)="openInfoWindow(somemarker, marker.info)">
</map-marker>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...