[英]Angular map-marker-clusterer component doesn't work
我正在使用 map 如下,但這不起作用
<google-map #googleMap width="100%" height="100%" (idle)="initClusterer($event)">
<map-marker-clusterer *ngIf="googleMap?.googleMap">
<ng-container *ngFor="let i of items">
<ng-container *ngIf="i.categories | haveCategory: targetCategory">
<map-marker #markerElem [position]="i.position"> </map-marker>
</ng-container>
</ng-container>
</map-marker-clusterer>
</google-map>
import { MarkerClusterer } from '@googlemaps/markerclusterer'
//...
@ViewChild('googleMap', { static: true }) googleMap: GoogleMap
markerCluster?: MarkerClusterer
// ...
initClusterer(e) {
console.log('initClusterer', e)
if (!this.googleMap?.googleMap || this.markerCluster) return
console.log(this.googleMap, this.googleMap.googleMap)
this.markerCluster = new MarkerClusterer({
map: this.googleMap.googleMap,
markers: this.markerElem,
})
}
我確實下載了以下依賴npm i @googlemaps/markerclusterer
npm i @types/google.maps --save-dev
而不是markerclustererplus,因為它已被棄用。
但我收到以下錯誤。
vendor.js:91237 ERROR Error: MarkerClusterer class not found, cannot construct a marker cluster. Please install the MarkerClustererPlus library: https://github.com/googlemaps/js-markerclustererplus
at MapMarkerClusterer.ngOnInit (vendor.js:125746:15)
我做錯了什么?
Angular:13.2.3 CDK/材料:13.2.3
@angukar/谷歌地圖:13.2.3
@types/google.maps:3.47.4
@angular/google-maps
確實存在錯誤並且確實導入了不正確的庫。
解決方法是在index.html
文件的頭部添加以下腳本。 (或作為angular.json
文件中的腳本)
<script src="https://unpkg.com/@googlemaps/markerclustererplus/dist/index.min.js" async defer></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.