gmaps4rails 0.11.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/README.rdoc +6 -2
  2. data/app/views/gmaps4rails/_gmaps4rails.html.erb +18 -20
  3. data/lib/gmaps4rails/base.rb +95 -0
  4. data/lib/gmaps4rails/extensions/hash.rb +3 -67
  5. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +13 -2
  6. data/public/javascripts/gmaps4rails/all_apis.js +5 -0
  7. data/public/javascripts/gmaps4rails/gmaps4rails.base.js +147 -112
  8. data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +182 -171
  9. data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +269 -235
  10. data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +135 -125
  11. data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +227 -218
  12. data/public/stylesheets/gmaps4rails.css +2 -2
  13. metadata +9 -111
  14. data/test/dummy/app/controllers/application_controller.rb +0 -3
  15. data/test/dummy/app/controllers/users_controller.rb +0 -60
  16. data/test/dummy/app/helpers/application_helper.rb +0 -2
  17. data/test/dummy/app/helpers/users_helper.rb +0 -3
  18. data/test/dummy/app/models/user.rb +0 -38
  19. data/test/dummy/config/application.rb +0 -41
  20. data/test/dummy/config/boot.rb +0 -6
  21. data/test/dummy/config/environment.rb +0 -5
  22. data/test/dummy/config/environments/development.rb +0 -26
  23. data/test/dummy/config/environments/production.rb +0 -49
  24. data/test/dummy/config/environments/test.rb +0 -35
  25. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  26. data/test/dummy/config/initializers/inflections.rb +0 -10
  27. data/test/dummy/config/initializers/mime_types.rb +0 -5
  28. data/test/dummy/config/initializers/secret_token.rb +0 -7
  29. data/test/dummy/config/initializers/session_store.rb +0 -8
  30. data/test/dummy/config/routes.rb +0 -7
  31. data/test/dummy/db/migrate/20110306182914_create_users.rb +0 -21
  32. data/test/dummy/db/migrate/20110430081624_add_addresses_to_users.rb +0 -11
  33. data/test/dummy/db/migrate/20110430083824_remove_address_from_users.rb +0 -9
  34. data/test/dummy/db/schema.rb +0 -35
  35. data/test/dummy/db/seeds.rb +0 -7
  36. data/test/dummy/spec/base/base_spec.rb +0 -127
  37. data/test/dummy/spec/helpers/gmaps4rails_helper_spec.rb +0 -13
  38. data/test/dummy/spec/javascripts/support/jasmine_config.rb +0 -23
  39. data/test/dummy/spec/javascripts/support/jasmine_runner.rb +0 -20
  40. data/test/dummy/spec/models/user_spec.rb +0 -284
  41. data/test/dummy/spec/requests/users_spec.rb +0 -22
  42. data/test/dummy/spec/spec_helper.rb +0 -41
  43. data/test/dummy/spec/support/factories.rb +0 -20
  44. data/test/dummy/spec/support/matchers.rb +0 -7
  45. data/test/dummy31/app/controllers/application_controller.rb +0 -3
  46. data/test/dummy31/app/controllers/users_controller.rb +0 -83
  47. data/test/dummy31/app/helpers/application_helper.rb +0 -2
  48. data/test/dummy31/app/helpers/users_helper.rb +0 -2
  49. data/test/dummy31/app/models/user.rb +0 -7
  50. data/test/dummy31/config/application.rb +0 -43
  51. data/test/dummy31/config/boot.rb +0 -6
  52. data/test/dummy31/config/environment.rb +0 -5
  53. data/test/dummy31/config/environments/development.rb +0 -27
  54. data/test/dummy31/config/environments/production.rb +0 -51
  55. data/test/dummy31/config/environments/test.rb +0 -39
  56. data/test/dummy31/config/initializers/backtrace_silencers.rb +0 -7
  57. data/test/dummy31/config/initializers/inflections.rb +0 -10
  58. data/test/dummy31/config/initializers/mime_types.rb +0 -5
  59. data/test/dummy31/config/initializers/secret_token.rb +0 -7
  60. data/test/dummy31/config/initializers/session_store.rb +0 -8
  61. data/test/dummy31/config/initializers/wrap_parameters.rb +0 -12
  62. data/test/dummy31/config/routes.rb +0 -61
  63. data/test/dummy31/db/migrate/20110809134019_create_users.rb +0 -13
  64. data/test/dummy31/db/schema.rb +0 -25
  65. data/test/dummy31/db/seeds.rb +0 -7
@@ -1,34 +1,40 @@
1
- var Gmaps4Rails = {
2
-
3
- //map config
4
- map: null, // contains the map we're working on
5
- visibleInfoWindow: null, //contains the current opened infowindow
6
- userLocation: null, //contains user's location if geolocalization was performed and successful
1
+ var Gmaps = {mapsToLoad: []};
7
2
 
8
- //empty slots
9
- geolocationFailure: function() { return false;}, //triggered when geolocation fails. If customized, must be like: function(navigator_handles_geolocation){} where 'navigator_handles_geolocation' is a boolean
10
- callback: function() { return false;}, //to let user set a custom callback function
11
- customClusterer: function() { return null;}, //to let user set custom clusterer pictures
12
- infobox: function() { return null;}, //to let user use custom infoboxes
3
+ Gmaps.loadMaps = function(){
4
+ for (var i = 0; i < Gmaps.mapsToLoad.length; ++i) {
5
+ window[Gmaps.mapsToLoad[i]]();
6
+ }
7
+ };
13
8
 
9
+ function Gmaps4Rails() {
14
10
 
11
+ //map config
12
+ this.map = null; // contains the map we're working on
13
+ this.visibleInfoWindow = null; //contains the current opened infowindow
14
+ this.userLocation = null; //contains user's location if geolocalization was performed and successful
15
+
16
+ //empty slots
17
+ this.geolocationFailure = function() { return false;} //triggered when geolocation fails. If customized, must be like= function(navigator_handles_geolocation){} where 'navigator_handles_geolocation' is a boolean
18
+ this.callback = function() { return false;} //to let user set a custom callback function
19
+ this.customClusterer = function() { return null;} //to let user set custom clusterer pictures
20
+ this.infobox = function() { return null;} //to let user use custom infoboxes
15
21
 
16
- map_options: {
17
- id: 'gmaps4rails_map',
22
+ this.default_map_options = {
23
+ id: 'map',
18
24
  draggable: true,
19
25
  detect_location: false, // should the browser attempt to use geolocation detection features of HTML5?
20
26
  center_on_user: false, // centers map on the location detected through the browser
21
27
  center_latitude: 0,
22
28
  center_longitude: 0,
23
- zoom: 1,
29
+ zoom: 7,
24
30
  maxZoom: null,
25
31
  minZoom: null,
26
32
  auto_adjust : true, // adjust the map to the markers if set to true
27
33
  auto_zoom: true, // zoom given by auto-adjust
28
34
  bounds: [] // adjust map to these limits. Should be [{"lat": , "lng": }]
29
- },
35
+ };
30
36
 
31
- markers_conf: {
37
+ this.default_markers_conf = {
32
38
  // Marker config
33
39
  title: "",
34
40
  // MarkerImage config
@@ -37,61 +43,63 @@ var Gmaps4Rails = {
37
43
  length: 32,
38
44
  draggable: false, // how to modify: <%= gmaps( "markers" => { "data" => @object.to_gmaps4rails, "options" => { "draggable" => true }}) %>
39
45
  //clustering config
40
- do_clustering: false, // do clustering if set to true
46
+ do_clustering: true, // do clustering if set to true
41
47
  randomize: false, // Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
42
48
  max_random_distance: 100, // in meters. Each marker coordinate could be altered by this distance in a random direction
43
49
  list_container: null, // id of the ul that will host links to all markers
44
- offset: 0 //used when adding_markers to an existing map. Because new markers are concated with previous one, offset is here to prevent the existing from being re-created.
45
- },
50
+ offset: 0 //used when adding_markers to an existing map. Because new markers are concated with previous one, offset is here to prevent the existing from being re-created.
51
+ };
46
52
 
47
53
  //Stored variables
48
- markers: [], // contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker}
49
- boundsObject: null, // contains current bounds from markers, polylines etc...
50
- polygons: [], // contains raw data, array of arrays (first element could be a hash containing options)
51
- polylines: [], // contains raw data, array of arrays (first element could be a hash containing options)
52
- circles: [], // contains raw data, array of hash
53
- markerClusterer: null, // contains all marker clusterers
54
- markerImages: [],
54
+ this.markers = []; // contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker}
55
+ this.boundsObject = null; // contains current bounds from markers, polylines etc...
56
+ this.polygons = []; // contains raw data, array of arrays (first element could be a hash containing options)
57
+ this.polylines = []; // contains raw data, array of arrays (first element could be a hash containing options)
58
+ this.circles = []; // contains raw data, array of hash
59
+ this.markerClusterer = null; // contains all marker clusterers
60
+ this.markerImages = [];
55
61
 
56
62
  //initializes the map
57
- initialize: function() {
63
+ this.initialize = function() {
58
64
 
59
- this.map = Gmaps4Rails.createMap();
65
+ this.map = this.createMap();
60
66
 
61
67
  if (this.map_options.detect_location === true || this.map_options.center_on_user === true) {
62
- this.findUserLocation();
68
+ this.findUserLocation(this);
63
69
  }
64
70
  //resets sidebar if needed
65
71
  this.resetSidebarContent();
66
- },
72
+ }
67
73
 
68
- findUserLocation: function() {
74
+ // this.initialize();
75
+
76
+ this.findUserLocation = function(map_object) {
69
77
  if(navigator.geolocation) {
70
78
  //try to retrieve user's position
71
79
  navigator.geolocation.getCurrentPosition(function(position) {
72
80
  //saves the position in the userLocation variable
73
- Gmaps4Rails.userLocation = Gmaps4Rails.createLatLng(position.coords.latitude, position.coords.longitude);
81
+ map_object.userLocation = map_object.createLatLng(position.coords.latitude, position.coords.longitude);
74
82
  //change map's center to focus on user's geoloc if asked
75
- if(Gmaps4Rails.map_options.center_on_user === true) {
76
- Gmaps4Rails.centerMapOnUser();
83
+ if(map_object.map_options.center_on_user === true) {
84
+ map_object.centerMapOnUser();
77
85
  }
78
86
  },
79
87
  function() {
80
88
  //failure, but the navigator handles geolocation
81
- this.geolocationFailure(true);
89
+ map_object.geolocationFailure(true);
82
90
  });
83
91
  }
84
92
  else {
85
93
  //failure but the navigator doesn't handle geolocation
86
- this.geolocationFailure(false);
94
+ map_object.geolocationFailure(false);
87
95
  }
88
- },
96
+ }
89
97
 
90
98
  ////////////////////////////////////////////////////
91
99
  //////////////////// DIRECTIONS ////////////////////
92
100
  ////////////////////////////////////////////////////
93
101
 
94
- create_direction: function(){
102
+ this.create_direction = function(){
95
103
  var directionsDisplay = new google.maps.DirectionsRenderer();
96
104
  var directionsService = new google.maps.DirectionsService();
97
105
 
@@ -120,7 +128,7 @@ var Gmaps4Rails = {
120
128
  directionsDisplay.setDirections(response);
121
129
  }
122
130
  });
123
- },
131
+ }
124
132
 
125
133
  ////////////////////////////////////////////////////
126
134
  ///////////////////// CIRCLES //////////////////////
@@ -128,14 +136,14 @@ var Gmaps4Rails = {
128
136
 
129
137
  //Loops through all circles
130
138
  //Loops through all circles and draws them
131
- create_circles: function() {
139
+ this.create_circles = function() {
132
140
  for (var i = 0; i < this.circles.length; ++i) {
133
141
  //by convention, default style configuration could be integrated in the first element
134
142
  this.create_circle(this.circles[i]);
135
143
  }
136
- },
144
+ }
137
145
 
138
- create_circle: function(circle) {
146
+ this.create_circle = function(circle) {
139
147
  if ( i === 0 ) {
140
148
  if (this.exists(circle.strokeColor )) { this.circles_conf.strokeColor = circle.strokeColor; }
141
149
  if (this.exists(circle.strokeOpacity)) { this.circles_conf.strokeOpacity = circle.strokeOpacity; }
@@ -147,7 +155,7 @@ var Gmaps4Rails = {
147
155
  // always check if a config is given, if not, use defaults
148
156
  // NOTE: is there a cleaner way to do this? Maybe a hash merge of some sort?
149
157
  var newCircle = new google.maps.Circle({
150
- center: Gmaps4Rails.createLatLng(circle.lat, circle.lng),
158
+ center: this.createLatLng(circle.lat, circle.lng),
151
159
  strokeColor: circle.strokeColor || this.circles_conf.strokeColor,
152
160
  strokeOpacity: circle.strokeOpacity || this.circles_conf.strokeOpacity,
153
161
  strokeWeight: circle.strokeWeight || this.circles_conf.strokeWeight,
@@ -160,52 +168,52 @@ var Gmaps4Rails = {
160
168
  circle.serviceObject = newCircle;
161
169
  newCircle.setMap(this.map);
162
170
  }
163
- },
171
+ }
164
172
 
165
173
  // clear circles
166
- clear_circles: function() {
174
+ this.clear_circles = function() {
167
175
  for (var i = 0; i < this.circles.length; ++i) {
168
176
  this.clear_circle(this.circles[i]);
169
177
  }
170
- },
178
+ }
171
179
 
172
- clear_circle: function(circle) {
180
+ this.clear_circle = function(circle) {
173
181
  circle.serviceObject.setMap(null);
174
- },
182
+ }
175
183
 
176
- hide_circles: function() {
184
+ this.hide_circles = function() {
177
185
  for (var i = 0; i < this.circles.length; ++i) {
178
186
  this.hide_circle(this.circles[i]);
179
187
  }
180
- },
188
+ }
181
189
 
182
- hide_circle: function(circle) {
190
+ this.hide_circle = function(circle) {
183
191
  circle.serviceObject.setMap(null);
184
- },
192
+ }
185
193
 
186
- show_circles: function() {
194
+ this.show_circles = function() {
187
195
  for (var i = 0; i < this.circles.length; ++i) {
188
196
  this.show_circle(this.circles[i]);
189
197
  }
190
- },
198
+ }
191
199
 
192
- show_circle: function(circle) {
200
+ this.show_circle = function(circle) {
193
201
  circle.serviceObject.setMap(this.map);
194
- },
202
+ }
195
203
 
196
204
  ////////////////////////////////////////////////////
197
205
  ///////////////////// POLYGONS /////////////////////
198
206
  ////////////////////////////////////////////////////
199
207
 
200
208
  //polygons is an array of arrays. It loops.
201
- create_polygons: function(){
209
+ this.create_polygons = function(){
202
210
  for (var i = 0; i < this.polygons.length; ++i) {
203
211
  this.create_polygon(i);
204
212
  }
205
- },
213
+ }
206
214
 
207
215
  //creates a single polygon, triggered by create_polygons
208
- create_polygon: function(i){
216
+ this.create_polygon = function(i){
209
217
  var polygon_coordinates = [];
210
218
  var strokeColor;
211
219
  var strokeOpacity;
@@ -214,7 +222,7 @@ var Gmaps4Rails = {
214
222
  var fillOpacity;
215
223
  //Polygon points are in an Array, that's why looping is necessary
216
224
  for (var j = 0; j < this.polygons[i].length; ++j) {
217
- var latlng = Gmaps4Rails.createLatLng(this.polygons[i][j].lat, this.polygons[i][j].lng);
225
+ var latlng = this.createLatLng(this.polygons[i][j].lat, this.polygons[i][j].lng);
218
226
  polygon_coordinates.push(latlng);
219
227
  //first element of an Array could contain specific configuration for this particular polygon. If no config given, use default
220
228
  if (j===0) {
@@ -239,21 +247,21 @@ var Gmaps4Rails = {
239
247
  //save polygon in list
240
248
  this.polygons[i].serviceObject = new_poly;
241
249
  new_poly.setMap(this.map);
242
- },
250
+ }
243
251
 
244
252
  ////////////////////////////////////////////////////
245
253
  /////////////////// POLYLINES //////////////////////
246
254
  ////////////////////////////////////////////////////
247
255
 
248
256
  //polylines is an array of arrays. It loops.
249
- create_polylines: function(){
257
+ this.create_polylines = function(){
250
258
  for (var i = 0; i < this.polylines.length; ++i) {
251
259
  this.create_polyline(i);
252
260
  }
253
- },
261
+ }
254
262
 
255
263
  //creates a single polyline, triggered by create_polylines
256
- create_polyline: function(i) {
264
+ this.create_polyline = function(i) {
257
265
  var polyline_coordinates = [];
258
266
  var strokeColor;
259
267
  var strokeOpacity;
@@ -280,7 +288,7 @@ var Gmaps4Rails = {
280
288
  }
281
289
  //add latlng if positions provided
282
290
  if (this.exists(this.polylines[i][j].lat) && this.exists(this.polylines[i][j].lng)) {
283
- var latlng = Gmaps4Rails.createLatLng(this.polylines[i][j].lat, this.polylines[i][j].lng);
291
+ var latlng = this.createLatLng(this.polylines[i][j].lat, this.polylines[i][j].lng);
284
292
  polyline_coordinates.push(latlng);
285
293
  }
286
294
  }
@@ -296,37 +304,34 @@ var Gmaps4Rails = {
296
304
  //save polyline
297
305
  this.polylines[i].serviceObject = new_poly;
298
306
  new_poly.setMap(this.map);
299
- },
307
+ }
300
308
 
301
309
  ////////////////////////////////////////////////////
302
310
  ///////////////////// MARKERS //////////////////////
303
311
  //////////////////tests coded///////////////////////
304
312
 
305
313
  //creates, clusterizes and adjusts map
306
- create_markers: function() {
307
- this.markers_conf.offset = 0;
314
+ this.create_markers = function() {
308
315
  this.createServiceMarkersFromMarkers();
309
316
  this.clusterize();
310
317
  this.adjustMapToBounds();
311
- },
318
+ }
312
319
 
313
320
  //create google.maps Markers from data provided by user
314
- createServiceMarkersFromMarkers: function() {
321
+ this.createServiceMarkersFromMarkers = function() {
315
322
  for (var i = this.markers_conf.offset; i < this.markers.length; ++i) {
316
- //check if the marker has not already been created
317
- // if (!this.exists(this.markers[i].serviceObject && this.provider == "google")) {
318
323
  //extract options, test if value passed or use default
319
324
  var Lat = this.markers[i].lat;
320
325
  var Lng = this.markers[i].lng;
321
326
 
322
327
  //alter coordinates if randomize is true
323
328
  if ( this.markers_conf.randomize) {
324
- var LatLng = Gmaps4Rails.randomize(Lat, Lng);
325
- //retrieve coordinates from the array
329
+ var LatLng = this.randomize(Lat, Lng);
330
+ //retrieve coordinates from the æarray
326
331
  Lat = LatLng[0]; Lng = LatLng[1];
327
332
  }
328
333
  //save object
329
- this.markers[i].serviceObject = Gmaps4Rails.createMarker({
334
+ this.markers[i].serviceObject = this.createMarker({
330
335
  "marker_picture": this.exists(this.markers[i].picture) ? this.markers[i].picture : this.markers_conf.picture,
331
336
  "marker_width": this.exists(this.markers[i].width) ? this.markers[i].width : this.markers_conf.width,
332
337
  "marker_height": this.exists(this.markers[i].height) ? this.markers[i].height : this.markers_conf.length,
@@ -346,47 +351,46 @@ var Gmaps4Rails = {
346
351
  this.createInfoWindow(this.markers[i]);
347
352
  //create sidebar if enabled
348
353
  this.createSidebar(this.markers[i]);
349
- // }
350
354
  }
351
355
  this.markers_conf.offset = this.markers.length;
352
- },
356
+ }
353
357
 
354
358
 
355
359
  // creates Image Anchor Position or return null if nothing passed
356
- createImageAnchorPosition: function(anchorLocation) {
360
+ this.createImageAnchorPosition = function(anchorLocation) {
357
361
  if (anchorLocation === null)
358
362
  { return null; }
359
363
  else
360
- { return Gmaps4Rails.createPoint(anchorLocation[0], anchorLocation[1]); }
361
- },
364
+ { return this.createPoint(anchorLocation[0], anchorLocation[1]); }
365
+ }
362
366
 
363
367
  // replace old markers with new markers on an existing map
364
- replaceMarkers: function(new_markers){
368
+ this.replaceMarkers = function(new_markers){
365
369
  this.clearMarkers();
366
370
  //reset previous markers
367
371
  this.markers = new Array;
368
372
  //reset current bounds
369
- this.boundsObject = Gmaps4Rails.createLatLngBounds();
373
+ this.boundsObject = this.createLatLngBounds();
370
374
  //reset sidebar content if exists
371
375
  this.resetSidebarContent();
372
376
  //add new markers
373
377
  this.addMarkers(new_markers);
374
- },
378
+ }
375
379
 
376
380
  //add new markers to on an existing map
377
- addMarkers: function(new_markers){
381
+ this.addMarkers = function(new_markers){
378
382
  //update the list of markers to take into account
379
383
  this.markers = this.markers.concat(new_markers);
380
384
  //put markers on the map
381
385
  this.create_markers();
382
- },
386
+ }
383
387
 
384
388
  ////////////////////////////////////////////////////
385
389
  ///////////////////// SIDEBAR //////////////////////
386
390
  ////////////////////////////////////////////////////
387
391
 
388
392
  //creates sidebar
389
- createSidebar: function(marker_container){
393
+ this.createSidebar = function(marker_container){
390
394
  if (this.markers_conf.list_container)
391
395
  {
392
396
  var ul = document.getElementById(this.markers_conf.list_container);
@@ -399,48 +403,53 @@ var Gmaps4Rails = {
399
403
  li.appendChild(aSel);
400
404
  ul.appendChild(li);
401
405
  }
402
- },
406
+ }
403
407
 
404
408
  //moves map to marker clicked + open infowindow
405
- sidebar_element_handler: function(marker, eventType) {
409
+ this.sidebar_element_handler = function(marker, eventType) {
406
410
  return function() {
407
- Gmaps4Rails.map.panTo(marker.position);
411
+ this.map.panTo(marker.position);
408
412
  google.maps.event.trigger(marker, eventType);
409
413
  };
410
- },
414
+ }
411
415
 
412
- resetSidebarContent: function(){
416
+ this.resetSidebarContent = function(){
413
417
  if (this.markers_conf.list_container !== null ){
414
418
  var ul = document.getElementById(this.markers_conf.list_container);
415
419
  ul.innerHTML = "";
416
420
  }
417
- },
421
+ }
418
422
 
419
423
  ////////////////////////////////////////////////////
420
424
  ////////////////// MISCELLANEOUS ///////////////////
421
425
  ////////////////////////////////////////////////////
422
426
 
423
427
  //to make the map fit the different LatLng points
424
- adjustMapToBounds: function(latlng) {
428
+ this.adjustMapToBounds = function(latlng) {
425
429
 
426
430
  //FIRST_STEP: retrieve all bounds
427
431
  //create the bounds object only if necessary
428
432
  if (this.map_options.auto_adjust || this.map_options.bounds !== null) {
429
- this.boundsObject = Gmaps4Rails.createLatLngBounds();
433
+ this.boundsObject = this.createLatLngBounds();
430
434
  }
431
435
 
432
436
  //if autodjust is true, must get bounds from markers polylines etc...
433
437
  if (this.map_options.auto_adjust) {
434
438
  //from markers
435
- Gmaps4Rails.extendBoundsWithMarkers();
436
-
437
- //from polygons:
438
- for (var i = 0; i < this.polylines.length; ++i) {
439
- this.polylines[i].serviceObject.latLngs.forEach(function(obj1){ obj1.forEach(function(obj2){ Gmaps4Rails.boundsObject.extend(obj2);} );});
440
- }
439
+ this.extendBoundsWithMarkers();
441
440
  //from polylines:
442
- for (var i = 0; i < this.polygons.length; ++i) {
443
- this.polygons[i].serviceObject.latLngs.forEach(function(obj1){ obj1.forEach(function(obj2){ Gmaps4Rails.boundsObject.extend(obj2);} );});
441
+ for (var i = 0; i < this.polylines.length; ++i) {
442
+ var polyline_points = this.polylines[i].serviceObject.latLngs.getArray()[0].getArray();
443
+ for (var j = 0; j < polyline_points.length; ++j) {
444
+ this.boundsObject.extend(polyline_points[j]);
445
+ }
446
+ }
447
+ //from polygons:
448
+ for (var i = 0; i < this.polygons.length; ++i) {
449
+ var polygon_points = this.polygons[i].serviceObject.latLngs.getArray()[0].getArray();
450
+ for (var j = 0; j < polygon_points.length; ++j) {
451
+ this.boundsObject.extend(polygon_points[j]);
452
+ }
444
453
  }
445
454
  //from circles
446
455
  for (var i = 0; i < this.circles.length; ++i) {
@@ -451,7 +460,7 @@ var Gmaps4Rails = {
451
460
  //in every case, I've to take into account the bounds set up by the user
452
461
  for (var i = 0; i < this.map_options.bounds.length; ++i) {
453
462
  //create points from bounds provided
454
- var bound = Gmaps4Rails.createLatLng(this.map_options.bounds[i].lat, this.map_options.bounds[i].lng);
463
+ var bound = this.createLatLng(this.map_options.bounds[i].lat, this.map_options.bounds[i].lng);
455
464
  this.boundsObject.extend(bound);
456
465
  }
457
466
 
@@ -466,10 +475,20 @@ var Gmaps4Rails = {
466
475
  this.map.setCenter(map_center);
467
476
  }
468
477
  else {
469
- Gmaps4Rails.fitBounds();
478
+ this.fitBounds();
470
479
  }
471
480
  }
472
- },
481
+ }
482
+
483
+ ////////////////////////////////////////////////////
484
+ ///////////////// KML //////////////////
485
+ ////////////////////////////////////////////////////
486
+
487
+ this.create_kml = function(){
488
+ for (var i = 0; i < this.kml.length; ++i) {
489
+ this.kml[i].serviceObject = this.createKmlLayer(this.kml[i]);
490
+ }
491
+ }
473
492
 
474
493
 
475
494
  ////////////////////////////////////////////////////
@@ -477,21 +496,37 @@ var Gmaps4Rails = {
477
496
  ///////////////////tests coded//////////////////////
478
497
 
479
498
  //basic function to check existence of a variable
480
- exists: function(var_name) {
499
+ this.exists = function(var_name) {
481
500
  return (var_name !== "" && typeof var_name !== "undefined");
482
- },
501
+ }
483
502
 
484
503
  //randomize
485
- randomize: function(Lat0, Lng0) {
504
+ this.randomize = function(Lat0, Lng0) {
486
505
  //distance in meters between 0 and max_random_distance (positive or negative)
487
506
  var dx = this.markers_conf.max_random_distance * this.random();
488
507
  var dy = this.markers_conf.max_random_distance * this.random();
489
508
  var Lat = parseFloat(Lat0) + (180/Math.PI)*(dy/6378137);
490
509
  var Lng = parseFloat(Lng0) + ( 90/Math.PI)*(dx/6378137)/Math.cos(Lat0);
491
510
  return [Lat, Lng];
492
- },
493
-
511
+ }
512
+
513
+ this.mergeObjectWithDefault = function(object1, object2){
514
+ var copy_object1 = object1;
515
+ for (var attrname in object2) {
516
+ if ( typeof(copy_object1[attrname]) === "undefined") {
517
+ copy_object1[attrname] = object2[attrname];
518
+ }
519
+ }
520
+ return copy_object1;
521
+ }
522
+
523
+ this.mergeWithDefault = function(objectName){
524
+ var default_object = this["default_" + objectName];
525
+ var object = this[objectName];
526
+ this[objectName] = this.mergeObjectWithDefault(object, default_object);
527
+ return true;
528
+ }
494
529
  //gives a value between -1 and 1
495
- random: function() { return(Math.random() * 2 -1); }
530
+ this.random = function() { return(Math.random() * 2 -1); }
496
531
 
497
- };
532
+ }