gmaps4rails 1.5.8 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.gitignore +12 -0
  2. data/.travis.yml +9 -0
  3. data/Gemfile +7 -0
  4. data/Gemfile.lock +149 -0
  5. data/Guardfile.old +24 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +129 -0
  8. data/Rakefile +4 -0
  9. data/app/views/gmaps4rails/_gmaps4rails.html.erb +20 -0
  10. data/gmaps4rails.gemspec +38 -0
  11. data/lib/generators/gmaps4rails/install_generator.rb +43 -0
  12. data/lib/generators/templates/README +2 -0
  13. data/lib/gmaps4rails.rb +26 -0
  14. data/lib/gmaps4rails/acts_as_gmappable.rb +54 -0
  15. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
  16. data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
  17. data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
  18. data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
  19. data/lib/gmaps4rails/base.rb +126 -0
  20. data/lib/gmaps4rails/extensions/enumerable.rb +14 -0
  21. data/lib/gmaps4rails/extensions/hash.rb +9 -0
  22. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +33 -0
  23. data/lib/gmaps4rails/js_builder.rb +154 -0
  24. data/lib/gmaps4rails/json_builder.rb +140 -0
  25. data/lib/gmaps4rails/model_handler.rb +101 -0
  26. data/lib/gmaps4rails/version.rb +3 -0
  27. data/lib/gmaps4rails/view_helper.rb +172 -0
  28. data/lib/tasks/jasmine.rake +8 -0
  29. data/public/javascripts/gmaps4rails/all.js +2144 -0
  30. data/public/javascripts/gmaps4rails/base.js +792 -0
  31. data/public/javascripts/gmaps4rails/google.js +556 -0
  32. data/public/javascripts/gmaps4rails/openlayers.js +377 -0
  33. data/public/stylesheets/gmaps4rails.css +24 -0
  34. data/spec/dummy/.gitignore +3 -0
  35. data/spec/dummy/.rspec +1 -0
  36. data/spec/dummy/README.rdoc +261 -0
  37. data/spec/dummy/Rakefile +7 -0
  38. data/spec/dummy/app/assets/javascripts/application.js +18 -0
  39. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  40. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +24 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  42. data/spec/dummy/app/controllers/users_controller.rb +105 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/spec/dummy/app/mailers/.gitkeep +0 -0
  45. data/spec/dummy/app/models/.gitkeep +0 -0
  46. data/spec/dummy/app/models/place.rb +16 -0
  47. data/spec/dummy/app/models/user.rb +12 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +17 -0
  49. data/spec/dummy/app/views/users/_form.html.erb +37 -0
  50. data/spec/dummy/app/views/users/edit.html.erb +6 -0
  51. data/spec/dummy/app/views/users/index.html.erb +268 -0
  52. data/spec/dummy/app/views/users/new.html.erb +5 -0
  53. data/spec/dummy/app/views/users/show.html.erb +30 -0
  54. data/spec/dummy/config.ru +4 -0
  55. data/spec/dummy/config/application.rb +62 -0
  56. data/spec/dummy/config/boot.rb +10 -0
  57. data/spec/dummy/config/database.yml +25 -0
  58. data/spec/dummy/config/environment.rb +5 -0
  59. data/spec/dummy/config/environments/development.rb +37 -0
  60. data/spec/dummy/config/environments/production.rb +67 -0
  61. data/spec/dummy/config/environments/test.rb +37 -0
  62. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/dummy/config/initializers/gmaps4rails.rb +1 -0
  64. data/spec/dummy/config/initializers/inflections.rb +15 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  66. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  67. data/spec/dummy/config/initializers/session_store.rb +8 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  69. data/spec/dummy/config/locales/en.yml +5 -0
  70. data/spec/dummy/config/routes.rb +60 -0
  71. data/spec/dummy/db/migrate/20120408170155_create_users.rb +16 -0
  72. data/spec/dummy/db/schema.rb +29 -0
  73. data/spec/dummy/lib/assets/.gitkeep +0 -0
  74. data/spec/dummy/log/.gitkeep +0 -0
  75. data/spec/dummy/public/404.html +26 -0
  76. data/spec/dummy/public/422.html +26 -0
  77. data/spec/dummy/public/500.html +25 -0
  78. data/spec/dummy/public/favicon.ico +0 -0
  79. data/spec/dummy/public/javascripts/Player.js +22 -0
  80. data/spec/dummy/public/javascripts/Song.js +7 -0
  81. data/spec/dummy/public/logo.png +0 -0
  82. data/spec/dummy/script/rails +6 -0
  83. data/spec/factories/place_factory.rb +16 -0
  84. data/spec/factories/user_factory.rb +23 -0
  85. data/spec/fixtures/google_direction_valid.json +65 -0
  86. data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
  87. data/spec/fixtures/google_places_valid.json +45 -0
  88. data/spec/fixtures/google_wrong_geocoding.json +4 -0
  89. data/spec/launchers/all_but_requests.rb +0 -0
  90. data/spec/launchers/all_specs.rb +0 -0
  91. data/spec/launchers/requests.rb +0 -0
  92. data/spec/lib/base_spec.rb +59 -0
  93. data/spec/lib/direction_spec.rb +53 -0
  94. data/spec/lib/geocoder_spec.rb +46 -0
  95. data/spec/lib/js_builder_spec.rb +134 -0
  96. data/spec/lib/json_builder_spec.rb +232 -0
  97. data/spec/lib/places_spec.rb +25 -0
  98. data/spec/models/place_spec.rb +39 -0
  99. data/spec/models/user_spec.rb +187 -0
  100. data/spec/spec_helper.rb +38 -0
  101. data/spec/support/geocoding.rb +40 -0
  102. data/spec/support/matchers.rb +73 -0
  103. data/todo +0 -0
  104. data/vendor/assets/javascripts/gmaps4rails/all.js +1 -0
  105. data/vendor/assets/javascripts/gmaps4rails/base.coffee +1 -0
  106. data/vendor/assets/javascripts/gmaps4rails/base/common.coffee +43 -0
  107. data/vendor/assets/javascripts/gmaps4rails/base/configuration.coffee +7 -0
  108. data/vendor/assets/javascripts/gmaps4rails/base/gmaps.coffee +13 -0
  109. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/basic_interface.coffee +15 -0
  110. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/controller_interface.coffee +15 -0
  111. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/map_interface.coffee +27 -0
  112. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/marker_interface.coffee +15 -0
  113. data/vendor/assets/javascripts/gmaps4rails/base/main.coffee +124 -0
  114. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee +29 -0
  115. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/kml_controller.coffee +5 -0
  116. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee +76 -0
  117. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee +29 -0
  118. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polyline_controller.coffee +29 -0
  119. data/vendor/assets/javascripts/gmaps4rails/base/objects/circle.coffee +12 -0
  120. data/vendor/assets/javascripts/gmaps4rails/base/objects/kml.coffee +8 -0
  121. data/vendor/assets/javascripts/gmaps4rails/base/objects/map.coffee +62 -0
  122. data/vendor/assets/javascripts/gmaps4rails/base/objects/marker.coffee +24 -0
  123. data/vendor/assets/javascripts/gmaps4rails/base/objects/polygon.coffee +11 -0
  124. data/vendor/assets/javascripts/gmaps4rails/base/objects/polyline.coffee +11 -0
  125. data/vendor/assets/javascripts/gmaps4rails/bing.coffee +1 -0
  126. data/vendor/assets/javascripts/gmaps4rails/bing/main.coffee +29 -0
  127. data/vendor/assets/javascripts/gmaps4rails/bing/objects/map.coffee +63 -0
  128. data/vendor/assets/javascripts/gmaps4rails/bing/objects/marker.coffee +78 -0
  129. data/vendor/assets/javascripts/gmaps4rails/bing/shared.coffee +20 -0
  130. data/vendor/assets/javascripts/gmaps4rails/google.coffee +1 -0
  131. data/vendor/assets/javascripts/gmaps4rails/google/main.coffee +47 -0
  132. data/vendor/assets/javascripts/gmaps4rails/google/objects/circle.coffee +38 -0
  133. data/vendor/assets/javascripts/gmaps4rails/google/objects/kml.coffee +16 -0
  134. data/vendor/assets/javascripts/gmaps4rails/google/objects/map.coffee +71 -0
  135. data/vendor/assets/javascripts/gmaps4rails/google/objects/marker.coffee +114 -0
  136. data/vendor/assets/javascripts/gmaps4rails/google/objects/polygon.coffee +38 -0
  137. data/vendor/assets/javascripts/gmaps4rails/google/objects/polyline.coffee +49 -0
  138. data/vendor/assets/javascripts/gmaps4rails/google/shared.coffee +27 -0
  139. data/vendor/assets/javascripts/gmaps4rails/openlayers.coffee +1 -0
  140. data/vendor/assets/javascripts/gmaps4rails/openlayers/main.coffee +138 -0
  141. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/map.coffee +49 -0
  142. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/marker.coffee +68 -0
  143. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/polyline.coffee +39 -0
  144. data/vendor/assets/javascripts/gmaps4rails/openlayers/shared.coffee +19 -0
  145. metadata +378 -14
  146. checksums.yaml +0 -7
@@ -0,0 +1,7 @@
1
+ @Gmaps4Rails.Configuration =
2
+
3
+ setConf: ->
4
+ if @CONF?
5
+ @mergeObjects(@CONF, @DEFAULT_CONF)
6
+ else
7
+ @DEFAULT_CONF
@@ -0,0 +1,13 @@
1
+ @Gmaps =
2
+ triggerOldOnload: ->
3
+ window.Gmaps.oldOnload() if typeof(window.Gmaps.oldOnload) == 'function'
4
+
5
+ loadMaps: ->
6
+ #loop through all variable names.
7
+ #there should only be maps inside so it trigger their load function
8
+ for key, value of window.Gmaps
9
+ #console.log key, searchLoadIncluded
10
+ if /^load_/.test(key)
11
+ #load_function_name = "load_" + key
12
+ window.Gmaps[key]()
13
+
@@ -0,0 +1,15 @@
1
+ Gmaps4Rails.Interfaces ||= {}
2
+
3
+ Gmaps4Rails.Interfaces.Basic =
4
+
5
+ clear: ()->
6
+ throw "clear should be implemented"
7
+
8
+ show: () ->
9
+ throw "show should be implemented"
10
+
11
+ hide: () ->
12
+ throw "hide should be implemented"
13
+
14
+ isVisible: ->
15
+ throw "hide should be implemented"
@@ -0,0 +1,15 @@
1
+ Gmaps4Rails.Interfaces ||= {}
2
+
3
+ Gmaps4Rails.Interfaces.Controller =
4
+
5
+ # module is the namespace of the map provider you implement, ie: Gmaps4Rails.Google
6
+ getModule: ->
7
+ throw "getModule should be implemented in controller"
8
+
9
+ # This method should create and return a clusterer object
10
+ createClusterer : (markers_array) ->
11
+ throw "createClusterer should be implemented in controller"
12
+
13
+ # this method should reset the clusterer
14
+ clearClusterer : ->
15
+ throw "clearClusterer should be implemented in controller"
@@ -0,0 +1,27 @@
1
+ Gmaps4Rails.Interfaces ||= {}
2
+
3
+ Gmaps4Rails.Interfaces.Map =
4
+
5
+ extendBoundsWithMarker : (marker) ->
6
+ throw "extendBoundsWithMarker should be implemented in controller"
7
+
8
+ extendBoundsWithPolyline: (polyline)->
9
+ throw "extendBoundsWithPolyline should be implemented in controller"
10
+
11
+ extendBoundsWithPolygon: (polygon)->
12
+ throw "extendBoundsWithPolygon should be implemented in controller"
13
+
14
+ extendBoundsWithCircle: (circle)->
15
+ throw "extendBoundsWithCircle should be implemented in controller"
16
+
17
+ extendBound: (bound)->
18
+ throw "extendBound should be implemented in controller"
19
+
20
+ adaptToBounds:()->
21
+ throw "adaptToBounds should be implemented in controller"
22
+
23
+ fitBounds : ->
24
+ throw "fitBounds should be implemented in controller"
25
+
26
+ centerMapOnUser : (position)->
27
+ throw "centerMapOnUser should be implemented in controller"
@@ -0,0 +1,15 @@
1
+ Gmaps4Rails.Interfaces ||= {}
2
+
3
+ Gmaps4Rails.Interfaces.Marker =
4
+
5
+ createInfoWindow : () ->
6
+ throw "createInfoWindow should be implemented in marker"
7
+
8
+ clear: ()->
9
+ throw "clear should be implemented in marker"
10
+
11
+ show: () ->
12
+ throw "show should be implemented in marker"
13
+
14
+ hide: () ->
15
+ throw "hide should be implemented in marker"
@@ -0,0 +1,124 @@
1
+ #= require './common'
2
+ #= require './configuration'
3
+ #= require './gmaps'
4
+
5
+ #= require_tree './objects'
6
+ #= require_tree './main_controller_extensions'
7
+ #= require_tree './interfaces'
8
+
9
+ class @Gmaps4Rails.BaseController extends Gmaps4Rails.Common
10
+
11
+ @include Gmaps4Rails.MarkerController
12
+ @include Gmaps4Rails.PolylineController
13
+ @include Gmaps4Rails.PolygonController
14
+ @include Gmaps4Rails.CircleController
15
+ @include Gmaps4Rails.KmlController
16
+
17
+ @include Gmaps4Rails.Interfaces.Controller
18
+
19
+ visibleInfoWindow: null #contains the current opened infowindow
20
+ userLocation: null #contains user's location if geolocalization was performed and successful
21
+
22
+ #empty slots
23
+ afterMapInitialization: -> false
24
+ geolocationSuccess: -> false
25
+ geolocationFailure: -> false #triggered when geolocation fails. If customized, must be like= function(navigator_handles_geolocation){} where 'navigator_handles_geolocation' is a boolean
26
+ callback: -> false #to let user set a custom callback function
27
+ customClusterer: -> false #to let user set custom clusterer pictures
28
+ infobox: -> false #to let user use custom infoboxes
29
+ jsTemplate: false #to let user create infowindows client side
30
+
31
+
32
+ #Stored variables
33
+ map_options: {} # deleted once map is created
34
+ markers: [] # contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker}
35
+ boundsObject: null # contains current bounds from markers, polylines etc...
36
+ polygons: [] # contains raw data, array of arrays (first element could be a hash containing options)
37
+ polylines: [] # contains raw data, array of arrays (first element could be a hash containing options)
38
+ circles: [] # contains raw data, array of hash
39
+ markerClusterer: null # contains all marker clusterers
40
+ markerImages: []
41
+ kmls: []
42
+ rootModule: null
43
+
44
+ constructor: ->
45
+ @rootModule = @getModule()
46
+ @markers_conf = @rootModule.Marker.setConf() if @rootModule.Marker?
47
+ @polylines_conf = @rootModule.Polyline.setConf() if @rootModule.Polyline?
48
+ @polygons_conf = @rootModule.Polygon.setConf() if @rootModule.Polygon?
49
+ @circles_conf = @rootModule.Circle.setConf() if @rootModule.Circle?
50
+
51
+ #////////////////////////////////////////////////////
52
+ #/////////////// Basic Objects //////////////
53
+ #////////////////////////////////////////////////////
54
+
55
+ createMap : ->
56
+ new @rootModule.Map(@map_options, @)
57
+
58
+ createMarker: (args)->
59
+ new @rootModule.Marker(args, @)
60
+
61
+ createPolyline: (args)->
62
+ new @rootModule.Polyline(args, @)
63
+
64
+ createPolygon: (args)->
65
+ new @rootModule.Polygon(args, @)
66
+
67
+ createCircle: (args)->
68
+ new @rootModule.Circle(args, @)
69
+
70
+ createKml: (args)->
71
+ new @rootModule.Kml(args, @)
72
+
73
+ #///////////////////////////////////
74
+ #/////////////// Map //////////////
75
+ #///////////////////////////////////
76
+
77
+ initialize : ->
78
+ detectUserLocation = @map_options.detect_location or @map_options.center_on_user
79
+ center_on_user = @map_options.center_on_user
80
+ @map = @createMap()
81
+ @afterMapInitialization()
82
+
83
+ delete @map_options
84
+
85
+ if detectUserLocation
86
+ @findUserLocation(this, center_on_user)
87
+
88
+ getMapObject: ->
89
+ @map.serviceObject
90
+
91
+ adjustMapToBounds: ->
92
+ @map.adjustToBounds() if @map.autoAdjustRequested()
93
+
94
+ #////////////////////////////////////////////////////
95
+ #/////////////// Miscellaneous //////////////
96
+ #////////////////////////////////////////////////////
97
+
98
+ clusterize : ->
99
+ if @markers_conf.do_clustering
100
+ #first clear the existing clusterer if any
101
+ @clearClusterer() if @markerClusterer?
102
+
103
+ markers_array = []
104
+ for marker in @markers
105
+ markers_array.push(marker.serviceObject)
106
+
107
+ @markerClusterer = @createClusterer(markers_array)
108
+
109
+ findUserLocation : (controller, center_on_user) ->
110
+ if navigator.geolocation
111
+ #try to retrieve user's position
112
+ positionSuccessful = (position) ->
113
+ controller.userLocation = controller.createLatLng(position.coords.latitude, position.coords.longitude)
114
+ #change map's center to focus on user's geoloc if asked
115
+ controller.geolocationSuccess()
116
+ if center_on_user
117
+ controller.map.centerMapOnUser(controller.userLocation)
118
+ positionFailure = (error)->
119
+ controller.geolocationFailure(true)
120
+
121
+ navigator.geolocation.getCurrentPosition( positionSuccessful, positionFailure)
122
+ else
123
+ #failure but the navigator doesn't handle geolocation
124
+ controller.geolocationFailure(false)
@@ -0,0 +1,29 @@
1
+ @Gmaps4Rails.CircleController =
2
+
3
+ #polygons is an array of arrays. It loops.
4
+ addCircles: (circleData)->
5
+ for circleArgs in circleData
6
+ @circles.push @createCircle(circleArgs)
7
+
8
+ replaceCircles : (circleData) ->
9
+ #reset previous polylines and kill them from map
10
+ @clearCircles()
11
+ #set new polylines
12
+ @addCircles(circleData)
13
+ #.... and adjust map boundaries
14
+ @adjustMapToBounds()
15
+
16
+ clearCircles : ->
17
+ for circle in @circles
18
+ #delete polylines from map
19
+ circle.clear()
20
+ #empty array
21
+ @circles = []
22
+
23
+ showCircles : ->
24
+ for circle in @circles
25
+ circle.show()
26
+
27
+ hideCircles : ->
28
+ for circle in @circles
29
+ circle.hide()
@@ -0,0 +1,5 @@
1
+ @Gmaps4Rails.KmlController =
2
+
3
+ addKml : (kmlData) ->
4
+ for kml in kmlData
5
+ @kmls.push @createKml kml
@@ -0,0 +1,76 @@
1
+ @Gmaps4Rails.MarkerController =
2
+
3
+ addMarkers: (markersData)->
4
+ @clearClusterer() if @markerClusterer?
5
+
6
+ for markerData, index in markersData
7
+ #unless markerData.serviceObject?
8
+
9
+ lat = markerData.lat
10
+ lng = markerData.lng
11
+
12
+ if @markers_conf.randomize
13
+ latLng = @randomize(lat, lng)
14
+ #retrieve coordinates from the array
15
+ lat = latLng[0]
16
+ lng = latLng[1]
17
+
18
+ newMarker = @createMarker
19
+ "marker_picture": if markerData.picture then markerData.picture else @markers_conf.picture
20
+ "marker_width": if markerData.width then markerData.width else @markers_conf.width
21
+ "marker_height": if markerData.height then markerData.height else @markers_conf.length
22
+ "marker_title": if markerData.title then markerData.title else null
23
+ "marker_anchor": if markerData.marker_anchor then markerData.marker_anchor else null
24
+ "shadow_anchor": if markerData.shadow_anchor then markerData.shadow_anchor else null
25
+ "shadow_picture": if markerData.shadow_picture then markerData.shadow_picture else null
26
+ "shadow_width": if markerData.shadow_width then markerData.shadow_width else null
27
+ "shadow_height": if markerData.shadow_height then markerData.shadow_height else null
28
+ "marker_draggable": if markerData.draggable then markerData.draggable else @markers_conf.draggable
29
+ "rich_marker": if markerData.rich_marker then markerData.rich_marker else null
30
+ "zindex": if markerData.zindex then markerData.zindex else null
31
+ "lat": lat
32
+ "lng": lng
33
+ "index": index
34
+
35
+
36
+ Gmaps4Rails.Common.mergeWith.call(newMarker, markerData)
37
+ #add infowindowstuff if enabled
38
+ newMarker.createInfoWindow()
39
+
40
+ @markers.push newMarker
41
+
42
+ @clusterize()
43
+
44
+ #replace old markers with new markers on an existing map
45
+ replaceMarkers : (new_markers) ->
46
+ @clearMarkers()
47
+ #reset previous markers
48
+ @markers = []
49
+ #reset current bounds
50
+ @boundsObject = @createLatLngBounds()
51
+ #add new markers
52
+ @addMarkers(new_markers)
53
+
54
+ #clear markers
55
+ clearMarkers : ->
56
+ @clearClusterer() if @markerClusterer?
57
+ for marker in @markers
58
+ marker.clear()
59
+ @markers = []
60
+
61
+ #show and hide markers
62
+ showMarkers : ->
63
+ for marker in @markers
64
+ marker.show()
65
+
66
+ hideMarkers : ->
67
+ for marker in @markers
68
+ marker.hide()
69
+
70
+ randomize : (Lat0, Lng0) ->
71
+ #distance in meters between 0 and max_random_distance (positive or negative)
72
+ dx = @markers_conf.max_random_distance * @random()
73
+ dy = @markers_conf.max_random_distance * @random()
74
+ Lat = parseFloat(Lat0) + (180/Math.PI)*(dy/6378137)
75
+ Lng = parseFloat(Lng0) + ( 90/Math.PI)*(dx/6378137)/Math.cos(Lat0)
76
+ return [Lat, Lng]
@@ -0,0 +1,29 @@
1
+ @Gmaps4Rails.PolygonController =
2
+
3
+ #polygons is an array of arrays. It loops.
4
+ addPolygons: (polygonData)->
5
+ for polygonArgs in polygonData
6
+ @polygons.push @createPolygon(polygonArgs)
7
+
8
+ replacePolygons : (polylineData) ->
9
+ #reset previous polylines and kill them from map
10
+ @clearPolygons()
11
+ #set new polylines
12
+ @addPolygons(polylineData)
13
+ #.... and adjust map boundaries
14
+ @adjustMapToBounds()
15
+
16
+ clearPolygons : ->
17
+ for polygon in @polygons
18
+ #delete polylines from map
19
+ polygon.clear()
20
+ #empty array
21
+ @polygons = []
22
+
23
+ showPolygons : ->
24
+ for polygon in @polygons
25
+ polygon.show()
26
+
27
+ hidePolygons : ->
28
+ for polygon in @polygons
29
+ polygon.hide()
@@ -0,0 +1,29 @@
1
+ @Gmaps4Rails.PolylineController =
2
+
3
+ replacePolylines : (polylineData) ->
4
+ #reset previous polylines and kill them from map
5
+ @clearPolylines()
6
+ #set new polylines
7
+ @addPolylines(polylineData)
8
+ #.... and adjust map boundaries
9
+ @adjustMapToBounds()
10
+
11
+ clearPolylines : ->
12
+ for polyline in @polylines
13
+ #delete polylines from map
14
+ polyline.clear()
15
+ #empty array
16
+ @polylines = []
17
+
18
+ #polylines is an array of arrays. It loops.
19
+ addPolylines: (polylineData)->
20
+ for polylineArgs in polylineData
21
+ @polylines.push @createPolyline(polylineArgs)
22
+
23
+ showPolylines : ->
24
+ for polyline in @polylines
25
+ polyline.show()
26
+
27
+ hidePolylines : ->
28
+ for polyline in @polylines
29
+ polyline.hide()
@@ -0,0 +1,12 @@
1
+ @Gmaps4Rails.Circle = { }
2
+
3
+ @Gmaps4Rails.Circle.Class =
4
+
5
+ DEFAULT_CONF:
6
+ fillColor: "#00AAFF"
7
+ fillOpacity: 0.35
8
+ strokeColor: "#FFAA00"
9
+ strokeOpacity: 0.8
10
+ strokeWeight: 2
11
+ clickable: false
12
+ zIndex: null
@@ -0,0 +1,8 @@
1
+ @Gmaps4Rails.Kml = { }
2
+
3
+ @Gmaps4Rails.Kml.Instance =
4
+
5
+ DEFAULT_CONF:
6
+ clickable: true
7
+ preserveViewport: false
8
+ suppressInfoWindows: false
@@ -0,0 +1,62 @@
1
+ @Gmaps4Rails.Map =
2
+
3
+ DEFAULT_CONF:
4
+ id: 'map'
5
+ draggable: true
6
+ detect_location: false # should the browser attempt to use geolocation detection features of HTML5?
7
+ center_on_user: false # centers map on the location detected through the browser
8
+ center_latitude: 0
9
+ center_longitude: 0
10
+ zoom: 7
11
+ maxZoom: null
12
+ minZoom: null
13
+ auto_adjust : true # adjust the map to the markers if set to true
14
+ auto_zoom: true # zoom given by auto-adjust
15
+ bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }]
16
+ raw: {} # raw json to pass additional options
17
+
18
+ #to make the map fit the different LatLng points
19
+ adjustToBounds : ->
20
+ #reset previous bounds
21
+ @boundsObject = @createLatLngBounds()
22
+
23
+ #from markers
24
+ @extendBoundsWithMarkers()
25
+
26
+ #from polylines:
27
+ @extendBoundsWithPolylines()
28
+
29
+ #from polygons:
30
+ @extendBoundsWithPolygons()
31
+
32
+ #from circles
33
+ @extendBoundsWithCircles()
34
+
35
+ #in every case, I've to take into account the bounds set up by the user
36
+ @extendBoundsWithLatLng()
37
+
38
+ #SECOND_STEP: ajust the map to the bounds
39
+ @adaptToBounds()
40
+
41
+ extendBoundsWithMarkers : ->
42
+ for marker in @controller.markers
43
+ @extendBoundsWithMarker(marker) if marker.isVisible()
44
+
45
+ extendBoundsWithPolylines: ()->
46
+ for polyline in @controller.polylines
47
+ @extendBoundsWithPolyline(polyline) #if polyline.isVisible()
48
+
49
+ extendBoundsWithPolygons: ()->
50
+ for polygon in @controller.polygons
51
+ @extendBoundsWithPolygon(polygon) #if polygon.isVisible()
52
+
53
+ extendBoundsWithCircles: ()->
54
+ for circle in @controller.circles
55
+ @extendBoundsWithCircle(circle) #if circle.isVisible()
56
+
57
+ extendBoundsWithLatLng: ()->
58
+ for bound in @options.bounds
59
+ @extendBound bound
60
+
61
+ autoAdjustRequested: ->
62
+ @options.auto_adjust or @options.bounds.length > 0