maps.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // When the window has finished loading create our google map below
  2. google.maps.event.addDomListener(window, 'load', init);
  3. function init() {
  4. // Basic options for a simple Google Map
  5. // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
  6. var mapElement = document.getElementById('google-map');
  7. var map_lat = mapElement.getAttribute('data-latitude');
  8. var map_lon = mapElement.getAttribute('data-longitude');
  9. var map_title = mapElement.getAttribute('data-map-title');
  10. var map_zoom = mapElement.getAttribute('data-map-zoom');
  11. var mapOptions = {
  12. // How zoomed in you want the map to start at (always required)
  13. zoom: parseInt(map_zoom),
  14. // The latitude and longitude to center the map (always required)
  15. center: new google.maps.LatLng(map_lat, map_lon),
  16. // How you would like to style the map.
  17. // This is where you would paste any style found on Snazzy Maps.
  18. styles: [{ "featureType": "water", "elementType": "geometry", "stylers": [{ "color": "#e9e9e9" }, { "lightness": 17 }] }, { "featureType": "landscape", "elementType": "geometry", "stylers": [{ "color": "#f5f5f5" }, { "lightness": 20 }] }, { "featureType": "road.highway", "elementType": "geometry.fill", "stylers": [{ "color": "#ffffff" }, { "lightness": 17 }] }, { "featureType": "road.highway", "elementType": "geometry.stroke", "stylers": [{ "color": "#ffffff" }, { "lightness": 29 }, { "weight": 0.2 }] }, { "featureType": "road.arterial", "elementType": "geometry", "stylers": [{ "color": "#ffffff" }, { "lightness": 18 }] }, { "featureType": "road.local", "elementType": "geometry", "stylers": [{ "color": "#ffffff" }, { "lightness": 16 }] }, { "featureType": "poi", "elementType": "geometry", "stylers": [{ "color": "#f5f5f5" }, { "lightness": 21 }] }, { "featureType": "poi.park", "elementType": "geometry", "stylers": [{ "color": "#dedede" }, { "lightness": 21 }] }, { "elementType": "labels.text.stroke", "stylers": [{ "visibility": "on" }, { "color": "#ffffff" }, { "lightness": 16 }] }, { "elementType": "labels.text.fill", "stylers": [{ "saturation": 36 }, { "color": "#333333" }, { "lightness": 40 }] }, { "elementType": "labels.icon", "stylers": [{ "visibility": "off" }] }, { "featureType": "transit", "elementType": "geometry", "stylers": [{ "color": "#f2f2f2" }, { "lightness": 19 }] }, { "featureType": "administrative", "elementType": "geometry.fill", "stylers": [{ "color": "#fefefe" }, { "lightness": 20 }] }, { "featureType": "administrative", "elementType": "geometry.stroke", "stylers": [{ "color": "#fefefe" }, { "lightness": 17 }, { "weight": 1.2 }] }]
  19. };
  20. // Get the HTML DOM element that will contain your map
  21. // We are using a div with id="map" seen below in the <body>
  22. var mapElement = document.getElementById('google-map');
  23. // Create the Google Map using our element and options defined above
  24. var map = new google.maps.Map(mapElement, mapOptions);
  25. // Let's also add a marker while we're at it
  26. var marker = new google.maps.Marker({
  27. position: new google.maps.LatLng(map_lat, map_lon),
  28. map: map,
  29. title: map_title
  30. });
  31. var map_locations = document.getElementById("map-address");
  32. map_locations.addEventListener("click",function(e){
  33. e.preventDefault()
  34. var newlat = e.target.getAttribute('data-latitude');
  35. var newlon = e.target.getAttribute('data-longitude');
  36. var newtitle = e.target.getAttribute('data-map-title');
  37. var newzoom = e.target.getAttribute('data-map-zoom');
  38. marker.setPosition( new google.maps.LatLng( newlat, newlon ) );
  39. marker.setTitle(newtitle);
  40. map.panTo( new google.maps.LatLng( newlat, newlon ) );
  41. map.setZoom( parseInt(newzoom) );
  42. },false);
  43. }