/* ==========================================================================
Google Maps handler
-- https://developers.google.com/maps/documentation/javascript/adding-a-google-map
========================================================================== */
var MapsHandler = {
map: '',
key: '',
location: {lat: 51.2618222, lng: 5.5965538},
styling: '',
init: function () {
// Get map by id
MapsHandler.map = document.getElementById('map');
// Check if a map is defined
if (isset(MapsHandler.map)) {
MapsHandler.key = MapsHandler.map.getAttribute('data-api-key');
MapsHandler.location.lat = parseFloat(MapsHandler.map.getAttribute('data-google-lat'));
MapsHandler.location.lng = parseFloat(MapsHandler.map.getAttribute('data-google-lng'));
MapsHandler.setCustomStyling();
// See if google variable exists
if (typeof(google) == 'undefined' || typeof(google.maps) == 'undefined') {
// Load external script
$.getScript('https://maps.googleapis.com/maps/api/js?key=' + MapsHandler.key)
.done(function (script, textStatus) {
MapsHandler.drawMap();
});
} else {
MapsHandler.drawMap()
}
}
},
drawMap: function () {
// Create a map
var map = new google.maps.Map(MapsHandler.map, {
zoom: 12,
center: MapsHandler.location,
disableDefaultUI: true,
styles: MapsHandler.styling
});
// Add a marker
var marker = new google.maps.Marker({
position: MapsHandler.location,
map: map
});
},
setCustomStyling: function () {
MapsHandler.styling =
[
{
"featureType": "landscape",
"stylers": [
{
"saturation": -100
},
{
"lightness": 60
}
]
},
{
"featureType": "road.local",
"stylers": [
{
"saturation": -100
},
{
"lightness": 40
},
{
"visibility": "on"
}
]
},
{
"featureType": "transit",
"stylers": [
{
"saturation": -100
},
{
"visibility": "simplified"
}
]
},
{
"featureType": "administrative.province",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"stylers": [
{
"visibility": "on"
},
{
"lightness": 30
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#ef8c25"
},
{
"lightness": 40
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "poi.park",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#b6c54c"
},
{
"lightness": 40
},
{
"saturation": -40
}
]
},
];
}
};
MapsHandler.init();