gmaps4rails 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3f77b5d1875cbe806f725f554e7f63209da6da3
4
+ data.tar.gz: 3f53c193d0df201cfcb9ab94fdca200c5daa9e2f
5
+ SHA512:
6
+ metadata.gz: d7242c6c3ac10947e0e11b3bc27fa46cefbb7d50e7685e465cc90924b89406905b7e9e9b42bd257d93728500aaad0910211f1046d7f5459a2a0ec47ff65eccd8
7
+ data.tar.gz: 401280be6d9ed24d82b075df6ee4f07bfa7950334853ccbdd462fe6e1b15773b4e7db709864587fa550f16ed385c5fd4ac2a61dd4814703c3336d776ecd581e5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gmaps4rails (2.0.3)
4
+ gmaps4rails (2.0.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,4 +1,5 @@
1
1
  == Google Maps for Rails
2
+
2
3
  {<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]
3
4
  {<img src="https://codeclimate.com/github/apneadiving/Google-Maps-for-Rails.png" />}[https://codeclimate.com/github/apneadiving/Google-Maps-for-Rails]
4
5
  {<img src="https://badge.fury.io/rb/gmaps4rails.png" alt="Gem Version" />}[http://badge.fury.io/rb/gmaps4rails]
@@ -9,6 +10,13 @@ Yet it's backed on a very flexible codebase which could be prone to accept other
9
10
 
10
11
  Use it with any Ruby app (I guess you could simply take the js anywhere if you like).
11
12
 
13
+ {Here is a quick tutorial on youtube}[http://www.youtube.com/watch?v=R0l-7en3dUw&feature=youtu.be].
14
+
15
+ == A note for < 2.x users
16
+
17
+ Google-Maps-for-Rails-2.0 is an important rewrite to keep the minimum code and features. If
18
+ you're migrating from previous versions, you may want to read the {rational about it}[https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Why-but-why%3F].
19
+
12
20
  == Requirements
13
21
 
14
22
  1) Gemfile
@@ -39,7 +47,7 @@ If you have the asset pipeline, add this:
39
47
  //= require underscore
40
48
  //= require gmaps/google
41
49
 
42
- If you don't have aset pipeline, you'll need to import the js OR coffee files:
50
+ If you don't have asset pipeline, you'll need to import the js OR coffee files:
43
51
 
44
52
  rails g gmaps4rails:copy_js
45
53
 
@@ -90,18 +98,10 @@ You can change almost everything with a few lines of code. {See details here}[ht
90
98
 
91
99
  * Markers with Info window, Custom Picture, RichMarkers (make your own markers with custom html)
92
100
 
93
- * Circles, Polylines, Polygons
94
-
95
- * Geocode directly your address and retrieve coordinates.
96
-
97
- * Auto-adjust the map to your markers
101
+ * Circles, Polylines, Polygons, Kml
98
102
 
99
103
  * Refresh your map on the fly with Javascript (and Ajax)
100
104
 
101
- * KML support
102
-
103
- * Easy multimap
104
-
105
105
  * {More details in the Wiki}[https://github.com/apneadiving/Google-Maps-for-Rails/wiki]
106
106
 
107
107
  == Todo?
@@ -112,6 +112,6 @@ Feel free to contact us, you have your say.
112
112
  == Copyright
113
113
  MIT license.
114
114
 
115
- Authors: Benjamin Roth, David Ruyer
115
+ Author: Benjamin Roth
116
116
 
117
117
  {Contributors}[https://github.com/apneadiving/Google-Maps-for-Rails/graphs/contributors]
@@ -124,7 +124,7 @@
124
124
  if (onMapLoad == null) {
125
125
  onMapLoad = function() {};
126
126
  }
127
- return this.map = this._map_builder().build(options, function() {
127
+ return this.map = this._builder('Map').build(options, function() {
128
128
  _this._createClusterer();
129
129
  return onMapLoad();
130
130
  });
@@ -139,7 +139,7 @@
139
139
 
140
140
  Handler.prototype.addMarker = function(marker_data, provider_options) {
141
141
  var marker;
142
- marker = this._marker_builder().build(marker_data, provider_options, this.marker_options);
142
+ marker = this._builder('Marker').build(marker_data, provider_options, this.marker_options);
143
143
  marker.setMap(this.getMap());
144
144
  this.clusterer.addMarker(marker);
145
145
  return marker;
@@ -189,6 +189,18 @@
189
189
  return this._addResource('kml', kml_data, provider_options);
190
190
  };
191
191
 
192
+ Handler.prototype.removeMarkers = function(gem_markers) {
193
+ var _this = this;
194
+ return _.map(gem_markers, function(gem_marker) {
195
+ return _this.removeMarker(gem_marker);
196
+ });
197
+ };
198
+
199
+ Handler.prototype.removeMarker = function(gem_marker) {
200
+ gem_marker.clear();
201
+ return this.clusterer.removeMarker(gem_marker);
202
+ };
203
+
192
204
  Handler.prototype.fitMapToBounds = function() {
193
205
  return this.map.fitToBounds(this.bounds.getServiceObject());
194
206
  };
@@ -204,7 +216,7 @@
204
216
  };
205
217
 
206
218
  Handler.prototype.resetBounds = function() {
207
- return this.bounds = this._bound_builder().build();
219
+ return this.bounds = this._builder('Bound').build();
208
220
  };
209
221
 
210
222
  Handler.prototype.setPrimitives = function(options) {
@@ -217,7 +229,7 @@
217
229
 
218
230
  Handler.prototype._addResource = function(resource_name, resource_data, provider_options) {
219
231
  var resource;
220
- resource = this["_" + resource_name + "_builder"]().build(resource_data, provider_options);
232
+ resource = this._builder(resource_name).build(resource_data, provider_options);
221
233
  resource.setMap(this.getMap());
222
234
  return resource;
223
235
  };
@@ -227,7 +239,7 @@
227
239
  };
228
240
 
229
241
  Handler.prototype._createClusterer = function() {
230
- return this.clusterer = this._clusterer_builder().build({
242
+ return this.clusterer = this._builder('Clusterer').build({
231
243
  map: this.getMap()
232
244
  }, this.marker_options.clusterer);
233
245
  };
@@ -243,40 +255,9 @@
243
255
  };
244
256
  };
245
257
 
246
- Handler.prototype._bound_builder = function() {
247
- return this._builder('Bound');
248
- };
249
-
250
- Handler.prototype._clusterer_builder = function() {
251
- return this._builder('Clusterer');
252
- };
253
-
254
- Handler.prototype._marker_builder = function() {
255
- return this._builder('Marker');
256
- };
257
-
258
- Handler.prototype._map_builder = function() {
259
- return this._builder('Map');
260
- };
261
-
262
- Handler.prototype._kml_builder = function() {
263
- return this._builder('Kml');
264
- };
265
-
266
- Handler.prototype._circle_builder = function() {
267
- return this._builder('Circle');
268
- };
269
-
270
- Handler.prototype._polyline_builder = function() {
271
- return this._builder('Polyline');
272
- };
273
-
274
- Handler.prototype._polygon_builder = function() {
275
- return this._builder('Polygon');
276
- };
277
-
278
258
  Handler.prototype._builder = function(name) {
279
259
  var _name;
260
+ name = this._capitalize(name);
280
261
  if (this[_name = "__builder" + name] == null) {
281
262
  this[_name] = Gmaps.Objects.Builders(this.builders[name], this.models[name], this.primitives);
282
263
  }
@@ -294,6 +275,10 @@
294
275
  }
295
276
  };
296
277
 
278
+ Handler.prototype._capitalize = function(string) {
279
+ return string.charAt(0).toUpperCase() + string.slice(1);
280
+ };
281
+
297
282
  Handler.prototype._default_builders = function() {
298
283
  return this._rootModule().Builders;
299
284
  };
@@ -320,6 +305,8 @@
320
305
 
321
306
  NullClusterer.prototype.clear = function() {};
322
307
 
308
+ NullClusterer.prototype.removeMarker = function() {};
309
+
323
310
  return NullClusterer;
324
311
 
325
312
  })();
@@ -334,17 +321,16 @@
334
321
  return this.getServiceObject().setMap(map);
335
322
  },
336
323
  clear: function() {
337
- this.serviceObject.setMap(null);
338
- return this.serviceObject = null;
324
+ return this.getServiceObject().setMap(null);
339
325
  },
340
326
  show: function() {
341
- return this.serviceObject.setVisible(true);
327
+ return this.getServiceObject().setVisible(true);
342
328
  },
343
329
  hide: function() {
344
- return this.serviceObject.setVisible(false);
330
+ return this.getServiceObject().setVisible(false);
345
331
  },
346
332
  isVisible: function() {
347
- return this.serviceObject.getVisible();
333
+ return this.getServiceObject().getVisible();
348
334
  },
349
335
  primitives: function() {
350
336
  return this.constructor.PRIMITIVES;
@@ -749,14 +735,9 @@
749
735
 
750
736
  }).call(this);
751
737
  (function() {
752
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
753
-
754
738
  this.Gmaps.Google.Objects.Clusterer = (function() {
755
739
  function Clusterer(serviceObject) {
756
740
  this.serviceObject = serviceObject;
757
- this.clear = __bind(this.clear, this);
758
- this.addMarker = __bind(this.addMarker, this);
759
- this.addMarkers = __bind(this.addMarkers, this);
760
741
  }
761
742
 
762
743
  Clusterer.prototype.addMarkers = function(markers) {
@@ -767,11 +748,19 @@
767
748
  };
768
749
 
769
750
  Clusterer.prototype.addMarker = function(marker) {
770
- return this.serviceObject.addMarker(marker.serviceObject);
751
+ return this.getServiceObject().addMarker(marker.getServiceObject());
771
752
  };
772
753
 
773
754
  Clusterer.prototype.clear = function() {
774
- return this.serviceObject.clearMarkers();
755
+ return this.getServiceObject().clearMarkers();
756
+ };
757
+
758
+ Clusterer.prototype.removeMarker = function(marker) {
759
+ return this.getServiceObject().removeMarker(marker.getServiceObject());
760
+ };
761
+
762
+ Clusterer.prototype.getServiceObject = function() {
763
+ return this.serviceObject;
775
764
  };
776
765
 
777
766
  return Clusterer;
@@ -1,3 +1,3 @@
1
1
  module Gmaps4rails
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -315,6 +315,46 @@ describe("Gmaps.Objects.Handler", function() {
315
315
  });
316
316
  });
317
317
  });
318
+
319
+ describe("remove collection", function() {
320
+ beforeEach(function() {
321
+ build_subject()
322
+ });
323
+ describe("removeMarkers", function() {
324
+ it("loops and delegates to removeMarker", function() {
325
+ spyOn(subject, 'removeMarker');
326
+
327
+ marker_to_suppress = jasmine.createSpy('marker');
328
+
329
+ subject.removeMarkers([ marker_to_suppress ]);
330
+
331
+ expect(subject.removeMarker).toHaveBeenCalledWith(marker_to_suppress);
332
+ });
333
+ });
334
+ });
335
+
336
+ describe("remove single item", function() {
337
+ beforeEach(function() {
338
+ build_subject();
339
+ });
340
+ describe("removeMarker", function() {
341
+ beforeEach(function() {
342
+ subject.clusterer = { removeMarker: function(){} };
343
+ spyOn(subject.clusterer, 'removeMarker');
344
+ });
345
+
346
+ it("deletes marker", function() {
347
+ spy_clear_fn = jasmine.createSpy('marker_fn');
348
+ marker_to_suppress = { clear: spy_clear_fn };
349
+
350
+ subject.removeMarker(marker_to_suppress);
351
+
352
+ expect(spy_clear_fn).toHaveBeenCalled();
353
+ expect(subject.clusterer.removeMarker).toHaveBeenCalledWith(marker_to_suppress);
354
+ });
355
+ });
356
+ });
357
+
318
358
  });
319
359
 
320
360
  });
@@ -2,12 +2,19 @@ class @Gmaps.Google.Objects.Clusterer
2
2
 
3
3
  constructor: (@serviceObject)->
4
4
 
5
- addMarkers: (markers)=>
5
+ addMarkers: (markers)->
6
6
  _.each markers, (marker)=>
7
7
  @addMarker(marker)
8
8
 
9
- addMarker: (marker)=>
10
- @serviceObject.addMarker(marker.serviceObject)
9
+ addMarker: (marker)->
10
+ @getServiceObject().addMarker(marker.getServiceObject())
11
+
12
+ clear: ->
13
+ @getServiceObject().clearMarkers()
14
+
15
+ removeMarker: (marker)->
16
+ @getServiceObject().removeMarker marker.getServiceObject()
17
+
18
+ getServiceObject: ->
19
+ @serviceObject
11
20
 
12
- clear: =>
13
- @serviceObject.clearMarkers()
@@ -7,17 +7,16 @@
7
7
  @getServiceObject().setMap map
8
8
 
9
9
  clear: ->
10
- @serviceObject.setMap(null)
11
- @serviceObject = null
10
+ @getServiceObject().setMap(null)
12
11
 
13
12
  show: ->
14
- @serviceObject.setVisible(true)
13
+ @getServiceObject().setVisible(true)
15
14
 
16
15
  hide: ->
17
- @serviceObject.setVisible(false)
16
+ @getServiceObject().setVisible(false)
18
17
 
19
18
  isVisible: ->
20
- @serviceObject.getVisible()
19
+ @getServiceObject().getVisible()
21
20
 
22
21
  primitives: ->
23
22
  @constructor.PRIMITIVES
@@ -14,7 +14,7 @@ class @Gmaps.Objects.Handler
14
14
  @resetBounds()
15
15
 
16
16
  buildMap: (options, onMapLoad = ->)->
17
- @map = @_map_builder().build options, =>
17
+ @map = @_builder('Map').build options, =>
18
18
  @_createClusterer()
19
19
  onMapLoad()
20
20
 
@@ -25,7 +25,7 @@ class @Gmaps.Objects.Handler
25
25
 
26
26
  # return marker object
27
27
  addMarker: (marker_data, provider_options)->
28
- marker = @_marker_builder().build(marker_data, provider_options, @marker_options)
28
+ marker = @_builder('Marker').build(marker_data, provider_options, @marker_options)
29
29
  marker.setMap(@getMap())
30
30
  @clusterer.addMarker marker
31
31
  marker
@@ -66,6 +66,16 @@ class @Gmaps.Objects.Handler
66
66
  addKml: (kml_data, provider_options)->
67
67
  @_addResource('kml', kml_data, provider_options)
68
68
 
69
+ # removes markers from map
70
+ removeMarkers: (gem_markers)->
71
+ _.map gem_markers, (gem_marker)=>
72
+ @removeMarker gem_marker
73
+
74
+ # removes marker from map
75
+ removeMarker: (gem_marker)->
76
+ gem_marker.clear()
77
+ @clusterer.removeMarker(gem_marker)
78
+
69
79
  fitMapToBounds: ->
70
80
  @map.fitToBounds @bounds.getServiceObject()
71
81
 
@@ -78,7 +88,7 @@ class @Gmaps.Objects.Handler
78
88
  @models = _.extend @_default_models(), options.models
79
89
 
80
90
  resetBounds: ->
81
- @bounds = @_bound_builder().build()
91
+ @bounds = @_builder('Bound').build()
82
92
 
83
93
  setPrimitives: (options)->
84
94
  @primitives = if options.primitives is undefined
@@ -90,7 +100,7 @@ class @Gmaps.Objects.Handler
90
100
  @builders.Marker.CURRENT_INFOWINDOW
91
101
 
92
102
  _addResource: (resource_name, resource_data, provider_options)->
93
- resource = @["_#{ resource_name }_builder"]().build(resource_data, provider_options)
103
+ resource = @_builder(resource_name).build(resource_data, provider_options)
94
104
  resource.setMap(@getMap())
95
105
  resource
96
106
 
@@ -98,7 +108,7 @@ class @Gmaps.Objects.Handler
98
108
  _.isObject @marker_options.clusterer
99
109
 
100
110
  _createClusterer: ->
101
- @clusterer = @_clusterer_builder().build({ map: @getMap() }, @marker_options.clusterer )
111
+ @clusterer = @_builder('Clusterer').build({ map: @getMap() }, @marker_options.clusterer )
102
112
 
103
113
  _default_marker_options: ->
104
114
  {
@@ -109,31 +119,8 @@ class @Gmaps.Objects.Handler
109
119
  gridSize: 50
110
120
  }
111
121
 
112
- _bound_builder: ->
113
- @_builder('Bound')
114
-
115
- _clusterer_builder: ->
116
- @_builder('Clusterer')
117
-
118
- _marker_builder: ->
119
- @_builder('Marker')
120
-
121
- _map_builder: ->
122
- @_builder('Map')
123
-
124
- _kml_builder: ->
125
- @_builder('Kml')
126
-
127
- _circle_builder: ->
128
- @_builder('Circle')
129
-
130
- _polyline_builder: ->
131
- @_builder('Polyline')
132
-
133
- _polygon_builder: ->
134
- @_builder('Polygon')
135
-
136
122
  _builder: (name)->
123
+ name = @_capitalize(name)
137
124
  @["__builder#{name}"] ?= Gmaps.Objects.Builders(@builders[name], @models[name], @primitives)
138
125
  @["__builder#{name}"]
139
126
 
@@ -145,6 +132,9 @@ class @Gmaps.Objects.Handler
145
132
  models.Clusterer = Gmaps.Objects.NullClusterer
146
133
  models
147
134
 
135
+ _capitalize: (string)->
136
+ string.charAt(0).toUpperCase() + string.slice(1)
137
+
148
138
  _default_builders: ->
149
139
  @_rootModule().Builders
150
140
 
@@ -2,3 +2,4 @@ class @Gmaps.Objects.NullClusterer
2
2
  addMarkers: ->
3
3
  addMarker: ->
4
4
  clear: ->
5
+ removeMarker: ->
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
5
- prerelease:
4
+ version: 2.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Benjamin Roth
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-10-24 00:00:00.000000000 Z
12
+ date: 2013-11-06 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - '='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - '='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rake
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - '='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - '='
45
40
  - !ruby/object:Gem::Version
@@ -47,49 +42,43 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: coffee-script
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: sprockets
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: pry
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  description: Enables easy Google map + overlays creation.
@@ -154,27 +143,26 @@ files:
154
143
  - vendor/assets/javascripts/gmaps/objects/null_clusterer.coffee
155
144
  homepage: http://github.com/apneadiving/Google-Maps-for-Rails
156
145
  licenses: []
146
+ metadata: {}
157
147
  post_install_message:
158
148
  rdoc_options: []
159
149
  require_paths:
160
150
  - lib
161
151
  required_ruby_version: !ruby/object:Gem::Requirement
162
- none: false
163
152
  requirements:
164
- - - ! '>='
153
+ - - '>='
165
154
  - !ruby/object:Gem::Version
166
155
  version: '0'
167
156
  required_rubygems_version: !ruby/object:Gem::Requirement
168
- none: false
169
157
  requirements:
170
- - - ! '>='
158
+ - - '>='
171
159
  - !ruby/object:Gem::Version
172
160
  version: '0'
173
161
  requirements: []
174
162
  rubyforge_project:
175
- rubygems_version: 1.8.24
163
+ rubygems_version: 2.0.3
176
164
  signing_key:
177
- specification_version: 3
165
+ specification_version: 4
178
166
  summary: Maps made easy for Ruby apps
179
167
  test_files:
180
168
  - spec/javascripts/google/builders/marker_spec.js