gmaps4rails 2.0.0.pre → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/.travis.yml +2 -4
  2. data/Gemfile +5 -1
  3. data/Gemfile.lock +31 -113
  4. data/README.rdoc +53 -70
  5. data/Rakefile +21 -1
  6. data/gmaps4rails.gemspec +4 -19
  7. data/js_compilation/gmaps_google.js +961 -0
  8. data/lib/generators/gmaps4rails/copy_coffee_generator.rb +14 -0
  9. data/lib/generators/gmaps4rails/copy_js_generator.rb +15 -0
  10. data/lib/gmaps4rails.rb +12 -22
  11. data/lib/gmaps4rails/markers_builder.rb +74 -0
  12. data/lib/gmaps4rails/rails/engine.rb +6 -0
  13. data/lib/gmaps4rails/rails/railtie.rb +6 -0
  14. data/lib/gmaps4rails/version.rb +2 -2
  15. data/script/compile_coffee_files.rb +19 -0
  16. data/script/gmaps4rails.rake +7 -0
  17. data/spec/javascripts/google/builders/marker_spec.js +96 -0
  18. data/spec/javascripts/helpers/SpecHelper.js +101 -0
  19. data/spec/javascripts/helpers/matchers.js +12 -0
  20. data/spec/javascripts/helpers/underscore.js +6 -0
  21. data/spec/javascripts/objects/handler_spec.js +320 -0
  22. data/spec/javascripts/support/jasmine.yml +86 -0
  23. data/spec/javascripts/support/jasmine_helper.rb +11 -0
  24. data/spec/lib/base_spec.rb +10 -52
  25. data/spec/lib/markers_builder_spec.rb +49 -0
  26. data/spec/spec_helper.rb +1 -25
  27. data/vendor/assets/javascripts/gmaps/base.coffee +16 -0
  28. data/vendor/assets/javascripts/gmaps/base/base.coffee +17 -0
  29. data/vendor/assets/javascripts/gmaps/google.coffee +3 -0
  30. data/vendor/assets/javascripts/gmaps/google/builders/bound.coffee +6 -0
  31. data/vendor/assets/javascripts/gmaps/google/builders/circle.coffee +21 -0
  32. data/vendor/assets/javascripts/gmaps/google/builders/clusterer.coffee +6 -0
  33. data/vendor/assets/javascripts/gmaps/google/builders/kml.coffee +17 -0
  34. data/vendor/assets/javascripts/gmaps/google/builders/map.coffee +27 -0
  35. data/vendor/assets/javascripts/gmaps/google/builders/marker.coffee +100 -0
  36. data/vendor/assets/javascripts/gmaps/google/builders/polygon.coffee +24 -0
  37. data/vendor/assets/javascripts/gmaps/google/builders/polyline.coffee +24 -0
  38. data/vendor/assets/javascripts/gmaps/google/objects/bound.coffee +13 -0
  39. data/vendor/assets/javascripts/gmaps/google/objects/circle.coffee +9 -0
  40. data/vendor/assets/javascripts/gmaps/google/objects/clusterer.coffee +13 -0
  41. data/vendor/assets/javascripts/gmaps/google/objects/common.coffee +23 -0
  42. data/vendor/assets/javascripts/gmaps/google/objects/kml.coffee +15 -0
  43. data/vendor/assets/javascripts/gmaps/google/objects/map.coffee +19 -0
  44. data/vendor/assets/javascripts/gmaps/google/objects/marker.coffee +11 -0
  45. data/vendor/assets/javascripts/gmaps/google/objects/polygon.coffee +8 -0
  46. data/vendor/assets/javascripts/gmaps/google/objects/polyline.coffee +8 -0
  47. data/vendor/assets/javascripts/gmaps/google/primitives.coffee +43 -0
  48. data/vendor/assets/javascripts/gmaps/objects/base_builder.coffee +20 -0
  49. data/vendor/assets/javascripts/gmaps/objects/builder.coffee +12 -0
  50. data/vendor/assets/javascripts/gmaps/objects/handler.coffee +153 -0
  51. data/vendor/assets/javascripts/gmaps/objects/null_clusterer.coffee +4 -0
  52. metadata +66 -299
  53. data/Guardfile.old +0 -24
  54. data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
  55. data/lib/generators/gmaps4rails/install_generator.rb +0 -43
  56. data/lib/generators/templates/README +0 -2
  57. data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
  58. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
  59. data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
  60. data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
  61. data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
  62. data/lib/gmaps4rails/base.rb +0 -126
  63. data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
  64. data/lib/gmaps4rails/extensions/hash.rb +0 -9
  65. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
  66. data/lib/gmaps4rails/js_builder.rb +0 -154
  67. data/lib/gmaps4rails/json_builder.rb +0 -140
  68. data/lib/gmaps4rails/model_handler.rb +0 -101
  69. data/lib/gmaps4rails/view_helper.rb +0 -172
  70. data/lib/tasks/jasmine.rake +0 -8
  71. data/public/javascripts/gmaps4rails/all.js +0 -2144
  72. data/public/javascripts/gmaps4rails/base.js +0 -792
  73. data/public/javascripts/gmaps4rails/google.js +0 -556
  74. data/public/javascripts/gmaps4rails/openlayers.js +0 -377
  75. data/public/stylesheets/gmaps4rails.css +0 -24
  76. data/spec/dummy/.gitignore +0 -3
  77. data/spec/dummy/.rspec +0 -1
  78. data/spec/dummy/README.rdoc +0 -261
  79. data/spec/dummy/Rakefile +0 -7
  80. data/spec/dummy/app/assets/javascripts/application.js +0 -18
  81. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  82. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
  83. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  84. data/spec/dummy/app/controllers/users_controller.rb +0 -105
  85. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  86. data/spec/dummy/app/mailers/.gitkeep +0 -0
  87. data/spec/dummy/app/models/.gitkeep +0 -0
  88. data/spec/dummy/app/models/place.rb +0 -16
  89. data/spec/dummy/app/models/user.rb +0 -12
  90. data/spec/dummy/app/views/layouts/application.html.erb +0 -17
  91. data/spec/dummy/app/views/users/_form.html.erb +0 -37
  92. data/spec/dummy/app/views/users/edit.html.erb +0 -6
  93. data/spec/dummy/app/views/users/index.html.erb +0 -268
  94. data/spec/dummy/app/views/users/new.html.erb +0 -5
  95. data/spec/dummy/app/views/users/show.html.erb +0 -30
  96. data/spec/dummy/config.ru +0 -4
  97. data/spec/dummy/config/application.rb +0 -62
  98. data/spec/dummy/config/boot.rb +0 -10
  99. data/spec/dummy/config/database.yml +0 -25
  100. data/spec/dummy/config/environment.rb +0 -5
  101. data/spec/dummy/config/environments/development.rb +0 -37
  102. data/spec/dummy/config/environments/production.rb +0 -67
  103. data/spec/dummy/config/environments/test.rb +0 -37
  104. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  105. data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
  106. data/spec/dummy/config/initializers/inflections.rb +0 -15
  107. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  108. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  109. data/spec/dummy/config/initializers/session_store.rb +0 -8
  110. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  111. data/spec/dummy/config/locales/en.yml +0 -5
  112. data/spec/dummy/config/routes.rb +0 -60
  113. data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
  114. data/spec/dummy/db/schema.rb +0 -29
  115. data/spec/dummy/lib/assets/.gitkeep +0 -0
  116. data/spec/dummy/log/.gitkeep +0 -0
  117. data/spec/dummy/public/404.html +0 -26
  118. data/spec/dummy/public/422.html +0 -26
  119. data/spec/dummy/public/500.html +0 -25
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/dummy/public/javascripts/Player.js +0 -22
  122. data/spec/dummy/public/javascripts/Song.js +0 -7
  123. data/spec/dummy/public/logo.png +0 -0
  124. data/spec/dummy/script/rails +0 -6
  125. data/spec/factories/place_factory.rb +0 -16
  126. data/spec/factories/user_factory.rb +0 -23
  127. data/spec/fixtures/google_direction_valid.json +0 -65
  128. data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
  129. data/spec/fixtures/google_places_valid.json +0 -45
  130. data/spec/fixtures/google_wrong_geocoding.json +0 -4
  131. data/spec/launchers/all_but_requests.rb +0 -0
  132. data/spec/launchers/all_specs.rb +0 -0
  133. data/spec/launchers/requests.rb +0 -0
  134. data/spec/lib/direction_spec.rb +0 -53
  135. data/spec/lib/geocoder_spec.rb +0 -46
  136. data/spec/lib/js_builder_spec.rb +0 -134
  137. data/spec/lib/json_builder_spec.rb +0 -232
  138. data/spec/lib/places_spec.rb +0 -25
  139. data/spec/models/place_spec.rb +0 -39
  140. data/spec/models/user_spec.rb +0 -187
  141. data/spec/support/geocoding.rb +0 -40
  142. data/spec/support/matchers.rb +0 -73
  143. data/todo +0 -0
  144. data/vendor/assets/javascripts/gmaps4rails/all.js +0 -1
  145. data/vendor/assets/javascripts/gmaps4rails/base.coffee +0 -1
  146. data/vendor/assets/javascripts/gmaps4rails/base/common.coffee +0 -43
  147. data/vendor/assets/javascripts/gmaps4rails/base/configuration.coffee +0 -7
  148. data/vendor/assets/javascripts/gmaps4rails/base/gmaps.coffee +0 -13
  149. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/basic_interface.coffee +0 -15
  150. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/controller_interface.coffee +0 -15
  151. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/map_interface.coffee +0 -27
  152. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/marker_interface.coffee +0 -15
  153. data/vendor/assets/javascripts/gmaps4rails/base/main.coffee +0 -124
  154. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee +0 -29
  155. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/kml_controller.coffee +0 -5
  156. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee +0 -76
  157. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee +0 -29
  158. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polyline_controller.coffee +0 -29
  159. data/vendor/assets/javascripts/gmaps4rails/base/objects/circle.coffee +0 -12
  160. data/vendor/assets/javascripts/gmaps4rails/base/objects/kml.coffee +0 -8
  161. data/vendor/assets/javascripts/gmaps4rails/base/objects/map.coffee +0 -62
  162. data/vendor/assets/javascripts/gmaps4rails/base/objects/marker.coffee +0 -24
  163. data/vendor/assets/javascripts/gmaps4rails/base/objects/polygon.coffee +0 -11
  164. data/vendor/assets/javascripts/gmaps4rails/base/objects/polyline.coffee +0 -11
  165. data/vendor/assets/javascripts/gmaps4rails/bing.coffee +0 -1
  166. data/vendor/assets/javascripts/gmaps4rails/bing/main.coffee +0 -29
  167. data/vendor/assets/javascripts/gmaps4rails/bing/objects/map.coffee +0 -63
  168. data/vendor/assets/javascripts/gmaps4rails/bing/objects/marker.coffee +0 -78
  169. data/vendor/assets/javascripts/gmaps4rails/bing/shared.coffee +0 -20
  170. data/vendor/assets/javascripts/gmaps4rails/google.coffee +0 -1
  171. data/vendor/assets/javascripts/gmaps4rails/google/main.coffee +0 -47
  172. data/vendor/assets/javascripts/gmaps4rails/google/objects/circle.coffee +0 -38
  173. data/vendor/assets/javascripts/gmaps4rails/google/objects/kml.coffee +0 -16
  174. data/vendor/assets/javascripts/gmaps4rails/google/objects/map.coffee +0 -71
  175. data/vendor/assets/javascripts/gmaps4rails/google/objects/marker.coffee +0 -114
  176. data/vendor/assets/javascripts/gmaps4rails/google/objects/polygon.coffee +0 -38
  177. data/vendor/assets/javascripts/gmaps4rails/google/objects/polyline.coffee +0 -49
  178. data/vendor/assets/javascripts/gmaps4rails/google/shared.coffee +0 -27
  179. data/vendor/assets/javascripts/gmaps4rails/openlayers.coffee +0 -1
  180. data/vendor/assets/javascripts/gmaps4rails/openlayers/main.coffee +0 -138
  181. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/map.coffee +0 -49
  182. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/marker.coffee +0 -68
  183. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/polyline.coffee +0 -39
  184. data/vendor/assets/javascripts/gmaps4rails/openlayers/shared.coffee +0 -19
@@ -0,0 +1,86 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - 'js_compilation/*.js'
15
+ # stylesheets
16
+ #
17
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
18
+ # Default: []
19
+ #
20
+ # EXAMPLE:
21
+ #
22
+ # stylesheets:
23
+ # - css/style.css
24
+ # - stylesheets/*.css
25
+ #
26
+ stylesheets:
27
+
28
+ # helpers
29
+ #
30
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
31
+ # Default: ["helpers/**/*.js"]
32
+ #
33
+ # EXAMPLE:
34
+ #
35
+ # helpers:
36
+ # - helpers/**/*.js
37
+ #
38
+ helpers:
39
+ - 'helpers/**/*.js'
40
+ # spec_files
41
+ #
42
+ # Return an array of filepaths relative to spec_dir to include.
43
+ # Default: ["**/*[sS]pec.js"]
44
+ #
45
+ # EXAMPLE:
46
+ #
47
+ # spec_files:
48
+ # - **/*[sS]pec.js
49
+ #
50
+ spec_files:
51
+ - '**/*[sS]pec.js'
52
+
53
+ # src_dir
54
+ #
55
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
56
+ # Default: project root
57
+ #
58
+ # EXAMPLE:
59
+ #
60
+ # src_dir: public
61
+ #
62
+ src_dir:
63
+ # spec_dir
64
+ #
65
+ # Spec directory path. Your spec_files must be returned relative to this path.
66
+ # Default: spec/javascripts
67
+ #
68
+ # EXAMPLE:
69
+ #
70
+ # spec_dir: spec/javascripts
71
+ #
72
+ spec_dir:
73
+
74
+ # spec_helper
75
+ #
76
+ # Ruby file that Jasmine server will require before starting.
77
+ # Returned relative to your root path
78
+ # Default spec/support/jasmine_helper.rb
79
+ #
80
+ # EXAMPLE:
81
+ #
82
+ # spec_helper: spec/support/jasmine_helper.rb
83
+ #
84
+ spec_helper: spec/support/jasmine_helper.rb
85
+
86
+
@@ -0,0 +1,11 @@
1
+ #Use this file to set/override Jasmine configuration options
2
+ #You can remove it if you don't need it.
3
+ #This file is loaded *after* jasmine.yml is interpreted.
4
+ #
5
+ #Example: using a different boot file.
6
+ #Jasmine.configure do |config|
7
+ # config.boot_dir = '/absolute/path/to/boot_dir'
8
+ # config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
9
+ #end
10
+ #
11
+
@@ -1,59 +1,17 @@
1
1
  require 'spec_helper'
2
+ require './lib/gmaps4rails'
2
3
 
3
- include Geocoding
4
+ describe Gmaps4rails do
5
+ describe 'build_markers' do
6
+ let(:collection) { double 'collection' }
7
+ let(:proc) { lambda {} }
8
+ let(:marker_builder) { double 'marker_builder' }
4
9
 
5
- set_gmaps4rails_options!
10
+ it "delegates" do
11
+ ::Gmaps4rails::MarkersBuilder.should_receive(:new).with(collection).and_return marker_builder
12
+ marker_builder.should_receive(:call)
6
13
 
7
- describe "condition_eval" do
8
-
9
- let(:user) { Factory(:user) }
10
-
11
- before(:each) do
12
- Geocoding.stub_geocoding
13
- end
14
-
15
- it "should trigger method if symbol passed" do
16
- User.class_eval do
17
- def gmaps4rails_options
18
- DEFAULT_CONFIG_HASH.merge({ :validation => :published? })
19
- end
20
-
21
- def published?; true; end
14
+ Gmaps4rails.build_markers collection, &proc
22
15
  end
23
- user.should_receive :published?
24
- Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
25
- end
26
-
27
- it "should evaluate lambda if provided" do
28
- user.instance_eval do
29
- def gmaps4rails_options
30
- DEFAULT_CONFIG_HASH.merge({ :validation => lambda { |object| object.test_me(:foo, :bar) } })
31
- end
32
-
33
- def test_me(a,b)
34
- "#{a}, #{b}"
35
- end
36
- end
37
- user.should_receive(:test_me).with(:foo, :bar)
38
- Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
39
- end
40
-
41
- it "should simply accept a true value" do
42
- user.instance_eval do
43
- def gmaps4rails_options
44
- DEFAULT_CONFIG_HASH.merge({ :validation => true })
45
- end
46
- end
47
- Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_true
48
- end
49
-
50
- it "should simply accept a false value" do
51
- user.instance_eval do
52
- def gmaps4rails_options
53
- DEFAULT_CONFIG_HASH.merge({ :validation => false })
54
- end
55
- end
56
- Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_false
57
16
  end
58
17
  end
59
-
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require './lib/gmaps4rails/markers_builder'
3
+
4
+ describe Gmaps4rails::MarkersBuilder do
5
+
6
+ describe "call" do
7
+ let(:lat) { 40 }
8
+ let(:lng) { 5 }
9
+ let(:id) { 'id' }
10
+ let(:infowindow) { 'some infowindow content' }
11
+ let(:name) { 'name' }
12
+ let(:picture) { {
13
+ :url => "http://www.blankdots.com/img/github-32x32.png",
14
+ :width => "32",
15
+ :height => "32"
16
+ }}
17
+ let(:expected_hash) { {
18
+ :lat => lat,
19
+ :lng => lng,
20
+ :marker_title => name,
21
+ :some_id => id,
22
+ :infowindow => infowindow,
23
+ :picture => picture
24
+ }}
25
+ let(:object) { OpenStruct.new(
26
+ :latitude => lat,
27
+ :longitude => lng,
28
+ :name => name,
29
+ :some_id => id
30
+ )}
31
+
32
+ let(:action) { Gmaps4rails::MarkersBuilder.new(object).call do |user, marker|
33
+ marker.lat user.latitude
34
+ marker.lng user.longitude
35
+ marker.infowindow infowindow
36
+ marker.picture picture
37
+ marker.title user.name
38
+ marker.json({ :some_id => user.some_id })
39
+ end
40
+ }
41
+
42
+ it "creates expected hash" do
43
+ expect(action).to eq [expected_hash]
44
+ end
45
+
46
+ end
47
+
48
+
49
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,38 +1,14 @@
1
1
  require 'rubygems'
2
2
 
3
3
  ENV["RAILS_ENV"] ||= 'test'
4
- require File.expand_path("../dummy/config/environment", __FILE__)
5
- require 'rspec/rails'
4
+
6
5
  require 'pry'
7
- #require 'capybara/rspec'
8
- require 'factory_girl_rails'
9
- require 'database_cleaner'
10
- require 'webmock/rspec'
11
6
 
12
7
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
13
- FactoryGirl.definition_file_paths = [ File.join(Rails.root, '../factories') ]
14
8
 
15
9
  RSpec.configure do |config|
16
10
  config.treat_symbols_as_metadata_keys_with_true_values = true
17
11
  config.filter_run :focus => true
18
12
  config.run_all_when_everything_filtered = true
19
-
20
- config.use_transactional_fixtures = true
21
- config.infer_base_class_for_anonymous_controllers = false
22
-
23
- config.before(:suite) do
24
- FactoryGirl.reload
25
- File.open("#{Rails.root}/log/test.log", 'w') {|file| file.truncate(0) } #cleans the log file to make it readable and control it's size
26
- DatabaseCleaner.strategy = :truncation
27
- end
28
-
29
- config.before(:each) do
30
- DatabaseCleaner.start
31
- DatabaseCleaner.clean
32
- end
33
-
34
- config.after(:each) do
35
- DatabaseCleaner.clean
36
- end
37
13
  end
38
14
 
@@ -0,0 +1,16 @@
1
+ #= require_self
2
+ #= require_tree './base'
3
+ #= require_tree './objects'
4
+
5
+ @Gmaps =
6
+
7
+ build: (type, options = {})->
8
+ model = if _.isFunction(options.handler) then options.handler else Gmaps.Objects.Handler
9
+ new model(type, options)
10
+
11
+ Builders: {}
12
+ Objects: {}
13
+
14
+ Google:
15
+ Objects: {}
16
+ Builders: {}
@@ -0,0 +1,17 @@
1
+ moduleKeywords = ['extended', 'included']
2
+
3
+ class @Gmaps.Base
4
+
5
+ @extend: (obj) ->
6
+ for key, value of obj when key not in moduleKeywords
7
+ @[key] = value
8
+
9
+ obj.extended?.apply(@)
10
+ this
11
+
12
+ @include: (obj) ->
13
+ for key, value of obj when key not in moduleKeywords
14
+ # Assign properties to the prototype
15
+ @::[key] = value
16
+ obj.included?.apply(@)
17
+ this
@@ -0,0 +1,3 @@
1
+ #= require './base'
2
+ #= require './google/objects/common'
3
+ #= require_tree './google'
@@ -0,0 +1,6 @@
1
+ class @Gmaps.Google.Builders.Bound extends Gmaps.Objects.BaseBuilder
2
+
3
+ constructor: (options)->
4
+ @before_init()
5
+ @serviceObject = new(@primitives().latLngBounds)
6
+ @after_init()
@@ -0,0 +1,21 @@
1
+ class @Gmaps.Google.Builders.Circle extends Gmaps.Objects.BaseBuilder
2
+
3
+ # args:
4
+ # lat
5
+ # lng
6
+ # radius
7
+ # provider options:
8
+ # https://developers.google.com/maps/documentation/javascript/reference?hl=fr#CircleOptions
9
+ constructor: (@args, @provider_options = {})->
10
+ @before_init()
11
+ @serviceObject = @create_circle()
12
+ @after_init()
13
+
14
+ create_circle: ->
15
+ new(@primitives().circle)(@circle_options())
16
+
17
+ circle_options: ->
18
+ base_options =
19
+ center: new(@primitives().latLng)(@args.lat, @args.lng)
20
+ radius: @args.radius
21
+ _.defaults base_options, @provider_options
@@ -0,0 +1,6 @@
1
+ class @Gmaps.Google.Builders.Clusterer extends Gmaps.Objects.BaseBuilder
2
+
3
+ constructor: (@args, @options)->
4
+ @before_init()
5
+ @serviceObject = new(@primitives().clusterer)(@args.map, [], @options)
6
+ @after_init()
@@ -0,0 +1,17 @@
1
+ class @Gmaps.Google.Builders.Kml extends Gmaps.Objects.BaseBuilder
2
+
3
+ # args:
4
+ # url
5
+ # provider options:
6
+ # https://developers.google.com/maps/documentation/javascript/reference?hl=fr#KmlLayerOptions
7
+ constructor: (@args, @provider_options = {})->
8
+ @before_init()
9
+ @serviceObject = @create_kml()
10
+ @after_init()
11
+
12
+ create_kml: ->
13
+ new(@primitives().kml)(@args.url, @kml_options())
14
+
15
+ kml_options: ->
16
+ base_options = {}
17
+ _.defaults base_options, @provider_options
@@ -0,0 +1,27 @@
1
+ class @Gmaps.Google.Builders.Map extends Gmaps.Objects.BaseBuilder
2
+
3
+ # options:
4
+ # internal:
5
+ # id: dom id of your map container
6
+ # provider: are any options from google: https://developers.google.com/maps/documentation/javascript/reference?hl=fr#MapOptions
7
+ # onMapLoad is the callback triggered once map is loaded
8
+ constructor: (options, onMapLoad)->
9
+ @before_init()
10
+ provider_options = _.extend @default_options(), options.provider
11
+ @internal_options = options.internal
12
+ @serviceObject = new(@primitives().map)(document.getElementById(@internal_options.id), provider_options)
13
+ @on_map_load onMapLoad
14
+ @after_init()
15
+
16
+ build: ->
17
+ new(@model_class())(@serviceObject, @primitives())
18
+
19
+ on_map_load: (onMapLoad)->
20
+ @primitives().addListenerOnce @serviceObject, 'idle', onMapLoad
21
+
22
+ default_options: ->
23
+ {
24
+ mapTypeId: @primitives().mapTypes('ROADMAP') # HYBRID, ROADMAP, SATELLITE, TERRAIN
25
+ center: @primitives().latLng(0, 0)
26
+ zoom: 8
27
+ }
@@ -0,0 +1,100 @@
1
+ class @Gmaps.Google.Builders.Marker extends Gmaps.Objects.BaseBuilder
2
+
3
+ @CURRENT_INFOWINDOW: undefined
4
+ @CACHE_STORE: {}
5
+
6
+ # args:
7
+ # lat
8
+ # lng
9
+ # infowindow
10
+ # marker_title
11
+ # picture
12
+ # anchor: [x,y]
13
+ # url
14
+ # width
15
+ # height
16
+ # shadow
17
+ # anchor: [x,y]
18
+ # url
19
+ # width
20
+ # height
21
+ # provider options:
22
+ # https://developers.google.com/maps/documentation/javascript/reference?hl=fr#MarkerOptions
23
+ # internal_options
24
+ # singleInfowindow: true/false
25
+ # maxRandomDistance: null / int in meters
26
+ constructor: (@args, @provider_options = {}, @internal_options = {})->
27
+ @before_init()
28
+ @create_marker()
29
+ @create_infowindow()
30
+ @after_init()
31
+
32
+ build: ->
33
+ new(@model_class())(@serviceObject, @infowindow)
34
+
35
+ create_marker: ->
36
+ @serviceObject = new(@primitives().marker)(@marker_options())
37
+
38
+ create_infowindow: ->
39
+ return null unless _.isString @args.infowindow
40
+ @infowindow = new(@primitives().infowindow)({content: @args.infowindow })
41
+ @bind_infowindow()
42
+
43
+ marker_options: ->
44
+ coords = @_randomized_coordinates()
45
+ base_options =
46
+ title: @args.marker_title
47
+ position: new(@primitives().latLng)(coords[0], coords[1])
48
+ icon: @_get_picture('picture')
49
+ shadow: @_get_picture('shadow')
50
+ _.extend @provider_options, base_options
51
+
52
+ bind_infowindow: ->
53
+ @addListener 'click', @infowindow_binding
54
+
55
+ infowindow_binding: =>
56
+ @panTo()
57
+ @constructor.CURRENT_INFOWINDOW.close() if @_should_close_infowindow()
58
+ @infowindow.open( @getServiceObject().getMap(), @getServiceObject())
59
+ @constructor.CURRENT_INFOWINDOW = @infowindow
60
+
61
+ panTo: ->
62
+ @getServiceObject().getMap().panTo @getServiceObject().getPosition()
63
+
64
+ _get_picture: (picture_name)->
65
+ return null if !_.isObject(@args[picture_name]) || !_.isString(@args[picture_name].url)
66
+ @_create_or_retrieve_image @_picture_args(picture_name)
67
+
68
+ _create_or_retrieve_image: (picture_args) ->
69
+ if @constructor.CACHE_STORE[picture_args.url] is undefined
70
+ @constructor.CACHE_STORE[picture_args.url] = new(@primitives().markerImage)(picture_args.url, picture_args.size, picture_args.origin, picture_args.anchor , picture_args.scaledSize)
71
+
72
+ @constructor.CACHE_STORE[picture_args.url]
73
+
74
+ _picture_args: (picture_name)->
75
+ {
76
+ url: @args[picture_name].url
77
+ anchor: @_createImageAnchorPosition @args[picture_name].anchor
78
+ size: new(@primitives().size)(@args[picture_name].width, @args[picture_name].height)
79
+ scaledSize: null
80
+ origin: null
81
+ }
82
+
83
+ _createImageAnchorPosition : (anchorLocation) ->
84
+ return null unless _.isArray anchorLocation
85
+ new(@primitives().point)(anchorLocation[0], anchorLocation[1])
86
+
87
+ _should_close_infowindow: ->
88
+ @internal_options.singleInfowindow and @constructor.CURRENT_INFOWINDOW?
89
+
90
+ _randomized_coordinates: ->
91
+ return [@args.lat, @args.lng] unless _.isNumber(@internal_options.maxRandomDistance)
92
+
93
+ #gives a value between -1 and 1
94
+ random = -> (Math.random() * 2 - 1)
95
+ dx = @internal_options.maxRandomDistance * random()
96
+ dy = @internal_options.maxRandomDistance * random()
97
+ Lat = parseFloat(@args.lat) + (180/Math.PI)*(dy/6378137)
98
+ Lng = parseFloat(@args.lng) + ( 90/Math.PI)*(dx/6378137)/Math.cos(@args.lat)
99
+ return [Lat, Lng]
100
+