gmaps4rails 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/public/javascripts/gmaps4rails.js +289 -102
  2. metadata +4 -4
@@ -1,59 +1,70 @@
1
1
  var Gmaps4Rails = {
2
2
  //map config
3
- map: null, //contains the map we're working on
4
- visibleInfoWindow: null,
5
-
3
+ map: null, // contains the map we're working on
4
+ visibleInfoWindow: null, //contains the current opened infowindow
5
+ userLocation: null, //contains user's location if geolocalization was performed and successful
6
+
6
7
  //Map settings
7
8
  map_options: {
8
9
  id: 'gmaps4rails_map',
9
- type: "ROADMAP", // HYBRID, ROADMAP, SATELLITE, TERRAIN
10
- center_latitude : 0,
11
- center_longitude : 0,
12
- zoom : 1,
10
+ disableDefaultUI: false,
11
+ disableDoubleClickZoom: false,
12
+ draggable: true,
13
+ type: "ROADMAP", // HYBRID, ROADMAP, SATELLITE, TERRAIN
14
+ detect_location: false, // should the browser attempt to use geolocation detection features of HTML5?
15
+ center_on_user: false, // centers map on the location detected through the browser
16
+ center_latitude: 0,
17
+ center_longitude: 0,
18
+ zoom: 1,
13
19
  maxZoom: null,
14
20
  minZoom: null,
15
- auto_adjust : false, //adjust the map to the markers if set to true
16
- auto_zoom: true, //zoom given by auto-adjust
17
- bounds: [] //adjust map to these limits. Should be [{"lat": , "lng": }]
18
- },
21
+ auto_adjust : false, // adjust the map to the markers if set to true
22
+ auto_zoom: true, // zoom given by auto-adjust
23
+ bounds: [] // adjust map to these limits. Should be [{"lat": , "lng": }]
24
+ },
19
25
 
20
26
  //markers + info styling
21
27
  markers_conf: {
28
+ // Marker config
29
+ title: "",
30
+ // MarkerImage config
22
31
  picture : "",
23
- width : 22,
24
- length : 32,
32
+ width: 22,
33
+ length: 32,
34
+ anchor: null, // centeranchor position of the marker image. Default is null <=> center, you can set options: top_left, top_center, top_right, center_left, center, center_right, bottom_right, bottom_center, bottom_left
25
35
  //clustering config
26
- do_clustering: true, //do clustering if set to true
27
- clusterer_gridSize: 50, //the more the quicker but the less precise
28
- clusterer_maxZoom: 5, //removes clusterer at this zoom level
29
- randomize: false, //Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
30
- max_random_distance: 100, //in meters. Each marker coordinate could be altered by this distance in a random direction
31
- list_container : null //id of the ul that will host links to all markers
32
- },
36
+ do_clustering: true, // do clustering if set to true
37
+ clusterer_gridSize: 50, // the more the quicker but the less precise
38
+ clusterer_maxZoom: 5, // removes clusterer at this zoom level
39
+ randomize: false, // Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
40
+ max_random_distance: 100, // in meters. Each marker coordinate could be altered by this distance in a random direction
41
+ list_container: null, // id of the ul that will host links to all markers
42
+ custom_cluster_pictures: null
43
+ },
33
44
 
34
45
  //Stored variables
35
- markers : [], //contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "google_object": google_marker}
36
- bounds_object: null, //contains current bounds from markers, polylines etc...
37
- polygons: [], //contains raw data, array of arrays (first element could be a hash containing options)
38
- polylines: [], //contains raw data, array of arrays (first element could be a hash containing options)
39
- circles: [], //contains raw data, array of hash
40
- markerClusterer: null, //contains all marker clusterers
46
+ markers: [], // contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "google_object": google_marker}
47
+ bounds_object: null, // contains current bounds from markers, polylines etc...
48
+ polygons: [], // contains raw data, array of arrays (first element could be a hash containing options)
49
+ polylines: [], // contains raw data, array of arrays (first element could be a hash containing options)
50
+ circles: [], // contains raw data, array of hash
51
+ markerClusterer: null, // contains all marker clusterers
41
52
 
42
53
  //Polygon Styling
43
- polygons_conf: { //default style for polygons
54
+ polygons_conf: { // default style for polygons
44
55
  strokeColor: "#FFAA00",
45
56
  strokeOpacity: 0.8,
46
57
  strokeWeight: 2,
47
58
  fillColor: "#000000",
48
59
  fillOpacity: 0.35
49
- },
60
+ },
50
61
 
51
62
  //Polyline Styling
52
63
  polylines_conf: { //default style for polylines
53
64
  strokeColor: "#FF0000",
54
65
  strokeOpacity: 1,
55
66
  strokeWeight: 2
56
- },
67
+ },
57
68
 
58
69
  //Circle Styling
59
70
  circles_conf: { //default style for circles
@@ -61,8 +72,10 @@ var Gmaps4Rails = {
61
72
  fillOpacity: 0.35,
62
73
  strokeColor: "#FFAA00",
63
74
  strokeOpacity: 0.8,
64
- strokeWeight: 2
65
- },
75
+ strokeWeight: 2,
76
+ clickable: false,
77
+ zIndex: null
78
+ },
66
79
 
67
80
  //Direction Settings
68
81
  direction_conf: {
@@ -70,7 +83,7 @@ var Gmaps4Rails = {
70
83
  display_panel: false,
71
84
  origin: null,
72
85
  destination: null,
73
- waypoints: [], //[{location: "toulouse,fr", stopover: true}, {location: "Clermont-Ferrand, fr", stopover: true}]
86
+ waypoints: [], //[{location: "toulouse,fr", stopover: true}, {location: "Clermont-Ferrand, fr", stopover: true}]
74
87
  optimizeWaypoints: false,
75
88
  unitSystem: "METRIC", //IMPERIAL
76
89
  avoidHighways: false,
@@ -78,19 +91,50 @@ var Gmaps4Rails = {
78
91
  region: null,
79
92
  travelMode: "DRIVING" //WALKING, BICYCLING
80
93
  },
94
+
81
95
  //initializes the map
82
- initialize: function(){
96
+ initialize: function() {
97
+
83
98
  this.map = new google.maps.Map(document.getElementById(this.map_options.id), {
84
99
  maxZoom: this.map_options.maxZoom,
85
100
  minZoom: this.map_options.minZoom,
86
101
  zoom: this.map_options.zoom,
87
- center: new google.maps.LatLng(this.map_options.center_latitude, this.map_options.center_longitude),
88
- mapTypeId: google.maps.MapTypeId[this.map_options.type]
102
+ center: new google.maps.LatLng(this.map_options.center_latitude, this.map_options.center_longitude),
103
+ mapTypeId: google.maps.MapTypeId[this.map_options.type],
104
+ mapTypeControl: this.map_options.mapTypeControl,
105
+ disableDefaultUI: this.map_options.disableDefaultUI,
106
+ disableDoubleClickZoom: this.map_options.disableDoubleClickZoom,
107
+ draggable: this.map_options.draggable
89
108
  });
109
+
110
+ if (this.map_options.detect_location === true || this.map_options.center_on_user === true) {
111
+ this.findUserLocation();
112
+ }
90
113
  //resets sidebar if needed
91
114
  this.reset_sidebar_content();
92
115
  },
93
116
 
117
+ findUserLocation: function() {
118
+ if(navigator.geolocation) {
119
+ navigator.geolocation.getCurrentPosition(function(position) {
120
+ Gmaps4Rails.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
121
+ //change map's center to focus on user's geoloc
122
+ if(Gmaps4Rails.map_options.center_on_user === true) {
123
+ Gmaps4Rails.map.setCenter(Gmaps4Rails.userLocation);
124
+ }
125
+ },
126
+ function() {
127
+ if(this.fnSet("gmaps4rails_geolocation_failure")) { gmaps4rails_geolocation_failure(true); }
128
+ });
129
+ } else {
130
+ if(this.fnSet("gmaps4rails_geolocation_failure")) { gmaps4rails_geolocation_failure(false); }
131
+ }
132
+ },
133
+
134
+ ////////////////////////////////////////////////////
135
+ //////////////////// DIRECTIONS ////////////////////
136
+ ////////////////////////////////////////////////////
137
+
94
138
  create_direction: function(){
95
139
  var directionsDisplay = new google.maps.DirectionsRenderer();
96
140
  var directionsService = new google.maps.DirectionsService();
@@ -99,9 +143,9 @@ var Gmaps4Rails = {
99
143
  //display panel only if required
100
144
  if (this.direction_conf.display_panel) { directionsDisplay.setPanel(document.getElementById(this.direction_conf.panel_id)); }
101
145
  directionsDisplay.setOptions({
102
- suppressMarkers: true,
146
+ suppressMarkers: false,
103
147
  suppressInfoWindows: false,
104
- suppressPolylines: false
148
+ suppressPolylines: false
105
149
  });
106
150
  var request = {
107
151
  origin: this.direction_conf.origin,
@@ -113,7 +157,7 @@ var Gmaps4Rails = {
113
157
  avoidTolls: this.direction_conf.avoidTolls,
114
158
  region: this.direction_conf.region,
115
159
  travelMode: google.maps.DirectionsTravelMode[this.direction_conf.travelMode],
116
- language: "fr"
160
+ language: "en"
117
161
  };
118
162
  directionsService.route(request, function(response, status) {
119
163
  if (status == google.maps.DirectionsStatus.OK) {
@@ -122,38 +166,81 @@ var Gmaps4Rails = {
122
166
  });
123
167
  },
124
168
 
169
+ ////////////////////////////////////////////////////
170
+ ///////////////////// CIRCLES //////////////////////
171
+ ////////////////////////////////////////////////////
172
+
125
173
  //Loops through all circles
126
- create_circles: function(){
174
+ //Loops through all circles and draws them
175
+ create_circles: function() {
127
176
  for (var i = 0; i < this.circles.length; ++i) {
128
177
  //by convention, default style configuration could be integrated in the first element
129
- if ( i === 0 )
130
- {
131
- if (this.exists(this.circles[i].strokeColor )) { this.circles_conf.strokeColor = this.circles[i].strokeColor; }
132
- if (this.exists(this.circles[i].strokeOpacity)) { this.circles_conf.strokeOpacity = this.circles[i].strokeOpacity; }
133
- if (this.exists(this.circles[i].strokeWeight )) { this.circles_conf.strokeWeight = this.circles[i].strokeWeight; }
134
- if (this.exists(this.circles[i].fillColor )) { this.circles_conf.fillColor = this.circles[i].fillColor; }
135
- if (this.exists(this.circles[i].fillOpacity )) { this.circles_conf.fillOpacity = this.circles[i].fillOpacity; }
136
- }
137
- if (this.exists(this.circles[i].latitude) && this.exists(this.circles[i].longitude))
138
- {
139
- center = new google.maps.LatLng(this.circles[i].latitude, this.circles[i].longitude);
140
- //always check if a config is given, if not, use defaults
141
- var circle = new google.maps.Circle({
142
- center: center,
143
- strokeColor: this.circles[i].strokeColor || this.circles_conf.strokeColor,
144
- strokeOpacity: this.circles[i].strokeOpacity || this.circles_conf.strokeOpacity,
145
- strokeWeight: this.circles[i].strokeWeight || this.circles_conf.strokeWeight,
146
- fillOpacity: this.circles[i].fillOpacity || this.circles_conf.fillOpacity,
147
- fillColor: this.circles[i].fillColor || this.circles_conf.fillColor,
148
- radius: this.circles[i].radius,
149
- clickable: false
150
- });
151
- this.circles[i].google_object = circle;
152
- circle.setMap(this.map);
153
- }
178
+ this.create_circle(this.circles[i]);
179
+ }
180
+ },
181
+
182
+ create_circle: function(circle) {
183
+ if ( i === 0 ) {
184
+ if (this.exists(circle.strokeColor )) { this.circles_conf.strokeColor = circle.strokeColor; }
185
+ if (this.exists(circle.strokeOpacity)) { this.circles_conf.strokeOpacity = circle.strokeOpacity; }
186
+ if (this.exists(circle.strokeWeight )) { this.circles_conf.strokeWeight = circle.strokeWeight; }
187
+ if (this.exists(circle.fillColor )) { this.circles_conf.fillColor = circle.fillColor; }
188
+ if (this.exists(circle.fillOpacity )) { this.circles_conf.fillOpacity = circle.fillOpacity; }
189
+ }
190
+ if (this.exists(circle.latitude) && this.exists(circle.longitude)) {
191
+ // always check if a config is given, if not, use defaults
192
+ // NOTE: is there a cleaner way to do this? Maybe a hash merge of some sort?
193
+ var newCircle = new google.maps.Circle({
194
+ center: new google.maps.LatLng(circle.latitude, circle.longitude),
195
+ strokeColor: circle.strokeColor || this.circles_conf.strokeColor,
196
+ strokeOpacity: circle.strokeOpacity || this.circles_conf.strokeOpacity,
197
+ strokeWeight: circle.strokeWeight || this.circles_conf.strokeWeight,
198
+ fillOpacity: circle.fillOpacity || this.circles_conf.fillOpacity,
199
+ fillColor: circle.fillColor || this.circles_conf.fillColor,
200
+ clickable: circle.clickable || this.circles_conf.clickable,
201
+ zIndex: circle.zIndex || this.circles_conf.zIndex,
202
+ radius: circle.radius
203
+ });
204
+ circle.google_object = newCircle;
205
+ newCircle.setMap(this.map);
154
206
  }
155
207
  },
156
208
 
209
+ // clear circles
210
+ clear_circles: function() {
211
+ for (var i = 0; i < this.circles.length; ++i) {
212
+ this.clear_circle(this.circles[i]);
213
+ }
214
+ },
215
+
216
+ clear_circle: function(circle) {
217
+ circle.google_object.setMap(null);
218
+ },
219
+
220
+ hide_circles: function() {
221
+ for (var i = 0; i < this.circles.length; ++i) {
222
+ this.hide_circle(this.circles[i]);
223
+ }
224
+ },
225
+
226
+ hide_circle: function(circle) {
227
+ circle.google_object.setMap(null);
228
+ },
229
+
230
+ show_circles: function() {
231
+ for (var i = 0; i < this.circles.length; ++i) {
232
+ this.show_circle(this.circles[i]);
233
+ }
234
+ },
235
+
236
+ show_circle: function(circle) {
237
+ circle.google_object.setMap(this.map);
238
+ },
239
+
240
+ ////////////////////////////////////////////////////
241
+ ///////////////////// POLYGONS /////////////////////
242
+ ////////////////////////////////////////////////////
243
+
157
244
  //polygons is an array of arrays. It loops.
158
245
  create_polygons: function(){
159
246
  for (var i = 0; i < this.polygons.length; ++i) {
@@ -197,6 +284,10 @@ var Gmaps4Rails = {
197
284
  this.polygons[i].google_object = new_poly;
198
285
  new_poly.setMap(this.map);
199
286
  },
287
+
288
+ ////////////////////////////////////////////////////
289
+ /////////////////// POLYLINES //////////////////////
290
+ ////////////////////////////////////////////////////
200
291
 
201
292
  //polylines is an array of arrays. It loops.
202
293
  create_polylines: function(){
@@ -206,7 +297,7 @@ var Gmaps4Rails = {
206
297
  },
207
298
 
208
299
  //creates a single polyline, triggered by create_polylines
209
- create_polyline: function(i){
300
+ create_polyline: function(i) {
210
301
  var polyline_coordinates = [];
211
302
  var strokeColor;
212
303
  var strokeOpacity;
@@ -215,7 +306,7 @@ var Gmaps4Rails = {
215
306
  //2 cases here, either we have a coded array of LatLng or we have an Array of LatLng
216
307
  for (var j = 0; j < this.polylines[i].length; ++j) {
217
308
  //if we have a coded array
218
- if (this.exists(this.polylines[i][j].coded_array)){
309
+ if (this.exists(this.polylines[i][j].coded_array)) {
219
310
  var decoded_array = new google.maps.geometry.encoding.decodePath(this.polylines[i][j].coded_array);
220
311
  //loop through every point in the array
221
312
  for (var k = 0; k < decoded_array.length; ++k) {
@@ -226,14 +317,13 @@ var Gmaps4Rails = {
226
317
  //or we have an array of latlng
227
318
  else{
228
319
  //by convention, a single polyline could be customized in the first array or it uses default values
229
- if (j===0){
320
+ if (j===0) {
230
321
  strokeColor = this.polylines[i][0].strokeColor || this.polylines_conf.strokeColor;
231
322
  strokeOpacity = this.polylines[i][0].strokeOpacity || this.polylines_conf.strokeOpacity;
232
323
  strokeWeight = this.polylines[i][0].strokeWeight || this.polylines_conf.strokeWeight;
233
324
  }
234
325
  //add latlng if positions provided
235
- if (this.exists(this.polylines[i][j].latitude) && this.exists(this.polylines[i][j].longitude))
236
- {
326
+ if (this.exists(this.polylines[i][j].latitude) && this.exists(this.polylines[i][j].longitude)) {
237
327
  var latlng = new google.maps.LatLng(this.polylines[i][j].latitude, this.polylines[i][j].longitude);
238
328
  polyline_coordinates.push(latlng);
239
329
  }
@@ -252,6 +342,10 @@ var Gmaps4Rails = {
252
342
  new_poly.setMap(this.map);
253
343
  },
254
344
 
345
+ ////////////////////////////////////////////////////
346
+ ///////////////////// MARKERS //////////////////////
347
+ ////////////////////////////////////////////////////
348
+
255
349
  //creates, clusterizes and adjusts map
256
350
  create_markers: function() {
257
351
  this.create_google_markers_from_markers();
@@ -260,7 +354,7 @@ var Gmaps4Rails = {
260
354
  },
261
355
 
262
356
  //create google.maps Markers from data provided by user
263
- create_google_markers_from_markers: function(){
357
+ create_google_markers_from_markers: function() {
264
358
  for (var i = 0; i < this.markers.length; ++i) {
265
359
  //check if the marker has not already been created
266
360
  if (!this.exists(this.markers[i].google_object)) {
@@ -268,49 +362,122 @@ var Gmaps4Rails = {
268
362
  var marker_picture = this.exists(this.markers[i].picture) ? this.markers[i].picture : this.markers_conf.picture;
269
363
  var marker_width = this.exists(this.markers[i].width) ? this.markers[i].width : this.markers_conf.width;
270
364
  var marker_height = this.exists(this.markers[i].height) ? this.markers[i].height : this.markers_conf.length;
365
+ var marker_anchor = this.exists(this.markers[i].anchor) ? this.markers[i].anchor : this.markers_conf.anchor;
271
366
  var marker_title = this.exists(this.markers[i].title) ? this.markers[i].title : null;
272
367
  var Lat = this.markers[i].latitude;
273
368
  var Lng = this.markers[i].longitude;
274
-
369
+ var imageAnchorPosition = null;
370
+ // calculate MarkerImage anchor location
371
+ if (this.exists(this.markers[i].width) && this.exists(this.markers[i].height) && marker_anchor !== null) {
372
+ imageAnchorPosition = getImageAnchorPosition(marker_width, marker_height, marker_anchor);
373
+ }
374
+
275
375
  //alter coordinates if randomize is true
276
- if ( this.markers_conf.randomize)
277
- {
278
- var LatLng = this.randomize(Lat, Lng);
279
- //retrieve coordinates from the array
280
- Lat = LatLng[0]; Lng = LatLng[1];
376
+ if ( this.markers_conf.randomize) {
377
+ var LatLng = this.randomize(Lat, Lng);
378
+ //retrieve coordinates from the array
379
+ Lat = LatLng[0]; Lng = LatLng[1];
281
380
  }
282
381
 
283
- var myLatLng = new google.maps.LatLng(Lat, Lng);
284
- var ThisMarker;
382
+ var markerLatLng = new google.maps.LatLng(Lat, Lng);
383
+ var thisMarker;
285
384
  // Marker sizes are expressed as a Size of X,Y
286
- if (marker_picture === "")
287
- { ThisMarker = new google.maps.Marker({position: myLatLng, map: this.map, title: marker_title}); }
288
- else
289
- {
290
- var image = new google.maps.MarkerImage(marker_picture, new google.maps.Size(marker_width, marker_height) );
291
- ThisMarker = new google.maps.Marker({position: myLatLng, map: this.map, icon: image, title: marker_title});
292
- }
293
- //save object
294
- this.markers[i].google_object = ThisMarker;
295
- //add infowindowstuff if enabled
296
- this.create_info_window(this.markers[i]);
297
- //create sidebar if enabled
298
- this.create_sidebar(this.markers[i]);
385
+ if (marker_picture === "") {
386
+ thisMarker = new google.maps.Marker({position: markerLatLng, map: this.map, title: marker_title});
387
+ } else {
388
+ var image = new google.maps.MarkerImage(marker_picture, new google.maps.Size(marker_width, marker_height), null, imageAnchorPosition, null );
389
+ thisMarker = new google.maps.Marker({position: markerLatLng, map: this.map, icon: image, title: marker_title});
390
+ }
391
+ //save object
392
+ this.markers[i].google_object = thisMarker;
393
+ //add infowindowstuff if enabled
394
+ this.create_info_window(this.markers[i]);
395
+ //create sidebar if enabled
396
+ this.create_sidebar(this.markers[i]);
299
397
  }
300
398
  }
301
399
 
400
+ // calculate anchor point for MarkerImage
401
+ function getImageAnchorPosition(markerWidth, markerHeight, anchorLocation) {
402
+ var x;
403
+ var y;
404
+ switch (anchorLocation) {
405
+ case "top_left":
406
+ x = 0;
407
+ y = 0;
408
+ break;
409
+ case "top_center":
410
+ x = markerWidth / 2;
411
+ y = 0;
412
+ break;
413
+ case "top_right":
414
+ x = markerWidth;
415
+ y = 0;
416
+ break;
417
+ case "center_left":
418
+ x = 0;
419
+ y = markerHeight / 2;
420
+ break;
421
+ case "center":
422
+ x = markerWidth / 2;
423
+ y = markerHeight / 2;
424
+ break;
425
+ case "center_right":
426
+ x = markerWidth;
427
+ y = markerHeight / 2;
428
+ break;
429
+ case "bottom_left":
430
+ x = 0;
431
+ y = markerHeight;
432
+ break;
433
+ case "bottom_center":
434
+ x = markerWidth / 2;
435
+ y = markerHeight;
436
+ break;
437
+ case "bottom_right":
438
+ x = markerWidth;
439
+ y = markerHeight;
440
+ break;
441
+ }
442
+ return new google.maps.Point(x,y);
443
+ }
302
444
  },
303
445
 
304
446
  // clear markers
305
- clear_markers: function(){
447
+ clear_markers: function() {
306
448
  if (this.markerClusterer !== null){
307
449
  this.markerClusterer.clearMarkers();
308
450
  }
309
- for (var i = 0; i < this.markers.length; ++i) {
310
- this.markers[i].google_object.setMap(null);
451
+ for (var i = 0; i < this.markers.length; ++i) {
452
+ this.clear_marker(this.markers[i]);
311
453
  }
312
454
  },
313
455
 
456
+ clear_marker: function(marker) {
457
+ marker.google_object.setMap(null);
458
+ },
459
+
460
+ // show and hide markers
461
+ show_markers: function() {
462
+ for (var i = 0; i < this.markers.length; ++i) {
463
+ this.show_marker(this.markers[i]);
464
+ }
465
+ },
466
+
467
+ show_marker: function(marker) {
468
+ marker.google_object.setVisible(true);
469
+ },
470
+
471
+ hide_markers: function() {
472
+ for (var i = 0; i < this.markers.length; ++i) {
473
+ this.hide_marker(this.markers[i]);
474
+ }
475
+ },
476
+
477
+ hide_marker: function(marker) {
478
+ marker.google_object.setVisible(false);
479
+ },
480
+
314
481
  // replace old markers with new markers on an existing map
315
482
  replace_markers: function(new_markers){
316
483
  //reset previous markers
@@ -342,19 +509,27 @@ var Gmaps4Rails = {
342
509
  for (var i = 0; i < this.markers.length; ++i) {
343
510
  gmarkers_array.push(this.markers[i].google_object);
344
511
  }
345
-
346
-
347
- this.markerClusterer = new MarkerClusterer(this.map, gmarkers_array, { maxZoom: this.markers_conf.clusterer_maxZoom, gridSize: this.markers_conf.clusterer_gridSize });
512
+ var clustererStyle = null;
513
+ if(this.fnSet("gmaps_custom_clusterer_pic")) {
514
+ clustererStyle = gmaps_custom_clusterer_pic();
515
+ }
516
+ this.markerClusterer = new MarkerClusterer( this.map,
517
+ gmarkers_array,
518
+ { maxZoom: this.markers_conf.clusterer_maxZoom, gridSize: this.markers_conf.clusterer_gridSize, styles: clustererStyle }
519
+ );
348
520
  }
349
521
  },
350
-
522
+
523
+ ////////////////////////////////////////////////////
524
+ /////////////////// INFO WINDOW ////////////////////
525
+ ////////////////////////////////////////////////////
526
+
351
527
  // creates infowindows
352
528
  create_info_window: function(marker_container){
353
529
  //create the infowindow
354
530
  var info_window = new google.maps.InfoWindow({content: marker_container.description });
355
531
  //add the listener associated
356
532
  google.maps.event.addListener(marker_container.google_object, 'click', this.openInfoWindow(info_window, marker_container.google_object));
357
-
358
533
  },
359
534
 
360
535
  openInfoWindow: function(infoWindow, marker) {
@@ -369,6 +544,10 @@ var Gmaps4Rails = {
369
544
  };
370
545
  },
371
546
 
547
+ ////////////////////////////////////////////////////
548
+ ///////////////////// SIDEBAR //////////////////////
549
+ ////////////////////////////////////////////////////
550
+
372
551
  //creates sidebar
373
552
  create_sidebar: function(marker_container){
374
553
  if (this.markers_conf.list_container)
@@ -400,6 +579,10 @@ var Gmaps4Rails = {
400
579
  }
401
580
  },
402
581
 
582
+ ////////////////////////////////////////////////////
583
+ ////////////////// MISCELLANEOUS ///////////////////
584
+ ////////////////////////////////////////////////////
585
+
403
586
  //to make the map fit the different LatLng points
404
587
  adjust_map_to_bounds: function(latlng) {
405
588
 
@@ -417,11 +600,11 @@ var Gmaps4Rails = {
417
600
  }
418
601
  //from polygons:
419
602
  for (var i = 0; i < this.polylines.length; ++i) {
420
- this.polylines[i].google_object.latLngs.forEach(function(obj1){ obj1.forEach(function(obj2){ Gmaps4Rails.google_bounds.extend(obj2);} );})
603
+ this.polylines[i].google_object.latLngs.forEach(function(obj1){ obj1.forEach(function(obj2){ Gmaps4Rails.google_bounds.extend(obj2);} );});
421
604
  }
422
605
  //from polylines:
423
606
  for (var i = 0; i < this.polygons.length; ++i) {
424
- this.polygons[i].google_object.latLngs.forEach(function(obj1){ obj1.forEach(function(obj2){ Gmaps4Rails.google_bounds.extend(obj2);} );})
607
+ this.polygons[i].google_object.latLngs.forEach(function(obj1){ obj1.forEach(function(obj2){ Gmaps4Rails.google_bounds.extend(obj2);} );});
425
608
  }
426
609
  //from circles
427
610
  for (var i = 0; i < this.circles.length; ++i) {
@@ -454,7 +637,11 @@ var Gmaps4Rails = {
454
637
 
455
638
  //basic function to check existence of a variable
456
639
  exists: function(var_name) {
457
- return var_name !== "" && typeof var_name !== "undefined"
640
+ return (var_name !== "" && typeof var_name !== "undefined");
641
+ },
642
+ //check existence of function
643
+ fnSet: function(fn_name){
644
+ return(typeof fn_name == 'function');
458
645
  },
459
646
 
460
647
  //randomize
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 4
10
- version: 0.8.4
9
+ - 5
10
+ version: 0.8.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benjamin Roth
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-11 00:00:00 +02:00
19
+ date: 2011-05-16 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency