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,24 @@
1
+ @Gmaps4Rails.Marker = { }
2
+
3
+ @Gmaps4Rails.Marker.Class =
4
+
5
+ DEFAULT_CONF:
6
+ #Marker config
7
+ title: null
8
+ #MarkerImage config
9
+ picture : null
10
+ width: 22
11
+ length: 32
12
+ draggable: false
13
+ #clustering config
14
+ do_clustering: false # do clustering if set to true
15
+ randomize: false # Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
16
+ max_random_distance: 100 # in meters. Each marker coordinate could be altered by this distance in a random direction
17
+ list_container: null # id of the ul that will host links to all markers
18
+ 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.
19
+ raw: {} # raw json to pass additional options
20
+
21
+ @Gmaps4Rails.Marker.Instance =
22
+
23
+ getMap: ->
24
+ @controller.getMapObject()
@@ -0,0 +1,11 @@
1
+ @Gmaps4Rails.Polygon = { }
2
+
3
+ @Gmaps4Rails.Polygon.Class =
4
+
5
+ DEFAULT_CONF:
6
+ strokeColor: "#FFAA00"
7
+ strokeOpacity: 0.8
8
+ strokeWeight: 2
9
+ fillColor: "#000000"
10
+ fillOpacity: 0.35
11
+ clickable: false
@@ -0,0 +1,11 @@
1
+ @Gmaps4Rails.Polyline = { }
2
+
3
+ @Gmaps4Rails.Polyline.Class =
4
+
5
+ DEFAULT_CONF:
6
+ strokeColor: "#FF0000"
7
+ strokeOpacity: 1
8
+ strokeWeight: 2
9
+ clickable: false
10
+ zIndex: null
11
+ icons: null
@@ -0,0 +1 @@
1
+ #= require './bing/main'
@@ -0,0 +1,29 @@
1
+ #= require './shared'
2
+
3
+ #= require_tree './objects'
4
+
5
+ class @Gmaps4RailsBing extends Gmaps4Rails.BaseController
6
+
7
+ @include Gmaps4Rails.Bing.Shared
8
+
9
+ constructor: ->
10
+ super
11
+
12
+
13
+ getModule: ->
14
+ Gmaps4Rails.Bing
15
+
16
+ #////////////////////////////////////////////////////
17
+ #/////////////////// Clusterer //////////////////////
18
+ #////////////////////////////////////////////////////
19
+
20
+ createClusterer: (marker_serviceObject_array)->
21
+
22
+ clearClusterer: ->
23
+
24
+ #overwriting method from base controller since it doesn't fit here
25
+ clearMarkers: ->
26
+
27
+ #////////////////////////////////////////////////////
28
+ #/////////////// Private methods ////////////////////
29
+ #////////////////////////////////////////////////////
@@ -0,0 +1,63 @@
1
+ class @Gmaps4Rails.Bing.Map extends Gmaps4Rails.Common
2
+
3
+ @include Gmaps4Rails.Interfaces.Map
4
+
5
+ @include Gmaps4Rails.Map
6
+ @include Gmaps4Rails.Bing.Shared
7
+ @include Gmaps4Rails.Configuration
8
+
9
+ CONF:
10
+ type: "road" # aerial, auto, birdseye, collinsBart, mercator, ordnanceSurvey, road
11
+
12
+ constructor:(map_options, controller) ->
13
+ @controller = controller
14
+
15
+ defaultOptions = @setConf()
16
+ @options = @mergeObjects map_options, defaultOptions
17
+
18
+ bingOptions =
19
+ credentials: @options.provider_key,
20
+ mapTypeId: @_getMapType(@options),
21
+ center: @createLatLng(@options.center_latitude, @options.center_longitude),
22
+ zoom: @options.zoom
23
+
24
+ mergedBingOptions = @mergeObjects map_options.raw, bingOptions
25
+
26
+ @serviceObject = new Microsoft.Maps.Map(document.getElementById(@options.id), mergedBingOptions)
27
+
28
+ extendBoundsWithMarkers : ->
29
+ locationsArray = []
30
+ for marker in @controller.markers
31
+ locationsArray.push(marker.serviceObject.getLocation())
32
+ @boundsObject = Microsoft.Maps.LocationRect.fromLocations(locationsArray)
33
+
34
+ extendBoundsWithPolyline: (polyline)->
35
+
36
+ extendBoundsWithPolygon: (polygon)->
37
+
38
+ extendBoundsWithCircle: (circle)->
39
+
40
+ extendBound: (bound)->
41
+
42
+ adaptToBounds: ->
43
+ @_fitBounds()
44
+
45
+ centerMapOnUser : (position)->
46
+ @serviceObject.setView({ center: position})
47
+
48
+ _fitBounds: ->
49
+ @serviceObject.setView({bounds: @boundsObject})
50
+
51
+ _getMapType: (map_options)->
52
+ switch map_options.type
53
+ when "road" then return Microsoft.Maps.MapTypeId.road
54
+ when "aerial" then return Microsoft.Maps.MapTypeId.aerial
55
+ when "auto" then return Microsoft.Maps.MapTypeId.auto
56
+ when "birdseye" then return Microsoft.Maps.MapTypeId.birdseye
57
+ when "collinsBart" then return Microsoft.Maps.MapTypeId.collinsBart
58
+ when "mercator" then return Microsoft.Maps.MapTypeId.mercator
59
+ when "ordnanceSurvey" then return Microsoft.Maps.MapTypeId.ordnanceSurvey
60
+ else return Microsoft.Maps.MapTypeId.auto
61
+
62
+
63
+
@@ -0,0 +1,78 @@
1
+ class @Gmaps4Rails.Bing.Marker extends Gmaps4Rails.Common
2
+
3
+ @include Gmaps4Rails.Interfaces.Marker
4
+
5
+ @include Gmaps4Rails.Bing.Shared
6
+ @include Gmaps4Rails.Marker.Instance
7
+ @extend Gmaps4Rails.Marker.Class
8
+ @extend Gmaps4Rails.Configuration
9
+
10
+ @CONF:
11
+ infobox: "description" #description or htmlContent
12
+
13
+ constructor: (args, controller)->
14
+ @controller = controller
15
+
16
+ markerLatLng = @createLatLng(args.lat, args.lng)
17
+ anchorLatLng = @_createImageAnchorPosition([args.lat, args.lng])
18
+
19
+ #// Marker sizes are expressed as a Size of X,Y
20
+ if args.marker_picture?
21
+ @serviceObject = new Microsoft.Maps.Pushpin(markerLatLng, {
22
+ draggable: args.marker_draggable,
23
+ anchor: anchorLatLng,
24
+ icon: args.marker_picture,
25
+ height: args.marker_height,
26
+ text: args.marker_title,
27
+ width: args.marker_width
28
+ }
29
+ );
30
+ else
31
+ @serviceObject = new Microsoft.Maps.Pushpin(markerLatLng, {
32
+ draggable: args.marker_draggable,
33
+ anchor: anchorLatLng,
34
+ text: args.marker_title
35
+ }
36
+ );
37
+
38
+ @_addToMap(@serviceObject)
39
+
40
+
41
+ #// creates infowindows
42
+ createInfoWindow: () ->
43
+ if @description?
44
+ #//create the infowindow
45
+ if @controller.markers_conf.infobox == "description"
46
+ @info_window = new Microsoft.Maps.Infobox(@serviceObject.getLocation(), { description: @description, visible: false, showCloseButton: true})
47
+ else
48
+ @info_window = new Microsoft.Maps.Infobox(@serviceObject.getLocation(), { htmlContent: @description, visible: false})
49
+
50
+ #//add the listener associated
51
+ Microsoft.Maps.Events.addHandler(@serviceObject, 'click', @_openInfoWindow(@controller, @info_window))
52
+ @_addToMap(@info_window)
53
+
54
+ #cheap integration, I admit
55
+ isVisible: ->
56
+ true
57
+
58
+ clear: ->
59
+ @_removeFromMap(@serviceObject)
60
+
61
+ show: ->
62
+ @serviceObject.setOptions({ visible: true })
63
+
64
+ hide: ->
65
+ @serviceObject.setOptions({ visible: false })
66
+
67
+ _openInfoWindow: (controller, infoWindow) ->
68
+ return ->
69
+ # Close the latest selected marker before opening the current one.
70
+ if controller.visibleInfoWindow
71
+ controller.visibleInfoWindow.setOptions({ visible: false })
72
+ infoWindow.setOptions({ visible:true })
73
+ controller.visibleInfoWindow = infoWindow
74
+
75
+ #creates Image Anchor Position or return null if nothing passed
76
+ _createImageAnchorPosition : (anchorLocation) ->
77
+ return null unless anchorLocation?
78
+ @createPoint(anchorLocation[0], anchorLocation[1])
@@ -0,0 +1,20 @@
1
+ Gmaps4Rails.Bing = {}
2
+
3
+ Gmaps4Rails.Bing.Shared =
4
+
5
+ createPoint: (lat, lng) ->
6
+ new Microsoft.Maps.Point(lat, lng)
7
+
8
+ createLatLng:(lat, lng) ->
9
+ new Microsoft.Maps.Location(lat, lng)
10
+
11
+ createLatLngBounds: ->
12
+
13
+ createSize: (width, height) ->
14
+ new google.maps.Size(width, height)
15
+
16
+ _addToMap: (object)->
17
+ @controller.getMapObject().entities.push(object)
18
+
19
+ _removeFromMap: (object)->
20
+ @controller.getMapObject().entities.remove(object)
@@ -0,0 +1 @@
1
+ #= require './google/main'
@@ -0,0 +1,47 @@
1
+ #= require './shared'
2
+
3
+ #= require_tree './objects'
4
+
5
+ #######################################################################################################
6
+ ############################################## Google maps ##########################################
7
+ #######################################################################################################
8
+
9
+ class @Gmaps4RailsGoogle extends Gmaps4Rails.BaseController
10
+
11
+ @include Gmaps4Rails.Google.Shared
12
+
13
+ getModule: ->
14
+ Gmaps4Rails.Google
15
+
16
+ constructor: ->
17
+ super
18
+ @markerImages = []
19
+
20
+ #////////////////////////////////////////////////////
21
+ #/////////////////// Clusterer //////////////////////
22
+ #////////////////////////////////////////////////////
23
+
24
+ createClusterer : (markers_array) ->
25
+ new MarkerClusterer( @getMapObject(), markers_array, { maxZoom: @markers_conf.clusterer_maxZoom, gridSize: @markers_conf.clusterer_gridSize, styles: @customClusterer() })
26
+
27
+ clearClusterer : ->
28
+ @markerClusterer.clearMarkers()
29
+
30
+ #creates clusters
31
+ clusterize : ->
32
+ if @markers_conf.do_clustering
33
+ #first clear the existing clusterer if any
34
+ @clearClusterer() if @markerClusterer?
35
+
36
+ markers_array = []
37
+ for marker in @markers
38
+ markers_array.push(marker.serviceObject)
39
+
40
+ @markerClusterer = @createClusterer(markers_array)
41
+
42
+ _closeVisibleInfoWindow: ->
43
+ @visibleInfowindow.close() if @visibleInfowindow?
44
+
45
+ _setVisibleInfoWindow: (infowindow)->
46
+ @visibleInfowindow = infowindow
47
+
@@ -0,0 +1,38 @@
1
+ class @Gmaps4Rails.Google.Circle extends Gmaps4Rails.Common
2
+
3
+ @include Gmaps4Rails.Interfaces.Basic
4
+
5
+ @include Gmaps4Rails.Google.Shared
6
+ @extend Gmaps4Rails.Circle.Class
7
+ @extend Gmaps4Rails.Configuration
8
+
9
+ #creates a single polyline, triggered by create_polylines
10
+ constructor : (circle, controller) ->
11
+ @controller = controller
12
+
13
+ #by convention, default style configuration could be integrated in the first element
14
+ if circle == @controller.circles[0]
15
+ @controller.circles_conf.strokeColor = circle.strokeColor if circle.strokeColor?
16
+ @controller.circles_conf.strokeOpacity = circle.strokeOpacity if circle.strokeOpacity?
17
+ @controller.circles_conf.strokeWeight = circle.strokeWeight if circle.strokeWeight?
18
+ @controller.circles_conf.fillColor = circle.fillColor if circle.fillColor?
19
+ @controller.circles_conf.fillOpacity = circle.fillOpacity if circle.fillOpacity?
20
+
21
+ if circle.lat? and circle.lng?
22
+ # always check if a config is given, if not, use defaults
23
+ # NOTE: is there a cleaner way to do this? Maybe a hash merge of some sort?
24
+ circleOptions =
25
+ center: @createLatLng(circle.lat, circle.lng)
26
+ strokeColor: circle.strokeColor || @controller.circles_conf.strokeColor
27
+ strokeOpacity: circle.strokeOpacity || @controller.circles_conf.strokeOpacity
28
+ strokeWeight: circle.strokeWeight || @controller.circles_conf.strokeWeight
29
+ fillOpacity: circle.fillOpacity || @controller.circles_conf.fillOpacity
30
+ fillColor: circle.fillColor || @controller.circles_conf.fillColor
31
+ clickable: circle.clickable || @controller.circles_conf.clickable
32
+ zIndex: circle.zIndex || @controller.circles_conf.zIndex
33
+ radius: circle.radius
34
+
35
+ mergedOptions = @mergeObjects @controller.circles_conf.raw, circleOptions
36
+
37
+ @serviceObject = new google.maps.Circle mergedOptions
38
+ @serviceObject.setMap @controller.getMapObject()
@@ -0,0 +1,16 @@
1
+ class @Gmaps4Rails.Google.Kml extends Gmaps4Rails.Common
2
+
3
+ @include Gmaps4Rails.Interfaces.Basic
4
+
5
+ @include Gmaps4Rails.Google.Shared
6
+ @include Gmaps4Rails.Kml.Instance
7
+
8
+ #creates a single polyline, triggered by create_polylines
9
+ constructor : (kmlData, controller) ->
10
+ @controller = controller
11
+
12
+ @options = kmlData.options || {}
13
+ @options = @mergeObjects(@options, @DEFAULT_CONF)
14
+ kml = new google.maps.KmlLayer( kmlData.url, @options)
15
+ kml.setMap @controller.getMapObject()
16
+ @serviceObject = kml
@@ -0,0 +1,71 @@
1
+ class Gmaps4Rails.Google.Map extends Gmaps4Rails.Common
2
+
3
+ @include Gmaps4Rails.Interfaces.Map
4
+
5
+ @include Gmaps4Rails.Map
6
+ @include Gmaps4Rails.Google.Shared
7
+ @include Gmaps4Rails.Configuration
8
+
9
+ CONF:
10
+ disableDefaultUI: false
11
+ disableDoubleClickZoom: false
12
+ type: "ROADMAP" # HYBRID, ROADMAP, SATELLITE, TERRAIN
13
+ mapTypeControl: null
14
+
15
+ constructor:(map_options, controller) ->
16
+ @controller = controller
17
+
18
+ defaultOptions = @setConf()
19
+ @options = @mergeObjects map_options, defaultOptions
20
+
21
+ googleOptions =
22
+ maxZoom: @options.maxZoom
23
+ minZoom: @options.minZoom
24
+ zoom: @options.zoom
25
+ center: @createLatLng(@options.center_latitude, @options.center_longitude)
26
+ mapTypeId: google.maps.MapTypeId[@options.type]
27
+ mapTypeControl: @options.mapTypeControl
28
+ disableDefaultUI: @options.disableDefaultUI
29
+ disableDoubleClickZoom: @options.disableDoubleClickZoom
30
+ draggable: @options.draggable
31
+
32
+ mergedGoogleOptions = @mergeObjects map_options.raw, googleOptions
33
+
34
+ @serviceObject = new google.maps.Map document.getElementById(@options.id), mergedGoogleOptions
35
+
36
+ extendBoundsWithMarker : (marker) ->
37
+ @boundsObject.extend(marker.serviceObject.position)
38
+
39
+ extendBoundsWithPolyline: (polyline)->
40
+ polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray()
41
+ for point in polyline_points
42
+ @boundsObject.extend point
43
+
44
+ extendBoundsWithPolygon: (polygon)->
45
+ polygon_points = polygon.serviceObject.latLngs.getArray()[0].getArray()
46
+ for point in polygon_points
47
+ @boundsObject.extend point
48
+
49
+ extendBoundsWithCircle: (circle)->
50
+ @boundsObject.extend(circle.serviceObject.getBounds().getNorthEast())
51
+ @boundsObject.extend(circle.serviceObject.getBounds().getSouthWest())
52
+
53
+ extendBound: (bound)->
54
+ #create points from bounds provided
55
+ @boundsObject.extend @createLatLng(bound.lat, bound.lng)
56
+
57
+ adaptToBounds:()->
58
+ #if autozoom is false, take user info into account
59
+ unless @options.auto_zoom
60
+ map_center = @boundsObject.getCenter()
61
+ @options.center_latitude = map_center.lat()
62
+ @options.center_longitude = map_center.lng()
63
+ @serviceObject.setCenter(map_center)
64
+ else
65
+ @fitBounds()
66
+
67
+ fitBounds : ->
68
+ @serviceObject.fitBounds(@boundsObject) unless @boundsObject.isEmpty()
69
+
70
+ centerMapOnUser : (position)->
71
+ @serviceObject.setCenter(position)
@@ -0,0 +1,114 @@
1
+ class Gmaps4Rails.Google.Marker extends Gmaps4Rails.Common
2
+
3
+ @include Gmaps4Rails.Interfaces.Marker
4
+
5
+ @include Gmaps4Rails.Google.Shared
6
+ @include Gmaps4Rails.Marker.Instance
7
+ @extend Gmaps4Rails.Marker.Class
8
+ @extend Gmaps4Rails.Configuration
9
+
10
+ @CONF:
11
+ clusterer_gridSize: 50
12
+ clusterer_maxZoom: 5
13
+ custom_cluster_pictures: null
14
+ custom_infowindow_class: null
15
+ raw: {}
16
+
17
+ constructor: (args, controller)->
18
+ @controller = controller
19
+
20
+ markerLatLng = @createLatLng(args.lat, args.lng)
21
+ #Marker sizes are expressed as a Size of X,Y
22
+ if @_isBasicMarker(args)
23
+ @_createBasicMarker(markerLatLng, args)
24
+
25
+ else
26
+ if args.rich_marker?
27
+ @_createRichMarker(markerLatLng, args)
28
+ else
29
+ @_createMarker(markerLatLng, args)
30
+
31
+ #// creates infowindows
32
+ createInfoWindow : () ->
33
+ if typeof(@controller.jsTemplate) == "function" or @description?
34
+ @description = @controller.jsTemplate(@) if typeof(@controller.jsTemplate) == "function"
35
+ if @controller.markers_conf.custom_infowindow_class?
36
+ #creating custom infowindow
37
+ boxText = document.createElement("div")
38
+ boxText.setAttribute("class", @controller.markers_conf.custom_infowindow_class) #to customize
39
+ boxText.innerHTML = @description
40
+ @infowindow = new InfoBox(@infobox(boxText))
41
+ google.maps.event.addListener(@serviceObject, 'click', @_openInfowindow())
42
+ else
43
+ #create default infowindow
44
+ @infowindow = new google.maps.InfoWindow({content: @description })
45
+ #add the listener associated
46
+ google.maps.event.addListener(@serviceObject, 'click', @_openInfowindow())
47
+
48
+ _createBasicMarker:(markerLatLng, args)->
49
+ defaultOptions = {position: markerLatLng, map: @getMap(), title: args.marker_title, draggable: args.marker_draggable, zIndex: args.zindex}
50
+ mergedOptions = @mergeObjects @controller.markers_conf.raw, defaultOptions
51
+ @serviceObject = new google.maps.Marker mergedOptions
52
+
53
+ _createRichMarker: (markerLatLng, args)->
54
+ @serviceObject = new RichMarker({
55
+ position: markerLatLng
56
+ map: @getMap()
57
+ draggable: args.marker_draggable
58
+ content: args.rich_marker
59
+ flat: if args.marker_anchor? ? args.marker_anchor[1] else false
60
+ anchor: if args.marker_anchor? ? args.marker_anchor[0] else null
61
+ zIndex: args.zindex
62
+ })
63
+
64
+ _createMarker: (markerLatLng, args)->
65
+ #calculate MarkerImage anchor location
66
+ imageAnchorPosition = @_createImageAnchorPosition args.marker_anchor
67
+ shadowAnchorPosition = @_createImageAnchorPosition args.shadow_anchor
68
+ #create or retrieve existing MarkerImages
69
+ markerImage = @_createOrRetrieveImage(args.marker_picture, args.marker_width, args.marker_height, imageAnchorPosition)
70
+ shadowImage = @_createOrRetrieveImage(args.shadow_picture, args.shadow_width, args.shadow_height, shadowAnchorPosition)
71
+ defaultOptions = {position: markerLatLng, map: @getMap(), icon: markerImage, title: args.marker_title, draggable: args.marker_draggable, shadow: shadowImage, zIndex: args.zindex}
72
+ mergedOptions = @mergeObjects @controller.markers_conf.raw, defaultOptions
73
+ @serviceObject = new google.maps.Marker mergedOptions
74
+
75
+ #checks if obj is included in arr Array and returns the position or false
76
+ _includeMarkerImage : (obj) ->
77
+ for object, index in @controller.markerImages
78
+ return index if object.url == obj
79
+ return false
80
+
81
+ #checks if MarkerImage exists before creating a new one
82
+ #returns a MarkerImage or false if ever something wrong is passed as argument
83
+ _createOrRetrieveImage : (currentMarkerPicture, markerWidth, markerHeight, imageAnchorPosition) ->
84
+ return null if (typeof(currentMarkerPicture) == "undefined" or currentMarkerPicture == "" or currentMarkerPicture == null )
85
+
86
+ if !(test_image_index = @_includeMarkerImage(currentMarkerPicture))
87
+ markerImage = @_createMarkerImage(currentMarkerPicture, @createSize(markerWidth, markerHeight), null, imageAnchorPosition, null )
88
+ @controller.markerImages.push(markerImage)
89
+ return markerImage
90
+ else
91
+ return @controller.markerImages[test_image_index] if typeof test_image_index == 'number'
92
+ return false
93
+
94
+ _isBasicMarker: (args)->
95
+ !args.marker_picture? and !args.rich_marker?
96
+
97
+ _createMarkerImage : (markerPicture, markerSize, origin, anchor, scaledSize) ->
98
+ new google.maps.MarkerImage(markerPicture, markerSize, origin, anchor, scaledSize)
99
+
100
+ #creates Image Anchor Position or return null if nothing passed
101
+ _createImageAnchorPosition : (anchorLocation) ->
102
+ if (anchorLocation == null)
103
+ return null
104
+ else
105
+ return @createPoint(anchorLocation[0], anchorLocation[1])
106
+
107
+ _openInfowindow : () ->
108
+ that = @
109
+ return ->
110
+ # Close the latest selected marker before opening the current one.
111
+ that.controller._closeVisibleInfoWindow()
112
+ that.infowindow.open(that.getMap(), that.serviceObject)
113
+ that.controller._setVisibleInfoWindow that.infowindow
114
+