Guest User

Link to GoogleMap (site.js)

a guest
Apr 21st, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.91 KB | None | 0 0
  1. /**
  2.  * Title: Pronamic Google Maps
  3.  * Description:
  4.  * Copyright: Copyright (c) 2005 - 2011
  5.  * Company: Pronamic
  6.  * @author Remco Tolsma
  7.  * @version 1.0
  8.  */
  9. (function($) {
  10.     var methods = {
  11.         /**
  12.          * Build map
  13.          *
  14.          * @param s an jQuery selector
  15.          */
  16.         buildMap: function(s) {
  17.             var element = $(s);
  18.  
  19.             var info = $.parseJSON(element.find('input[name="pgm-info"]').val());
  20.  
  21.             var canvas = element.find(".canvas").get(0);
  22.  
  23.             if(canvas) {
  24.                 // Location
  25.                 var location =  new google.maps.LatLng(info.latitude, info.longitude);
  26.  
  27.                 // Map options
  28.                 var mapOptions = $.extend({
  29.                         center: location
  30.                     } ,
  31.                     info.mapOptions
  32.                 );
  33.  
  34.                 var map = new google.maps.Map(canvas, mapOptions);
  35.  
  36.                 // Marker options
  37.                 var markerOptions = $.extend({
  38.                         position: location ,
  39.                         map: map
  40.                     } ,
  41.                     info.markerOptions
  42.                 );
  43.  
  44.                 var marker = new google.maps.Marker(markerOptions);
  45.  
  46.                 element.data("google-maps", map);
  47.                 element.data("google-maps-marker", marker);
  48.            
  49.                 var infoWindow = new google.maps.InfoWindow({content: info.description});
  50.  
  51.                 google.maps.event.addListener(marker, "click", function() {
  52.                     infoWindow.open(map, marker);
  53.                 });
  54.  
  55.  
  56.                 google.maps.event.addListener(map, "click", function() {
  57.                     window.open("http://maps.google.com/maps?ll=" + info.latitude + "," + info.longitude + "&z=" + info.mapOptions.zoom + "&q=to+location@" + info.latitude + "," + info.longitude);
  58.                 });
  59.  
  60.                 // Trigger ready event
  61.                 element.trigger("pronamic-google-maps-ready", map);
  62.             }
  63.         } ,
  64.  
  65.         //////////////////////////////////////////////////
  66.  
  67.         /**
  68.          * Build mashup
  69.          *
  70.          * @param s an jQuery selector
  71.          */
  72.         buildMashup: function(s) {
  73.             var element = $(s);
  74.  
  75.             var list = element.find("ul");
  76.  
  77.             var mashupInfo = $.parseJSON(element.find('input[name="pgmm-info"]').val());
  78.  
  79.             var canvas = element.find(".canvas").get(0);
  80.  
  81.             if(canvas) {
  82.                 if(mashupInfo.hideList) {
  83.                     list.hide();
  84.                 }
  85.                
  86.                 var center = new google.maps.LatLng(mashupInfo.center.latitude, mashupInfo.center.longitude);
  87.                 if(google.loader.ClientLocation) {
  88.                     center = new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
  89.                 }
  90.  
  91.                 // Map options
  92.                 var mapOptions = $.extend({
  93.                         center: center
  94.                     } ,
  95.                     mashupInfo.mapOptions
  96.                 );
  97.  
  98.                 var map = new google.maps.Map(canvas, mapOptions);
  99.  
  100.                 // MarkerClustererPlus options
  101.                 var markerClusterer = false;
  102.                 if(mashupInfo.markerClustererOptions) {
  103.                     var markerClusterer = new MarkerClusterer(map, [], mashupInfo.markerClustererOptions);
  104.                 }
  105.                
  106.                 // Associated the Google Maps with the element so other developers can easily retrieve the Google Maps object
  107.                 element.data("google-maps", map);
  108.  
  109.                 // Create one info window where the details from the posts will be displayed in
  110.                 var infoWindow = new google.maps.InfoWindow();
  111.                
  112.                 // Create an bounds object so we can fit the map to show all posts
  113.                 var bounds = new google.maps.LatLngBounds();
  114.  
  115.                 $.each(mashupInfo.markers, function(i, info) {
  116.                     var location =  new google.maps.LatLng(info.lat, info.lng);
  117.  
  118.                     var markerOptions = $.extend({
  119.                             position: location
  120.                         } ,
  121.                         info.options
  122.                     );
  123.  
  124.                     var marker = new google.maps.Marker(markerOptions);
  125.  
  126.                     google.maps.event.addListener(marker, "click", function() {
  127.                         infoWindow.setContent(info.description);
  128.                         infoWindow.open(map, marker);
  129.  
  130.                         element.trigger("pronamic-google-maps-infowindow-open", infoWindow);
  131.                     });
  132.  
  133.                     if(markerClusterer) {
  134.                         markerClusterer.addMarker(marker, false);
  135.                     } else {
  136.                         marker.setMap(map);
  137.                     }
  138.  
  139.                     // Extends the bounds object with this location so we can fit the map to show all posts
  140.                     bounds.extend(location);
  141.                 });
  142.  
  143.                 if(markerClusterer) {
  144.                     markerClusterer.repaint();
  145.                 }
  146.  
  147.                 if(mashupInfo.fitBounds) {
  148.                     map.fitBounds(bounds);
  149.                 }
  150.  
  151.                 // Trigger ready event
  152.                 element.trigger("pronamic-google-maps-ready", map);
  153.             }
  154.         }
  155.     };
  156.  
  157.     //////////////////////////////////////////////////
  158.  
  159.     /**
  160.      * The Pronamic Google Maps jQuery plugin function
  161.      */
  162.     $.fn.pronamicGoogleMaps = function() {
  163.         return this.each(function() {
  164.             methods.buildMap(this);
  165.         });
  166.     };
  167.  
  168.     //////////////////////////////////////////////////
  169.  
  170.     /**
  171.      * The Pronamic Google Maps mashup jQuery plugin function
  172.      */
  173.     $.fn.pronamicGoogleMapsMashup = function() {
  174.         return this.each(function() {
  175.             methods.buildMashup(this);
  176.         });
  177.     };
  178.    
  179.     //////////////////////////////////////////////////
  180.  
  181.     /**
  182.      * Initialize
  183.      */
  184.     var initialize = function() {
  185.         $(".pgm").pronamicGoogleMaps();
  186.        
  187.         $(".pgmm").pronamicGoogleMapsMashup();
  188.     };
  189.  
  190.     /**
  191.      * Ready
  192.      */
  193.     $(document).ready(function() {
  194.         google.load("maps", "3",  {
  195.             callback: initialize ,
  196.             other_params: "sensor=false"
  197.         });
  198.     });
  199. })(jQuery);
Add Comment
Please, Sign In to add comment