locationmap.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (function($){
  2. Drupal.behaviors.locationmap = {
  3. attach: function(context, settings) {
  4. var target_point = new google.maps.LatLng(Drupal.settings.locationmap.lat, Drupal.settings.locationmap.lng);
  5. var mapOptions = {
  6. zoom: parseInt(Drupal.settings.locationmap.zoom),
  7. center: target_point,
  8. mapTypeId: eval(Drupal.settings.locationmap.type),
  9. mapTypeControl: true
  10. };
  11. var map = new google.maps.Map(document.getElementById("locationmap_map"), mapOptions);
  12. var markerOptions = {
  13. position: target_point,
  14. draggable: Drupal.settings.locationmap.admin,
  15. map: map
  16. };
  17. var marker = new google.maps.Marker(markerOptions);
  18. var infowindow = new google.maps.InfoWindow({
  19. content: Drupal.settings.locationmap.info
  20. });
  21. google.maps.event.addListener(marker, 'click', function() {
  22. infowindow.open(map, marker);
  23. });
  24. // Allow fine tuning of the marker position in admin mode.
  25. if (Drupal.settings.locationmap.admin) {
  26. google.maps.event.addListener(marker, 'dragend', function(event) {
  27. $('#edit-locationmap-lat').val(event.latLng.lat());
  28. $('#edit-locationmap-lng').val(event.latLng.lng());
  29. });
  30. google.maps.event.addListener(map, 'zoom_changed', function(event) {
  31. $('#edit-locationmap-zoom').val(map.getZoom());
  32. });
  33. }
  34. }
  35. };
  36. })(jQuery);