Guest User

Untitled

a guest
Jun 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. (function($) {
  2.  
  3. $.fn.sightMap = function(options) {
  4. // define defaults
  5. var defaults = {
  6. center: [0, 0],
  7. zoom: 8,
  8. sights: []
  9. };
  10. // merge with plugin-params, fall back to defaults
  11. var settings = $.extend(defaults, options);
  12.  
  13. return this.each(function() {
  14. var $this = $(this);
  15. $this.data('settings', settings);
  16.  
  17. var myOptions = {
  18. zoom: settings.zoom,
  19. center: new google.maps.LatLng(settings.center[0], settings.center[1]),
  20. mapTypeId: google.maps.MapTypeId.ROADMAP
  21. };
  22.  
  23. // init GMap
  24. var map = new google.maps.Map(this, myOptions);
  25. $this.data('map', map);
  26.  
  27. map.markers = [];
  28.  
  29. var markerImage = new google.maps.MarkerImage('images/marker_sprite.png', new google.maps.Size(20, 34), new google.maps.Point(0, 0));
  30. var markerShadow = new google.maps.MarkerImage('images/marker_sprite.png', new google.maps.Size(29, 34), new google.maps.Point(29, 16), new google.maps.Point(0, 20));
  31.  
  32.  
  33. $.each(sights, function() {
  34. var marker = new google.maps.Marker({
  35. position: new google.maps.LatLng(this.position[0], this.position[1]),
  36. map: map,
  37. title: this.title,
  38. icon: markerImage,
  39. shadow: markerShadow
  40. });
  41.  
  42. var link = (!this.link || !this.linkText) ? '<p style="text-align: center;"><a href="' + this.link + '">' + this.linkText + '</a></p>' : ''
  43.  
  44. marker.infowindow = new google.maps.InfoWindow({
  45. content: '<h1>' + this.title + '</h1><p>' + this.text + '</p>' + link
  46. });
  47.  
  48.  
  49. google.maps.event.addListener(marker, 'click', function() {
  50. this.infowindow.open(map, this);
  51. });
  52.  
  53.  
  54. map.markers.push(marker);
  55. });
  56. });
  57.  
  58. }
  59.  
  60. })(jQuery);
Add Comment
Please, Sign In to add comment