J'utilise la bibliothèque Angular Google Maps et j'essaie de faire apparaître un composant agm-snazzy-info-window
lorsqu'un objet polygone sur la carte est cliqué. J'ai essayé de la modélisation sur la « utilisant la directive avec un marqueur » section de this page:Ouverture d'une fenêtre d'informations sur un polygone AGM
<agm-map [fitBounds]="mapData.bounds">
<agm-polygon *ngFor="let polygon of mapData.polygons" [paths]="polygon.points">
<agm-snazzy-info-window>
<ng-template>
text goes here
</ng-template>
</agm-snazzy-info-window>
</agm-polygon>
</agm-map>
mais ne rien faire. J'ai essayé de le faire par programme à la place:
<agm-map [fitBounds]="mapData.bounds">
<agm-polygon *ngFor="let polygon of mapData.polygons; let i = index" [paths]="polygon.points"
(polyClick)="polyClicked(i, polygon, infoWindow)"></agm-polygon>
<agm-snazzy-info-window #infoWindow [latitude]="mapData.selectedPoint.lat" [longitude]="mapData.selectedPoint.lng">
<ng-template>
text goes here
</ng-template>
</agm-snazzy-info-window>
</agm-map>
polyClicked (index: number, polygon, infoWindow: AgmSnazzyInfoWindow) {
console.log(index, polygon, infoWindow) // this works correctly
// getPolygonCenter returns a LatLngLiteral from the center of a rectangle that fits the points
this.mapData.selectedPoint = getPolygonCenter(polygon.points)
if (infoWindow.isOpen && index === this.mapData.polygonIndex) {
// close the window if it's already open and we're clicking the same polygon again
infoWindow.isOpen = false
} else {
// otherwise open it and save the index of the clicked polygon
this.mapData.polygonIndex = index
infoWindow.isOpen = true
}
}
mais cela n'a pas fonctionné non plus. Dans les deux cas, la carte et les polygones s'affichent très bien, et le console.log
dans le second affiche les informations attendues sur un clic, il n'affiche jamais la fenêtre. Est-ce que je fais quelque chose de mal? Y a-t-il un autre moyen de le faire? Note pour d'éventuels problèmes XY: Le composant par défaut (non-snazzy) agm-info-window
a bien fonctionné ici et a fait presque tout ce dont j'ai besoin. Cependant, je dois être en mesure d'ajouter un style CSS dessus, et je n'ai pas compris comment faire cela. Donc une autre solution pour cela résoudrait au moins mon problème immédiat.