<div class="map-container">
<div class="map"></div>
</div>
<script>
const locations = {{ markers|default("[]")|raw }};
const pin = '/img/pin.png';
window.map_init = () => {
const mapElement = document.querySelector(".map-container > .map");
if (!mapElement) {
return;
}
const map = new google.maps.Map(mapElement, {
center: {lat: 49.5, lng: -30},
zoom: 3,
minZoom: 3,
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
rotateControl: false,
fullscreenControl: false,
scrollwheel: false,
styles: [
{
featureType: "administrative",
stylers: [
{hue: "#000000"},
{lightness: -100},
{visibility: "off"},
],
},
{
featureType: "landscape",
elementType: "geometry",
stylers: [
{hue: "#dddddd"},
{saturation: -100},
{lightness: -3},
{visibility: "on"},
],
},
{
featureType: "landscape",
elementType: "labels",
stylers: [
{hue: "#000000"},
{saturation: -100},
{lightness: -100},
{visibility: "off"},
],
},
{
featureType: "poi",
stylers: [
{hue: "#000000"},
{saturation: -100},
{lightness: -100},
{visibility: "off"},
],
},
{
featureType: "road",
elementType: "geometry",
stylers: [
{hue: "#bbbbbb"},
{saturation: -100},
{lightness: 26},
{visibility: "on"},
],
},
{
featureType: "road",
elementType: "labels",
stylers: [
{hue: "#ffffff"},
{saturation: -100},
{lightness: 100},
{visibility: "off"},
],
},
{
featureType: "road.local",
stylers: [
{hue: "#ffffff"},
{saturation: -100},
{lightness: 100},
{visibility: "on"},
],
},
{
featureType: "transit",
elementType: "labels",
stylers: [
{hue: "#000000"},
{lightness: -100},
{visibility: "off"},
],
},
{
featureType: "water",
stylers: [
{saturation: -100}
]
},
{
featureType: "water",
elementType: "geometry",
stylers: [
{saturation: -100},
{lightness: 100},
{visibility: "on"},
],
},
{
featureType: "water",
elementType: "geometry.fill",
stylers: [
{color: "#fbfafa"}
],
},
{
featureType: "water",
elementType: "labels",
stylers: [
{hue: "#000000"},
{saturation: -100},
{lightness: -100},
{visibility: "off"},
],
},
],
});
const latLngList = [];
for (const location of locations) {
const position = new google.maps.LatLng(location["coords"]);
latLngList.push(position);
const marker = new google.maps.Marker({
position: position,
map: map,
icon: {
url: pin,
labelOrigin: new google.maps.Point(-30, 20),
},
title: location.title,
animation: google.maps.Animation.DROP,
label: {
color: "#000",
fontWeight: "bold",
fontSize: "12px",
text: location.city,
},
optimized: false,
visible: true,
});
if (location.uri) {
google.maps.event.addListener(marker, "click", function () {
window.location.href = location.uri;
});
}
}
if (latLngList.length > 1) {
if (latLngList.length > 2 && window.innerWidth < 600) {
map.fitBounds({
south: 21.639712295652373,
west: -21.062955980857527,
north: 66.29012644366672,
east: 44.85501276914247,
});
} else {
const bounds = new google.maps.LatLngBounds();
for (const latLng of latLngList) {
bounds.extend(latLng);
}
map.fitBounds(bounds);
}
}
};
</script>