我需要在Google地圖上呈現多個標記和markerclusterer。我目前正在使用API(v3),並且在較慢的機器上存在性能問題。 我該怎麼做? 我使用ajax和XMLGoogle Maps API V3在添加大量標記時速度很慢
0
A
回答
5
This is a known issue with gmap。現在,按照at this link提到的批量添加到DOM的建議。
請注意,有些方法可以批量添加標記,包括MarkerLight和MultiMarker,這些標記可能足夠快,無需直接DOM操作即可滿足您的需求。
3
我沒有使用Markerclusterer,但我確保只有視口中的標記在地圖上設置。對我來說,這在性能上有了顯着的提升。
我使用了多個充當不同圖層的標記陣列。 這些圖層通過在創建後添加marker.display屬性進行控制,以便以後使用。這樣,即使在視口內,這些也將被忽略。
使用「空閒」事件:當用戶停止平移/縮放時,「空閒」將觸發,而不是在平移/縮放時持續點亮的「bounds_changed」事件。
將事件添加到您的window.onload函數中。有關API(*)
google.maps.event.addListener(map, "idle", function (event) {
if (map) {
//This is the current user-viewable region of the map
var bounds = map.getBounds();
markerLayers.forEach(function (layer) {
checkVisibleElements(layer, bounds);
});
checkVisibleElements(searchMarkers, bounds);
//Loop through all the items that are available to be placed on the map
}
});
function checkVisibleElements(elementsArray, bounds) {
//checks if marker is within viewport and displays the marker accordingly - triggered by google.maps.event "idle" on the map Object
elementsArray.forEach(function (item) {
//If the item is within the the bounds of the viewport
if (bounds.contains(item.position) && item.display == true) {
//If the item isn't already being displayed
if (item.map!=map){
item.setMap(map);
}
} else {
item.setMap(null);
}
});
}
0
如果您的自定義標記使用的路徑,嘗試使用URL的圖像(如SVG),而不是。 路徑渲染速度很慢,但(共享)圖標要快得多。
相關問題
- 1. Google Maps Android API v2在添加大量標記時速度很慢
- 2. Google Maps API v3添加地圖標記
- 3. Google Maps API(v3)添加/更新標記
- 4. 如何在Google Maps API v3中將標記添加到標記
- 5. Google Maps API V3標記不加載
- 6. Google Maps API v3 - 添加地標控件
- 7. Google Maps API V3 - 隨時添加控件
- 8. Google Maps API V3-在創建標記後添加偵聽器
- 9. 無法在Google Maps Api v3中添加標記
- 10. 在Google Maps API V3中繪製標記
- 11. Google Maps API v3標記座標
- 12. 如何異步添加Google maps v3 API上的標記?
- 13. Google Maps V3 API for Codeigniter [添加編號標記+其他問題]
- 14. 使用Google Maps API v3添加多個標記
- 15. Google Maps API v3:從陣列添加標記不起作用
- 16. 多標記問題(Google Maps API v3)
- 17. 刷新標記 - Google Maps JavaScript API v3
- 18. Google Maps API v3多個標記Infowindow
- 19. Google Maps JavaScript API v3的標記
- 20. 刪除標記 - Google Maps JavaScript API v3
- 21. Google Maps JS API v3標記顏色
- 22. Google Maps API V3上的限制標記
- 23. 未顯示Google Maps API v3標記
- 24. Google Maps API v3:標記未被刪除
- 25. Google Maps API v3禁用標記
- 26. 標記拖拽事件Google Maps API V3
- 27. Google Maps API v3無法創建標記...
- 28. Google Maps API v3 SVG標記消失
- 29. 從Google Maps API V3中刪除標記
- 30. 通過標記過濾Google Maps API V3
偉大的,如果它爲你工作,記得投票和接受。如果不是,請評論你還需要什麼。歡迎來到SO。 – bishop