我有带有选项的谷歌地图对象:
$(document).ready(function () {
var mapOptions = {
zoom: 4,
minZoom: 3,
maxZoom: 12,
center: new google.maps.LatLng(39.484973, -0.364126),
mapTypeControl: false,
streetViewControl: false
};
var mapElement = document.getElementById('#map');
map = new google.maps.Map(mapElement, mapOptions);
markers = [...];
markerCluster = new MarkerClusterer(map, markers, {
averageCenter: true,
styles: [{
url: '/cluster.png',
width: 64,
height: 64,
textColor: 'white',
backgroundPosition: 'center'
}]
});
...
}
初始化 map 后,我想通过运行更改缩放级别:
var location = ...
map.setCenter(location); // works fine
map.setZoom(7);`,
但我在控制台中收到错误消息:
Uncaught TypeError: Cannot read property 'maxZoom' of undefined
at Ag.<anonymous> (markerclusterer.js:163)
at Object._.z.trigger (js?key=AIzaSyBpuEnTxOHtdmlMllM_Qd2SL_Q2t45o3_0:99)
at Hb (js?key=AIzaSyBpuEnTxOHtdmlMllM_Qd2SL_Q2t45o3_0:38)
at Ag._.k.set (js?key=AIzaSyBpuEnTxOHtdmlMllM_Qd2SL_Q2t45o3_0:101)
at Ag.setZoom (js?key=AIzaSyBpuEnTxOHtdmlMllM_Qd2SL_Q2t45o3_0:56)
at OfferMap.setBounds (offers_offer-map_1.js:1)
at HTMLDocument.<anonymous> (offers_trainee-offers_3.js:1)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
有人知道发生了什么事吗?
更新
由于问题是因为 MarkerClusterer,正如下面评论中提到的 @geocodezip,这里是我加载的脚本:
<script type="text/javascript" src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
最佳答案
好的,我解决了!显然,正如@geocodezip 在问题下提到的那样,这是 masterclusterer
问题,我导入的库已过时。不得不下载newer .完美运行。
另外不要忘记在 MarkerClusterer 选项中设置 maxZoom:
this.markerCluster = new MarkerClusterer(this.map, this.markers, {
maxZoom: 12,
averageCenter: true,
styles: [{
url: this.clusterIcon,
width: 64,
height: 64,
textColor: 'white',
backgroundPosition: 'center'
}]
});
在明确问题期间,为 future 的访问者更新标题和问题。
关于javascript - Google Maps API JS - MarkerClusterer - 无法读取未定义的属性 'maxZoom',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43784105/