File: D:/HostingSpaces/SBogers68/investeren.ouddorp-duin.nl/wwwroot/js/googleMaps.js
/**
* Created by Pascal on 05/04/16.
*/
var mapLocation = document.getElementById('map');
$(function () {
if (mapLocation != null) {
initMap();
}
});
function initMap() {
//create height of element
var mapWidth = window.getComputedStyle(mapLocation).width;
mapWidth = parseInt(mapWidth.slice(0, -2));
mapHeight = mapWidth / 2;
if(mapHeight < 350) mapHeight = 350;
if(mapHeight > 400) mapHeight = 400;
mapLocation.style.height = mapHeight + 'px';
googleMaps(parseFloat(mapLocation.getAttribute('data-googlex')), parseFloat(mapLocation.getAttribute('data-googley')));
}
function googleMaps(googleX, googleY) {
var zoom = 14;
var mapOptions = {
// How zoomed in you want the map to start at (always required)
zoom: zoom,
minZoom: zoom,
maxZoom: zoom,
disableDefaultUI: true,
draggable: false,
scrollwheel: false,
// The latitude and longitude to center the map (always required)
center: new google.maps.LatLng(googleX, googleY),
styles: []
}
var map = new google.maps.Map(mapLocation, mapOptions);
var marker = new google.maps.Marker({
position: {lat: googleX, lng: googleY},
optimized: false,
map: map,
icon: '/img/googleMarker.png',
zIndex: 10
});
marker.setMap(map);
map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function() {
window.open('https://goo.gl/maps/2Ebdn4FZyLt');
console.log('hoi');
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}