У меня есть Google Map, которая в настоящее время содержит 5 пинов в одной переменной.
Почему, если в моей переменной много мест, карта загружается очень медленно?
Myсмысл: Как я могу ускорить загрузку моей карты Google, если у меня более 100 пинов на одной карте?
Код:
<div id='main_map'></div>
<script>
var map;
var markers = [];
var locations = [['content of the popup', 51.248016, 22.567579, '3'],'content of the popup', 21.248016, 22.567579, '3'],'content of the popup', 31.248016, 22.567579, '2'],'content of the popup', 41.248016, 22.567579, '7'],'content of the popup', 71.248016, 22.567579, '3'],];
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var pinBase = '/static/img/user/pin-';
function initMap() {
var map = new google.maps.Map(document.getElementById('main_map') {
zoom: 2, center: new google.maps.LatLng(0, 0),
mapTypeId: 'terrain'
});
for (var i = 0; i < locations.length; i++) {
markers[i] = new google.maps.Marker({
position: {lat:locations[i][1], lng:locations[i][2]},
map: map,
html: locations[i][0],
id: i,
icon: pinBase + locations[i][3] + '.png'
});
google.maps.event.addListener(markers[i], 'click', function(){
var infowindow = new google.maps.InfoWindow({
id: this.id,
content: this.html,
position: this.getPosition()
});
map.panTo(this.getPosition());
smoothZoom(this.getMap(), 13, map.getZoom());
google.maps.event.addListenerOnce(infowindow, 'closeclick', function(){
markers[this.id].setVisible(true);
});
this.setVisible(true);
infowindow.open(map);
});
let toggleMarkers = (checkbox) => {
var isChecked = checkbox.checked;
markers.map((elem) => {
elem.setVisible(isChecked);
});
}
}
}
initMap();
</script>