PageSourceSearch

https://www.afaindia.com/vendor/jquery.gmap.js

js afaindia.com collected 2026-10-10 00:45:22 UTC 8,623 bytes, 272 lines download raw bytes

1/**
2 * jQuery gMap - Google Maps API V3
3 *
4 * @license MIT License; http://www.opensource.org/licenses/mit-license.php
5 * @url   http://github.com/marioestrada/jQuery-gMap
6 * @author  Mario Estrada <[email protected]> based on original plugin by Cedric Kastner <[email protected]>
7 * @version 2.1.5
8 */
9/* global google */
10(function($)
11{
12  // Main plugin function
13  $.fn.gMap = function(options, methods_options)
14  {
15    // Optional methods
16    switch(options)
17    {
18    case 'addMarker':
19      return $(this).trigger(
20        'gMap.addMarker',
21        [methods_options.latitude, methods_options.longitude, methods_options.content, methods_options.icon, methods_options.popup]
22      );
23    case 'centerAt':
24      return $(this).trigger('gMap.centerAt', [methods_options.latitude, methods_options.longitude, methods_options.zoom]);
25    case 'clearMarkers':
26      return $(this).trigger('gMap.clearMarkers');
27    }
28
29    // Build main options before element iteration
30    var opts = $.extend({}, $.fn.gMap.defaults, options);
31
32    // Iterate through each element
33    return this.each(function()
34    {
35      // Create map and set initial options
36      var $gmap = new google.maps.Map(this);
37
38      $(this).data('gMap.reference', $gmap);
39
40      // Create new object to geocode addresses
41      var $geocoder = new google.maps.Geocoder();
42
43      // Check for address to center on
44      if (opts.address)
45      {
46        // Get coordinates for given address and center the map
47        $geocoder.geocode(
48          {
49            address: opts.address
50          }, function(gresult, status)
51          {
52            if(gresult && gresult.length) {
53              $gmap.setCenter(gresult[0].geometry.location);
54            }
55          }
56        );
57      }else{
58        // Check for coordinates to center on
59        if (opts.latitude && opts.longitude)
60        {
61          // Center map to coordinates given by option
62          $gmap.setCenter(new google.maps.LatLng(opts.latitude, opts.longitude));
63        }
64        else
65        {
66          // Check for a marker to center on (if no coordinates given)
67          if ($.isArray(opts.markers) && opts.markers.length > 0)
68          {
69            // Check if the marker has an address
70            if (opts.markers[0].address)
71            {
72              // Get the coordinates for given marker address and center
73              $geocoder.geocode(
74                {
75                  address: opts.markers[0].address
76                }, function(gresult, status)
77                {
78                  if(gresult && gresult.length > 0) {
79                    $gmap.setCenter(gresult[0].geometry.location);
80                  }
81                }
82              );
83            }else{
84              // Center the map to coordinates given by marker
85              $gmap.setCenter(new google.maps.LatLng(opts.markers[0].latitude, opts.markers[0].longitude));
86            }
87          }else{
88            // Revert back to world view
89            $gmap.setCenter(new google.maps.LatLng(34.885931, 9.84375));
90          }
91        }
92      }
93      $gmap.setZoom(opts.zoom);
94
95      // Set the preferred map type
96      $gmap.setMapTypeId(google.maps.MapTypeId[opts.maptype]);
97
98      // Set scrollwheel option
99      var map_options = { scrollwheel: opts.scrollwheel, disableDoubleClickZoom: !opts.doubleclickzoom };
100      // Check for map controls
101      if(opts.controls === false){
102        $.extend(map_options, { disableDefaultUI: true });
103      }else if (opts.controls.length !== 0){
104        $.extend(map_options, opts.controls, { disableDefaultUI: true });
105      }
106
107      $gmap.setOptions(map_options);
108
109      // Create new icon
110      var gicon = new google.maps.Marker();
111      var marker_icon;
112      var marker_shadow;
113
114      // Set icon properties from global options
115      marker_icon = new google.maps.MarkerImage(opts.icon.image);
116      marker_icon.size = new google.maps.Size(opts.icon.iconsize[0], opts.icon.iconsize[1]);
117      marker_icon.anchor = new google.maps.Point(opts.icon.iconanchor[0], opts.icon.iconanchor[1]);
118      gicon.setIcon(marker_icon);
119
120      if(opts.icon.shadow)
121      {
122        marker_shadow = new google.maps.MarkerImage(opts.icon.shadow);
123        marker_shadow.size = new google.maps.Size(opts.icon.shadowsize[0], opts.icon.shadowsize[1]);
124        marker_shadow.anchor = new google.maps.Point(opts.icon.shadowanchor[0], opts.icon.shadowanchor[1]);
125        gicon.setShadow(marker_shadow);
126      }
127
128      // Bind actions
129      $(this).bind('gMap.centerAt', function(e, latitude, longitude, zoom)
130      {
131        if(zoom) {
132          $gmap.setZoom(zoom);
133        }
134
135        $gmap.panTo(new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude)));
136      });
137
138      // Clear Markers
139      var overlays = [];
140      $(this).bind('gMap.clearMarkers', function()
141      {
142        while(overlays[0]){
143          overlays.pop().setMap(null);
144        }
145      });
146
147      var last_infowindow;
148      $(this).bind('gMap.addMarker', function(e, latitude, longitude, content, icon, popup)
149      {
150        var marker_icon;
151        var marker_shadow;
152        var glatlng = new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude));
153
154        var gmarker = new google.maps.Marker({
155          position: glatlng
156        });
157
158        if(icon)
159        {
160          marker_icon = new google.maps.MarkerImage(icon.image);
161          marker_icon.size = new google.maps.Size(icon.iconsize[0], icon.iconsize[1]);
162          marker_icon.anchor = new google.maps.Point(icon.iconanchor[0], icon.iconanchor[1]);
163          gmarker.setIcon(marker_icon);
164
165          if(icon.shadow)
166          {
167            marker_shadow = new google.maps.MarkerImage(icon.shadow);
168            marker_shadow.size = new google.maps.Size(icon.shadowsize[0], icon.shadowsize[1]);
169            marker_shadow.anchor = new google.maps.Point(icon.shadowanchor[0], icon.shadowanchor[1]);
170            gicon.setShadow(marker_shadow);
171          }
172        }else{
173          gmarker.setIcon(gicon.getIcon());
174          gmarker.setShadow(gicon.getShadow());
175        }
176
177        if(content)
178        {
179          if(content === '_latlng') {
180            content = latitude + ', ' + longitude;
181          }
182
183          var infowindow = new google.maps.InfoWindow({
184            content: opts.html_prepend + content + opts.html_append
185          });
186
187          google.maps.event.addListener(gmarker, 'click', function()
188          {
189            if (last_infowindow) {
190              last_infowindow.close();
191            }
192            infowindow.open($gmap, gmarker);
193            last_infowindow = infowindow;
194          });
195
196          if(popup)
197          {
198            google.maps.event.addListenerOnce($gmap, 'tilesloaded', function()
199            {
200              infowindow.open($gmap, gmarker);
201            });
202          }
203        }
204        gmarker.setMap($gmap);
205        overlays.push(gmarker);
206      });
207
208      var marker;
209      var self = this;
210      var geocode_callback = function(marker) {
211        return function(gresult, status) {
212          // Create marker
213          if(gresult && gresult.length > 0)
214          {
215            $(self).trigger(
216              'gMap.addMarker',
217              [gresult[0].geometry.location.lat(), gresult[0].geometry.location.lng(), marker.html, marker.icon, marker.popup]
218            );
219          }
220        };
221      };
222
223      // Loop through marker array
224      for (var j = 0; j < opts.markers.length; j++)
225      {
226        // Get the options from current marker
227        marker = opts.markers[j];
228
229        // Check if address is available
230        if (marker.address)
231        {
232          // Check for reference to the marker's address
233          if (marker.html === '_address') {
234            marker.html = marker.address;
235          }
236
237          // Get the point for given address
238          $geocoder.geocode({
239              address: marker.address
240            }, geocode_callback(marker));
241        }else{
242          $(this).trigger('gMap.addMarker', [marker.latitude, marker.longitude, marker.html, marker.icon, marker.popup]);
243        }
244      }
245    });
246
247  };
248
249  // Default settings
250  $.fn.gMap.defaults = {
251    address: '',
252    latitude: 0,
253    longitude: 0,
254    zoom: 1,
255    markers: [],
256    controls: [],
257    scrollwheel: false,
258    doubleclickzoom: true,
259    maptype: 'ROADMAP',
260    html_prepend: '<div class="gmap_marker">',
261    html_append: '</div>',
262    icon: {
263      image: "http://www.google.com/mapfiles/marker.png",
264      shadow: "http://www.google.com/mapfiles/shadow50.png",
265      iconsize: [20, 34],
266      shadowsize: [37, 34],
267      iconanchor: [9, 34],
268      shadowanchor: [6, 34]
269    }
270  };
271
272})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.