gmaps4rails 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. metadata +6 -386
  3. data/.gitignore +0 -17
  4. data/.travis.yml +0 -10
  5. data/Gemfile +0 -9
  6. data/Gemfile.lock +0 -182
  7. data/Guardfile +0 -24
  8. data/MIT-LICENSE +0 -20
  9. data/README.rdoc +0 -135
  10. data/Rakefile +0 -4
  11. data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +0 -444
  12. data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +0 -174
  13. data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +0 -339
  14. data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +0 -145
  15. data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +0 -261
  16. data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
  17. data/gmaps4rails.gemspec +0 -39
  18. data/lib/generators/gmaps4rails/install_generator.rb +0 -48
  19. data/lib/generators/templates/README +0 -2
  20. data/lib/gmaps4rails.rb +0 -26
  21. data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
  22. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
  23. data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
  24. data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
  25. data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
  26. data/lib/gmaps4rails/base.rb +0 -119
  27. data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
  28. data/lib/gmaps4rails/extensions/hash.rb +0 -9
  29. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
  30. data/lib/gmaps4rails/js_builder.rb +0 -157
  31. data/lib/gmaps4rails/json_builder.rb +0 -140
  32. data/lib/gmaps4rails/model_handler.rb +0 -101
  33. data/lib/gmaps4rails/version.rb +0 -3
  34. data/lib/gmaps4rails/view_helper.rb +0 -175
  35. data/lib/tasks/gmaps4rails_tasks.rake +0 -4
  36. data/lib/tasks/jasmine.rake +0 -8
  37. data/public/javascripts/gmaps4rails/gmaps4rails.base.js +0 -464
  38. data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +0 -226
  39. data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +0 -430
  40. data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +0 -178
  41. data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +0 -265
  42. data/public/stylesheets/gmaps4rails.css +0 -24
  43. data/spec/dummy/.gitignore +0 -2
  44. data/spec/dummy/.rspec +0 -1
  45. data/spec/dummy/README.rdoc +0 -261
  46. data/spec/dummy/Rakefile +0 -7
  47. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  48. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  49. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
  50. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  51. data/spec/dummy/app/controllers/users_controller.rb +0 -101
  52. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  53. data/spec/dummy/app/mailers/.gitkeep +0 -0
  54. data/spec/dummy/app/models/.gitkeep +0 -0
  55. data/spec/dummy/app/models/place.rb +0 -16
  56. data/spec/dummy/app/models/user.rb +0 -12
  57. data/spec/dummy/app/views/layouts/application.html.erb +0 -16
  58. data/spec/dummy/app/views/users/_form.html.erb +0 -37
  59. data/spec/dummy/app/views/users/_map.html.erb +0 -5
  60. data/spec/dummy/app/views/users/edit.html.erb +0 -6
  61. data/spec/dummy/app/views/users/index.html.erb +0 -260
  62. data/spec/dummy/app/views/users/new.html.erb +0 -5
  63. data/spec/dummy/app/views/users/show.html.erb +0 -30
  64. data/spec/dummy/config.ru +0 -4
  65. data/spec/dummy/config/application.rb +0 -62
  66. data/spec/dummy/config/boot.rb +0 -10
  67. data/spec/dummy/config/database.yml +0 -25
  68. data/spec/dummy/config/environment.rb +0 -5
  69. data/spec/dummy/config/environments/development.rb +0 -37
  70. data/spec/dummy/config/environments/production.rb +0 -67
  71. data/spec/dummy/config/environments/test.rb +0 -37
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  73. data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
  74. data/spec/dummy/config/initializers/inflections.rb +0 -15
  75. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  76. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  77. data/spec/dummy/config/initializers/session_store.rb +0 -8
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  79. data/spec/dummy/config/locales/en.yml +0 -5
  80. data/spec/dummy/config/routes.rb +0 -60
  81. data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
  82. data/spec/dummy/db/schema.rb +0 -29
  83. data/spec/dummy/lib/assets/.gitkeep +0 -0
  84. data/spec/dummy/log/.gitkeep +0 -0
  85. data/spec/dummy/public/404.html +0 -26
  86. data/spec/dummy/public/422.html +0 -26
  87. data/spec/dummy/public/500.html +0 -25
  88. data/spec/dummy/public/favicon.ico +0 -0
  89. data/spec/dummy/public/javascripts/Player.js +0 -22
  90. data/spec/dummy/public/javascripts/Song.js +0 -7
  91. data/spec/dummy/public/logo.png +0 -0
  92. data/spec/dummy/script/rails +0 -6
  93. data/spec/factories/place_factory.rb +0 -16
  94. data/spec/factories/user_factory.rb +0 -23
  95. data/spec/fixtures/google_direction_valid.json +0 -65
  96. data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
  97. data/spec/fixtures/google_places_valid.json +0 -45
  98. data/spec/fixtures/google_wrong_geocoding.json +0 -4
  99. data/spec/javascripts/basic_methods_spec.js +0 -103
  100. data/spec/javascripts/helpers/.gitkeep +0 -0
  101. data/spec/javascripts/helpers/SpecHelper.js +0 -87
  102. data/spec/javascripts/map_spec.js +0 -49
  103. data/spec/javascripts/markers_methods_spec.js +0 -368
  104. data/spec/javascripts/mocks_spec.js +0 -27
  105. data/spec/javascripts/support/jasmine.yml +0 -10
  106. data/spec/javascripts/support/jasmine_config.rb +0 -23
  107. data/spec/javascripts/support/jasmine_runner.rb +0 -20
  108. data/spec/launchers/all_but_requests.rb +0 -0
  109. data/spec/launchers/all_specs.rb +0 -0
  110. data/spec/launchers/requests.rb +0 -0
  111. data/spec/lib/base_spec.rb +0 -59
  112. data/spec/lib/direction_spec.rb +0 -53
  113. data/spec/lib/geocoder_spec.rb +0 -46
  114. data/spec/lib/js_builder_spec.rb +0 -139
  115. data/spec/lib/json_builder_spec.rb +0 -232
  116. data/spec/lib/places_spec.rb +0 -25
  117. data/spec/models/place_spec.rb +0 -35
  118. data/spec/models/user_spec.rb +0 -187
  119. data/spec/spec_helper.rb +0 -44
  120. data/spec/support/geocoding.rb +0 -41
  121. data/spec/support/matchers.rb +0 -73
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Declare your gem's dependencies in gmaps4rails.gemspec.
4
- # Bundler will treat runtime dependencies like base dependencies, and
5
- # development dependencies will be added by default to the :development group.
6
-
7
- gemspec
8
-
9
- #gem 'growl'
@@ -1,182 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- gmaps4rails (1.5.7)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- actionmailer (3.2.3)
10
- actionpack (= 3.2.3)
11
- mail (~> 2.4.4)
12
- actionpack (3.2.3)
13
- activemodel (= 3.2.3)
14
- activesupport (= 3.2.3)
15
- builder (~> 3.0.0)
16
- erubis (~> 2.7.0)
17
- journey (~> 1.0.1)
18
- rack (~> 1.4.0)
19
- rack-cache (~> 1.2)
20
- rack-test (~> 0.6.1)
21
- sprockets (~> 2.1.2)
22
- activemodel (3.2.3)
23
- activesupport (= 3.2.3)
24
- builder (~> 3.0.0)
25
- activerecord (3.2.3)
26
- activemodel (= 3.2.3)
27
- activesupport (= 3.2.3)
28
- arel (~> 3.0.2)
29
- tzinfo (~> 0.3.29)
30
- activeresource (3.2.3)
31
- activemodel (= 3.2.3)
32
- activesupport (= 3.2.3)
33
- activesupport (3.2.3)
34
- i18n (~> 0.6)
35
- multi_json (~> 1.0)
36
- addressable (2.2.8)
37
- arel (3.0.2)
38
- builder (3.0.0)
39
- childprocess (0.3.1)
40
- ffi (~> 1.0.6)
41
- coderay (1.0.6)
42
- coffee-script (2.2.0)
43
- coffee-script-source
44
- execjs
45
- coffee-script-source (1.2.0)
46
- crack (0.3.1)
47
- database_cleaner (0.7.2)
48
- diff-lcs (1.1.3)
49
- erubis (2.7.0)
50
- execjs (1.3.0)
51
- multi_json (~> 1.0)
52
- factory_girl (2.6.1)
53
- activesupport (>= 2.3.9)
54
- factory_girl_rails (1.7.0)
55
- factory_girl (~> 2.6.0)
56
- railties (>= 3.0.0)
57
- ffi (1.0.11)
58
- guard (1.0.1)
59
- ffi (>= 0.5.0)
60
- thor (~> 0.14.6)
61
- guard-coffeescript (0.5.7)
62
- coffee-script (>= 2.2.0)
63
- guard (>= 0.8.3)
64
- guard-jasmine (1.1.0)
65
- childprocess
66
- guard (>= 0.8.3)
67
- multi_json
68
- thor
69
- guard-rspec (0.5.11)
70
- guard (>= 0.8.4)
71
- guard-spork (0.4.1)
72
- guard (>= 0.8.4)
73
- spork (>= 0.8.4)
74
- hike (1.2.1)
75
- i18n (0.6.0)
76
- jasmine (1.1.2)
77
- jasmine-core (>= 1.1.0)
78
- rack (>= 1.1)
79
- rspec (>= 1.3.1)
80
- selenium-webdriver (>= 0.1.3)
81
- jasmine-core (1.1.0)
82
- journey (1.0.3)
83
- jquery-rails (2.0.2)
84
- railties (>= 3.2.0, < 5.0)
85
- thor (~> 0.14)
86
- json (1.6.6)
87
- json_pure (1.6.5)
88
- mail (2.4.4)
89
- i18n (>= 0.4.0)
90
- mime-types (~> 1.16)
91
- treetop (~> 1.4.8)
92
- method_source (0.7.1)
93
- mime-types (1.18)
94
- multi_json (1.2.0)
95
- polyglot (0.3.3)
96
- pry (0.9.8.4)
97
- coderay (~> 1.0.5)
98
- method_source (~> 0.7.1)
99
- slop (>= 2.4.4, < 3)
100
- rack (1.4.1)
101
- rack-cache (1.2)
102
- rack (>= 0.4)
103
- rack-ssl (1.3.2)
104
- rack
105
- rack-test (0.6.1)
106
- rack (>= 1.0)
107
- rails (3.2.3)
108
- actionmailer (= 3.2.3)
109
- actionpack (= 3.2.3)
110
- activerecord (= 3.2.3)
111
- activeresource (= 3.2.3)
112
- activesupport (= 3.2.3)
113
- bundler (~> 1.0)
114
- railties (= 3.2.3)
115
- railties (3.2.3)
116
- actionpack (= 3.2.3)
117
- activesupport (= 3.2.3)
118
- rack-ssl (~> 1.3.2)
119
- rake (>= 0.8.7)
120
- rdoc (~> 3.4)
121
- thor (~> 0.14.6)
122
- rake (0.9.2.2)
123
- rdoc (3.12)
124
- json (~> 1.4)
125
- rspec (2.8.0)
126
- rspec-core (~> 2.8.0)
127
- rspec-expectations (~> 2.8.0)
128
- rspec-mocks (~> 2.8.0)
129
- rspec-core (2.8.0)
130
- rspec-expectations (2.8.0)
131
- diff-lcs (~> 1.1.2)
132
- rspec-mocks (2.8.0)
133
- rspec-rails (2.8.1)
134
- actionpack (>= 3.0)
135
- activesupport (>= 3.0)
136
- railties (>= 3.0)
137
- rspec (~> 2.8.0)
138
- rubyzip (0.9.6.1)
139
- selenium-webdriver (2.5.0)
140
- childprocess (>= 0.2.1)
141
- ffi (>= 1.0.7)
142
- json_pure
143
- rubyzip
144
- slop (2.4.4)
145
- spork (1.0.0rc2)
146
- sprockets (2.1.2)
147
- hike (~> 1.2)
148
- rack (~> 1.0)
149
- tilt (~> 1.1, != 1.3.0)
150
- sqlite3 (1.3.5)
151
- thor (0.14.6)
152
- tilt (1.3.3)
153
- treetop (1.4.10)
154
- polyglot
155
- polyglot (>= 0.3.1)
156
- tzinfo (0.3.32)
157
- webmock (1.8.7)
158
- addressable (>= 2.2.7)
159
- crack (>= 0.1.7)
160
-
161
- PLATFORMS
162
- ruby
163
-
164
- DEPENDENCIES
165
- database_cleaner
166
- factory_girl_rails
167
- gmaps4rails!
168
- guard (~> 1.0.1)
169
- guard-coffeescript
170
- guard-jasmine
171
- guard-rspec
172
- guard-spork
173
- jasmine
174
- jquery-rails
175
- pry
176
- rails (~> 3.2.1)
177
- rspec-rails
178
- sqlite3
179
- webmock
180
-
181
- BUNDLED WITH
182
- 1.12.0.rc.4
data/Guardfile DELETED
@@ -1,24 +0,0 @@
1
- guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
2
- watch('config/application.rb')
3
- watch('config/environment.rb')
4
- watch(%r{^config/environments/.+\.rb$})
5
- watch(%r{^config/initializers/.+\.rb$})
6
- watch('Gemfile')
7
- watch('Gemfile.lock')
8
- watch('spec/spec_helper.rb') { :rspec }
9
- end
10
-
11
- guard 'rspec', :cli => "-c -f d", :all_on_start => false, :all_after_pass => false do
12
- watch(%r{^spec/.+_spec\.rb$})
13
- watch('spec/launchers/all_specs.rb') { "spec" }
14
- watch('spec/launchers/all_but_requests.rb') { ["spec/base", "spec/helpers", "spec/models", "spec/views", "spec/javascripts"] }
15
- watch('spec/launchers/requests.rb') { "spec/requests" }
16
- end
17
-
18
- guard 'jasmine', :jasmine_url => 'http://localhost:8888/', :all_on_start => false, :all_after_pass => false do
19
- watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
20
- watch(%r{^spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
21
- watch(%r{^spec/javascripts/.+_spec\.js$}) { "spec/javascripts" }
22
- end
23
-
24
- guard 'coffeescript', :input => 'app/assets/javascripts/gmaps4rails', :output => 'public/javascripts/gmaps4rails'
@@ -1,20 +0,0 @@
1
- Copyright 2012 Benjamin Roth
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,135 +0,0 @@
1
- == Google Maps for Rails (gmaps4rails) {<img src="https://secure.travis-ci.org/apneadiving/Google-Maps-for-Rails.png?branch=master" alt="Build Status" />}[http://travis-ci.org/apneadiving/Google-Maps-for-Rails] {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/apneadiving/Google-Maps-for-Rails]
2
-
3
- Gmaps4rails is developed to simply create a Google Map:
4
-
5
- - directly from your model,
6
-
7
- - from your own json
8
-
9
- It's based on Ruby on Rails 3 Engines and uses Google Maps API V3.
10
-
11
- See (somewhat outdated) screencasts here: http://www.youtube.com/user/TheApneadiving
12
-
13
- == When Gmaps4rails finally means Global Maps for Rails
14
-
15
- I've added support for other map providers: openlayers, mapquest & bing.
16
-
17
- See: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Map-Apis
18
-
19
- Any help would be appreciated to complete this work.
20
-
21
- == Requirements
22
-
23
- 1) Gemfile
24
-
25
- gem 'gmaps4rails'
26
-
27
- 2) Copy the assets to your app (and be sure to copy the fresh assets when you upgrade the gem):
28
-
29
- rails generate gmaps4rails:install
30
-
31
- This will copy all the coffeescript files if you're running Rails >= 3.1 or all the js files for Rails 3.0.x.
32
-
33
- Only `gmaps4rails.base` + `gmaps4rails.your_provider` are necessary.
34
-
35
- 3) Javascript
36
-
37
- <%= yield :scripts %> (in your footer)
38
-
39
- This container will include the js files from map providers, the custom js to display the map, the gem's js code.
40
-
41
- 4) CSS
42
-
43
- `gmaps4rails.css` will be copied to your app after you run the Rails generator.
44
- Be sure to require this file in your view for your first steps.
45
-
46
- For Rails 3.0.x or without assets pipeline:
47
-
48
- <%= stylesheet_link_tag 'gmaps4rails' %>
49
-
50
- For Rails >= 3.1 with assets pipeline, same principle: add the required file to your manifest.
51
-
52
-
53
- == Basic configuration
54
- In your model, add:
55
-
56
- acts_as_gmappable
57
-
58
- def gmaps4rails_address
59
- #describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
60
- "#{self.street}, #{self.city}, #{self.country}"
61
- end
62
-
63
- Create a migration and add the following fields to your table (here users):
64
-
65
- add_column :users, :latitude, :float #you can change the name, see wiki
66
- add_column :users, :longitude, :float #you can change the name, see wiki
67
- add_column :users, :gmaps, :boolean #not mandatory, see wiki
68
-
69
- == Basic configuration: Non-relational DB
70
-
71
- Mongoid example:
72
-
73
- acts_as_gmappable :position => :location
74
-
75
- field :location, :type => Array
76
-
77
- == How to?
78
- === QuickStart!
79
- In your controller:
80
-
81
- @json = User.all.to_gmaps4rails
82
-
83
- In your view:
84
-
85
- <%= gmaps4rails(@json) %>
86
-
87
- Done!
88
-
89
- == Options
90
-
91
- * Markers with Info window, Custom Picture, RichMarkers (make your own markers with custom html)
92
-
93
- * Automatic sidebar with list of markers
94
-
95
- * Circles, Polylines, Polygons
96
-
97
- * Geocode directly your address and retrieve coordinates.
98
-
99
- * Wrapper for 'Direction', giving instructions to go from point A to point B
100
-
101
- * Auto-adjust the map to your markers
102
-
103
- * Refresh your map on the fly with Javascript (and Ajax)
104
-
105
- * KML support
106
-
107
- * Easy multimap
108
-
109
- * {More details in the Wiki}[https://github.com/apneadiving/Google-Maps-for-Rails/wiki]
110
-
111
- == Todo?
112
-
113
- Feel free to contact us, you have your say.
114
-
115
- == Want to help?
116
-
117
- This is how you can launch the spec suite (js + ruby):
118
-
119
- * Clone the gem repository
120
-
121
- * Go to the gem's folder
122
-
123
- * run `bundle`
124
-
125
- * run `cd spec/dummy; rake db:migrate RAILS_ENV=test; cd ../..`
126
-
127
- * run `bundle exec rspec spec`
128
-
129
-
130
- == Copyright
131
- MIT license.
132
-
133
- Authors: Benjamin Roth, David Ruyer
134
-
135
- {Contributors}[https://github.com/apneadiving/Google-Maps-for-Rails/graphs/contributors]
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- import 'lib/tasks/jasmine.rake'
@@ -1,444 +0,0 @@
1
- Gmaps = {}
2
-
3
- Gmaps.triggerOldOnload = ->
4
- Gmaps.oldOnload() if typeof(Gmaps.oldOnload) == 'function'
5
-
6
- Gmaps.loadMaps = ->
7
- #loop through all variable names.
8
- #there should only be maps inside so it trigger their load function
9
- for key, value of Gmaps
10
- searchLoadIncluded = key.search(/load/)
11
- if searchLoadIncluded == -1
12
- load_function_name = "load_" + key
13
- Gmaps[load_function_name]()
14
-
15
- window.Gmaps = Gmaps
16
-
17
- class @Gmaps4Rails
18
-
19
- constructor: ->
20
- #map config
21
- @map = null #DEPRECATED: will still contain a copy of serviceObject below as transition
22
- @serviceObject = null #contains the map we're working on
23
- @visibleInfoWindow = null #contains the current opened infowindow
24
- @userLocation = null #contains user's location if geolocalization was performed and successful
25
-
26
- #empty slots
27
- @geolocationSuccess = -> false #triggered when geolocation succeeds. Can be customized.
28
- @geolocationFailure = -> false #triggered when geolocation fails. If customized, must be like= function(navigator_handles_geolocation){} where 'navigator_handles_geolocation' is a boolean
29
- @callback = -> false #to let user set a custom callback function
30
- @customClusterer = -> false #to let user set custom clusterer pictures
31
- @infobox = -> false #to let user use custom infoboxes
32
- @jsTemplate = false #to let user create infowindows client side
33
-
34
- @default_map_options =
35
- id: 'map'
36
- draggable: true
37
- detect_location: false # should the browser attempt to use geolocation detection features of HTML5?
38
- center_on_user: false # centers map on the location detected through the browser
39
- center_latitude: 0
40
- center_longitude: 0
41
- zoom: 7
42
- maxZoom: null
43
- minZoom: null
44
- auto_adjust : true # adjust the map to the markers if set to true
45
- auto_zoom: true # zoom given by auto-adjust
46
- bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }]
47
- raw: {} # raw json to pass additional options
48
-
49
- @default_markers_conf =
50
- #Marker config
51
- title: ""
52
- #MarkerImage config
53
- picture : ""
54
- width: 22
55
- length: 32
56
- draggable: false # how to modify: <%= gmaps( "markers" => { "data" => @object.to_gmaps4rails, "options" => { "draggable" => true }}) %>
57
- #clustering config
58
- do_clustering: false # do clustering if set to true
59
- randomize: false # Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
60
- max_random_distance: 100 # in meters. Each marker coordinate could be altered by this distance in a random direction
61
- list_container: null # id of the ul that will host links to all markers
62
- 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.
63
- raw: {} # raw json to pass additional options
64
-
65
- #Stored variables
66
- @markers = [] # contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker}
67
- @boundsObject = null # contains current bounds from markers, polylines etc...
68
- @polygons = [] # contains raw data, array of arrays (first element could be a hash containing options)
69
- @polylines = [] # contains raw data, array of arrays (first element could be a hash containing options)
70
- @circles = [] # contains raw data, array of hash
71
- @markerClusterer = null # contains all marker clusterers
72
- @markerImages = []
73
-
74
- #Polyline Styling
75
- @polylines_conf = #default style for polylines
76
- strokeColor: "#FF0000"
77
- strokeOpacity: 1
78
- strokeWeight: 2
79
- clickable: false
80
- zIndex: null
81
-
82
- #tnitializes the map
83
- initialize : ->
84
- @serviceObject = @createMap()
85
- @map = @serviceObject #beware, soon deprecated
86
- if (@map_options.detect_location == true or @map_options.center_on_user == true)
87
- @findUserLocation(this)
88
- #resets sidebar if needed
89
- @resetSidebarContent()
90
-
91
- findUserLocation : (map_object) ->
92
- if (navigator.geolocation)
93
- #try to retrieve user's position
94
- positionSuccessful = (position) ->
95
- map_object.userLocation = map_object.createLatLng(position.coords.latitude, position.coords.longitude)
96
- #change map's center to focus on user's geoloc if asked
97
- if(map_object.map_options.center_on_user == true)
98
- map_object.centerMapOnUser()
99
- map_object.geolocationSuccess()
100
- positionFailure = ->
101
- map_object.geolocationFailure(true)
102
-
103
- navigator.geolocation.getCurrentPosition( positionSuccessful, positionFailure)
104
- else
105
- #failure but the navigator doesn't handle geolocation
106
- map_object.geolocationFailure(false)
107
-
108
-
109
- #////////////////////////////////////////////////////
110
- #//////////////////// DIRECTIONS ////////////////////
111
- #////////////////////////////////////////////////////
112
-
113
- create_direction : ->
114
- directionsDisplay = new google.maps.DirectionsRenderer()
115
- directionsService = new google.maps.DirectionsService()
116
-
117
- directionsDisplay.setMap(@serviceObject)
118
- #display panel only if required
119
- if @direction_conf.display_panel
120
- directionsDisplay.setPanel(document.getElementById(@direction_conf.panel_id))
121
-
122
- directionsDisplay.setOptions
123
- suppressMarkers: false
124
- suppressInfoWindows: false
125
- suppressPolylines: false
126
-
127
- request =
128
- origin: @direction_conf.origin
129
- destination: @direction_conf.destination
130
- waypoints: @direction_conf.waypoints
131
- optimizeWaypoints: @direction_conf.optimizeWaypoints
132
- unitSystem: google.maps.DirectionsUnitSystem[@direction_conf.unitSystem]
133
- avoidHighways: @direction_conf.avoidHighways
134
- avoidTolls: @direction_conf.avoidTolls
135
- region: @direction_conf.region
136
- travelMode: google.maps.DirectionsTravelMode[@direction_conf.travelMode]
137
- language: "en"
138
-
139
- directionsService.route request, (response, status) ->
140
- if (status == google.maps.DirectionsStatus.OK)
141
- directionsDisplay.setDirections(response)
142
-
143
- #////////////////////////////////////////////////////
144
- #///////////////////// CIRCLES //////////////////////
145
- #////////////////////////////////////////////////////
146
-
147
- #Loops through all circles
148
- #Loops through all circles and draws them
149
- create_circles : ->
150
- for circle in @circles
151
- @create_circle circle
152
-
153
- create_circle : (circle) ->
154
- #by convention, default style configuration could be integrated in the first element
155
- if circle == @circles[0]
156
- @circles_conf.strokeColor = circle.strokeColor if circle.strokeColor?
157
- @circles_conf.strokeOpacity = circle.strokeOpacity if circle.strokeOpacity?
158
- @circles_conf.strokeWeight = circle.strokeWeight if circle.strokeWeight?
159
- @circles_conf.fillColor = circle.fillColor if circle.fillColor?
160
- @circles_conf.fillOpacity = circle.fillOpacity if circle.fillOpacity?
161
-
162
- if circle.lat? and circle.lng?
163
- # always check if a config is given, if not, use defaults
164
- # NOTE: is there a cleaner way to do this? Maybe a hash merge of some sort?
165
- newCircle = new google.maps.Circle
166
- center: @createLatLng(circle.lat, circle.lng)
167
- strokeColor: circle.strokeColor || @circles_conf.strokeColor
168
- strokeOpacity: circle.strokeOpacity || @circles_conf.strokeOpacity
169
- strokeWeight: circle.strokeWeight || @circles_conf.strokeWeight
170
- fillOpacity: circle.fillOpacity || @circles_conf.fillOpacity
171
- fillColor: circle.fillColor || @circles_conf.fillColor
172
- clickable: circle.clickable || @circles_conf.clickable
173
- zIndex: circle.zIndex || @circles_conf.zIndex
174
- radius: circle.radius
175
-
176
- circle.serviceObject = newCircle
177
- newCircle.setMap(@serviceObject)
178
-
179
- # clear circles
180
- clear_circles : ->
181
- for circle in @circles
182
- @clear_circle circle
183
-
184
- clear_circle : (circle) ->
185
- circle.serviceObject.setMap(null)
186
-
187
- hide_circles : ->
188
- for circle in @circles
189
- @hide_circle circle
190
-
191
- hide_circle : (circle) ->
192
- circle.serviceObject.setMap(null)
193
-
194
- show_circles : ->
195
- for circle in @circles
196
- @show_circle @circle
197
-
198
- show_circle : (circle) ->
199
- circle.serviceObject.setMap(@serviceObject)
200
-
201
- #////////////////////////////////////////////////////
202
- #///////////////////// POLYGONS /////////////////////
203
- #////////////////////////////////////////////////////
204
-
205
- #polygons is an array of arrays. It loops.
206
- create_polygons : ->
207
- for polygon in @polygons
208
- @create_polygon(polygon)
209
-
210
- #creates a single polygon, triggered by create_polygons
211
- create_polygon : (polygon) ->
212
- polygon_coordinates = []
213
-
214
- #Polygon points are in an Array, that's why looping is necessary
215
- for point in polygon
216
- latlng = @createLatLng(point.lat, point.lng)
217
- polygon_coordinates.push(latlng)
218
- #first element of an Array could contain specific configuration for this particular polygon. If no config given, use default
219
- if point == polygon[0]
220
- strokeColor = point.strokeColor || @polygons_conf.strokeColor
221
- strokeOpacity = point.strokeOpacity || @polygons_conf.strokeOpacity
222
- strokeWeight = point.strokeWeight || @polygons_conf.strokeWeight
223
- fillColor = point.fillColor || @polygons_conf.fillColor
224
- fillOpacity = point.fillOpacity || @polygons_conf.fillOpacity
225
- clickable = point.clickable || @polygons_conf.clickable
226
-
227
- #Construct the polygon
228
- new_poly = new google.maps.Polygon
229
- paths: polygon_coordinates
230
- strokeColor: strokeColor
231
- strokeOpacity: strokeOpacity
232
- strokeWeight: strokeWeight
233
- fillColor: fillColor
234
- fillOpacity: fillOpacity
235
- clickable: clickable
236
- map: @serviceObject
237
-
238
- #save polygon in list
239
- polygon.serviceObject = new_poly
240
-
241
-
242
-
243
- #////////////////////////////////////////////////////
244
- #///////////////////// MARKERS //////////////////////
245
- #////////////////////////////////////////////////////
246
-
247
- #creates, clusterizes and adjusts map
248
- create_markers : ->
249
- @createServiceMarkersFromMarkers()
250
- @clusterize()
251
-
252
- #create google.maps Markers from data provided by user
253
- createServiceMarkersFromMarkers : ->
254
- for marker, index in @markers
255
- if not @markers[index].serviceObject?
256
- #extract options, test if value passed or use default
257
- Lat = @markers[index].lat
258
- Lng = @markers[index].lng
259
-
260
- #alter coordinates if randomize is true
261
- if @markers_conf.randomize
262
- LatLng = @randomize(Lat, Lng)
263
- #retrieve coordinates from the array
264
- Lat = LatLng[0]
265
- Lng = LatLng[1]
266
-
267
- #save object
268
- @markers[index].serviceObject = @createMarker
269
- "marker_picture": if @markers[index].picture then @markers[index].picture else @markers_conf.picture
270
- "marker_width": if @markers[index].width then @markers[index].width else @markers_conf.width
271
- "marker_height": if @markers[index].height then @markers[index].height else @markers_conf.length
272
- "marker_title": if @markers[index].title then @markers[index].title else null
273
- "marker_anchor": if @markers[index].marker_anchor then @markers[index].marker_anchor else null
274
- "shadow_anchor": if @markers[index].shadow_anchor then @markers[index].shadow_anchor else null
275
- "shadow_picture": if @markers[index].shadow_picture then @markers[index].shadow_picture else null
276
- "shadow_width": if @markers[index].shadow_width then @markers[index].shadow_width else null
277
- "shadow_height": if @markers[index].shadow_height then @markers[index].shadow_height else null
278
- "marker_draggable": if @markers[index].draggable then @markers[index].draggable else @markers_conf.draggable
279
- "rich_marker": if @markers[index].rich_marker then @markers[index].rich_marker else null
280
- "zindex": if @markers[index].zindex then @markers[index].zindex else null
281
- "Lat": Lat
282
- "Lng": Lng
283
- "index": index
284
-
285
- #add infowindowstuff if enabled
286
- @createInfoWindow(@markers[index])
287
- #create sidebar if enabled
288
- @createSidebar(@markers[index])
289
-
290
- @markers_conf.offset = @markers.length
291
-
292
- #creates Image Anchor Position or return null if nothing passed
293
- createImageAnchorPosition : (anchorLocation) ->
294
- if (anchorLocation == null)
295
- return null
296
- else
297
- return @createPoint(anchorLocation[0], anchorLocation[1])
298
-
299
-
300
- #replace old markers with new markers on an existing map
301
- replaceMarkers : (new_markers, adjustBounds = true) ->
302
- @clearMarkers()
303
- #reset previous markers
304
- @markers = new Array
305
- #reset current bounds
306
- @boundsObject = @createLatLngBounds() if adjustBounds
307
- #reset sidebar content if exists
308
- @resetSidebarContent()
309
- #add new markers
310
- @markers_conf.offset = 0
311
- @addMarkers(new_markers, adjustBounds)
312
-
313
- #add new markers to on an existing map
314
- addMarkers : (new_markers, adjustBounds = true) ->
315
- #update the list of markers to take into account
316
- @markers = @markers.concat(new_markers)
317
- #put markers on the map
318
- @create_markers()
319
- @adjustMapToBounds() if adjustBounds
320
-
321
- #////////////////////////////////////////////////////
322
- #///////////////////// SIDEBAR //////////////////////
323
- #////////////////////////////////////////////////////
324
-
325
- #//creates sidebar
326
- createSidebar : (marker_container) ->
327
- if (@markers_conf.list_container)
328
- ul = document.getElementById(@markers_conf.list_container)
329
- li = document.createElement('li')
330
- aSel = document.createElement('a')
331
- aSel.href = 'javascript:void(0);'
332
- html = if marker_container.sidebar? then marker_container.sidebar else "Marker"
333
- aSel.innerHTML = html
334
- currentMap = this
335
- aSel.onclick = @sidebar_element_handler(currentMap, marker_container.serviceObject, 'click')
336
- li.appendChild(aSel)
337
- ul.appendChild(li)
338
-
339
- #moves map to marker clicked + open infowindow
340
- sidebar_element_handler : (currentMap, marker, eventType) ->
341
- return () ->
342
- currentMap.map.panTo(marker.position)
343
- google.maps.event.trigger(marker, eventType)
344
-
345
-
346
- resetSidebarContent : ->
347
- if @markers_conf.list_container isnt null
348
- ul = document.getElementById(@markers_conf.list_container)
349
- ul.innerHTML = ""
350
-
351
- #////////////////////////////////////////////////////
352
- #////////////////// MISCELLANEOUS ///////////////////
353
- #////////////////////////////////////////////////////
354
-
355
- #to make the map fit the different LatLng points
356
- adjustMapToBounds : ->
357
- #FIRST_STEP: retrieve all bounds
358
- #create the bounds object only if necessary
359
- if @map_options.auto_adjust or @map_options.bounds isnt null
360
- @boundsObject = @createLatLngBounds()
361
-
362
- #if autodjust is true, must get bounds from markers polylines etc...
363
- if @map_options.auto_adjust
364
- #from markers
365
- @extendBoundsWithMarkers()
366
-
367
- #from polylines:
368
- @updateBoundsWithPolylines()
369
-
370
- #from polygons:
371
- @updateBoundsWithPolygons()
372
-
373
- #from circles
374
- @updateBoundsWithCircles()
375
-
376
- #in every case, I've to take into account the bounds set up by the user
377
- @extendMapBounds()
378
-
379
- #SECOND_STEP: ajust the map to the bounds
380
- @adaptMapToBounds()
381
-
382
- #////////////////////////////////////////////////////
383
- #/////////////////// POLYLINES //////////////////////
384
- #////////////////////////////////////////////////////
385
-
386
- #replace old markers with new markers on an existing map
387
- replacePolylines : (new_polylines) ->
388
- #reset previous polylines and kill them from map
389
- @destroy_polylines()
390
- #set new polylines
391
- @polylines = new_polylines
392
- #create
393
- @create_polylines()
394
- #.... and adjust map boundaries
395
- @adjustMapToBounds()
396
-
397
- destroy_polylines : ->
398
- for polyline in @polylines
399
- #delete polylines from map
400
- polyline.serviceObject.setMap(null)
401
- #empty array
402
- @polylines = []
403
-
404
- #polylines is an array of arrays. It loops.
405
- create_polylines : ->
406
- for polyline in @polylines
407
- @create_polyline polyline
408
-
409
- #////////////////////////////////////////////////////
410
- #///////////////// Basic functions //////////////////
411
- #///////////////////tests coded//////////////////////
412
-
413
- #//basic function to check existence of a variable
414
- exists : (var_name) ->
415
- return (var_name != "" and typeof var_name != "undefined")
416
-
417
-
418
- #randomize
419
- randomize : (Lat0, Lng0) ->
420
- #distance in meters between 0 and max_random_distance (positive or negative)
421
- dx = @markers_conf.max_random_distance * @random()
422
- dy = @markers_conf.max_random_distance * @random()
423
- Lat = parseFloat(Lat0) + (180/Math.PI)*(dy/6378137)
424
- Lng = parseFloat(Lng0) + ( 90/Math.PI)*(dx/6378137)/Math.cos(Lat0)
425
- return [Lat, Lng]
426
-
427
- mergeObjectWithDefault : (object1, object2) ->
428
- copy_object1 = {}
429
- for key, value of object1
430
- copy_object1[key] = value
431
-
432
- for key, value of object2
433
- unless copy_object1[key]?
434
- copy_object1[key] = value
435
- return copy_object1
436
-
437
- mergeWithDefault : (objectName) ->
438
- default_object = @["default_" + objectName]
439
- object = @[objectName]
440
- @[objectName] = @mergeObjectWithDefault(object, default_object)
441
- return true
442
-
443
- #gives a value between -1 and 1
444
- random : -> return(Math.random() * 2 -1)