我正在尝试在我的应用程序中实现标记聚类器。我在我的项目中安装了“@google/markerclusterer”并已将其导入,如下所示。但是,我收到错误:core.js:4002 ERROR TypeError: _google_markerclusterer__WEBPACK_IMPORTED_MODULE_7__ is not a constructor。我不知道为什么我会得到这个,因为它应该是一个构造函数。这是我的代码。
import * as MarkerClusterer from '@google/markerclusterer';
在 initMap() 中
for (var i = 0; i < features.length; i++) {
const infowindow = new google.maps.InfoWindow({
content: features[i].content
});
const marker2 = new google.maps.Marker({
position: features[i].position,
icon: icons[features[i].type].icon,
animation: google.maps.Animation.DROP,
map: map
});
marker2.addListener('click', () => {
marker2.setAnimation(google.maps.Animation.BOUNCE);
setTimeout(() => {
marker2.setAnimation(null);
}, 1000);
infowindow.open(map, marker2);
});
const markerCluster = new MarkerClusterer(map, marker2,
{ imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });
}
最佳答案
<script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>`
在您的函数 initMap
中使用它和
const markerCluster = new markerClusterer.MarkerClusterer({ map, markers });
关于javascript - 标记聚类器不是构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59187141/