gmaps4rails 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66e8ba074b32b4fdd7e122e2c512c50a826068b6
4
- data.tar.gz: 9eca5c6b222f11266666d1e2e149558e90bf2cdb
3
+ metadata.gz: 992d41f8b15816f851c02b3dbdcde4b7c3a88ce5
4
+ data.tar.gz: c5f60c19a76862be67d4f8fe4821f937877d383f
5
5
  SHA512:
6
- metadata.gz: 845a7f4fb3874697bd3f4cd58e610c5955df650cdb4ece016a07cf79bb213ddd728b10f6f47fb32edcd10ed7e62542204bd1d87a9bc23ff8db848688ed49a36e
7
- data.tar.gz: 4349d5157a5b9360474ee3a79772d85bd3b4fedf12ee3ade55cdf2d4575fba16d625ba5ae4986934c1384c3c3f7980b4b2f9a2233f29425532799911c3e72181
6
+ metadata.gz: b8cd6797a82ec1ffaa933230de8fac1b7ecfac8b14472b1b3fbce4f06b2961293f3ad9da6f9c07ff7d2486630df25a29299c124bccd9f653cabb4f453b2723b2
7
+ data.tar.gz: e9a4ecc2f663bd7148473a41d065bfc6797541514bd6e5dd6c2081fd0892108d56feb81def07a7e07591b30babf943493fba703c27612755188e30b6e0a8a5ac
@@ -1,16 +1,22 @@
1
- == Google Maps for Rails
1
+ == Google Maps for Rails {<img src="http://www.pledgie.com/campaigns/23367.png" alt="Endorse" />}[https://pledgie.com/campaigns/23367]
2
2
 
3
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]
4
4
  {<img src="https://codeclimate.com/github/apneadiving/Google-Maps-for-Rails.png" />}[https://codeclimate.com/github/apneadiving/Google-Maps-for-Rails]
5
5
  {<img src="https://badge.fury.io/rb/gmaps4rails.png" alt="Gem Version" />}[http://badge.fury.io/rb/gmaps4rails]
6
6
  {<img src="http://api.coderwall.com/apneadiving/endorsecount.png" alt="Endorse" />}[http://coderwall.com/apneadiving]
7
+ {<img src="https://d2weczhvl823v0.cloudfront.net/apneadiving/google-maps-for-rails/trend.png" alt="Bitdeli Badge" />}[https://bitdeli.com/free]
7
8
 
8
9
  Gmaps4rails is developed to simply create a Google Map with overlays (markers, infowindows...).
9
10
  Yet it's backed on a very flexible codebase which could be prone to accept other map providers.
10
11
 
11
12
  Use it with any Ruby app (I guess you could simply take the js anywhere if you like).
12
13
 
13
- {Here is a quick tutorial on youtube}[http://www.youtube.com/watch?v=R0l-7en3dUw&feature=youtu.be].
14
+ Here is a {quick tutorial on youtube}[http://www.youtube.com/watch?v=R0l-7en3dUw&feature=youtu.be],
15
+ and my {presentation on speaker deck}[https://speakerdeck.com/apneadiving/gmaps4rails].
16
+
17
+ For live examples, {see here}[http://apneadiving.github.io/].
18
+
19
+
14
20
 
15
21
  == A note for < 2.x users
16
22
 
@@ -38,7 +44,7 @@ Insert google scripts in your dom:
38
44
  <script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
39
45
  <script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
40
46
 
41
- You'll require underscore.js too, see here: {http://underscorejs.org/}[http://underscorejs.org/]
47
+ You'll require underscore.js too, see here: {http://underscorejs.org/}[http://underscorejs.org/] (`lo-dash` is compatible too, your choice!).
42
48
 
43
49
  3) Javascript source code
44
50
 
@@ -94,12 +94,12 @@
94
94
  }).call(this);
95
95
  (function() {
96
96
  this.Gmaps.Objects.Builders = function(builderClass, objectClass, primitivesProvider) {
97
- objectClass.PRIMITIVES = primitivesProvider;
98
- builderClass.OBJECT = objectClass;
99
- builderClass.PRIMITIVES = primitivesProvider;
100
97
  return {
101
98
  build: function(args, provider_options, internal_options) {
102
99
  var builder;
100
+ objectClass.PRIMITIVES = primitivesProvider;
101
+ builderClass.OBJECT = objectClass;
102
+ builderClass.PRIMITIVES = primitivesProvider;
103
103
  builder = new builderClass(args, provider_options, internal_options);
104
104
  return builder.build();
105
105
  }
@@ -116,6 +116,7 @@
116
116
  }
117
117
  this.setPrimitives(options);
118
118
  this.setOptions(options);
119
+ this._cacheAllBuilders();
119
120
  this.resetBounds();
120
121
  }
121
122
 
@@ -234,6 +235,14 @@
234
235
  return resource;
235
236
  };
236
237
 
238
+ Handler.prototype._cacheAllBuilders = function() {
239
+ var that;
240
+ that = this;
241
+ return _.each(['Bound', 'Circle', 'Clusterer', 'Kml', 'Map', 'Marker', 'Polygon', 'Polyline'], function(kind) {
242
+ return that._builder(kind);
243
+ });
244
+ };
245
+
237
246
  Handler.prototype._clusterize = function() {
238
247
  return _.isObject(this.marker_options.clusterer);
239
248
  };
@@ -245,14 +254,14 @@
245
254
  };
246
255
 
247
256
  Handler.prototype._default_marker_options = function() {
248
- return {
257
+ return _.clone({
249
258
  singleInfowindow: true,
250
- maxRandomDistance: 100,
259
+ maxRandomDistance: 0,
251
260
  clusterer: {
252
261
  maxZoom: 5,
253
262
  gridSize: 50
254
263
  }
255
- };
264
+ });
256
265
  };
257
266
 
258
267
  Handler.prototype._builder = function(name) {
@@ -266,7 +275,7 @@
266
275
 
267
276
  Handler.prototype._default_models = function() {
268
277
  var models;
269
- models = this._rootModule().Objects;
278
+ models = _.clone(this._rootModule().Objects);
270
279
  if (this._clusterize()) {
271
280
  return models;
272
281
  } else {
@@ -280,7 +289,7 @@
280
289
  };
281
290
 
282
291
  Handler.prototype._default_builders = function() {
283
- return this._rootModule().Builders;
292
+ return _.clone(this._rootModule().Builders);
284
293
  };
285
294
 
286
295
  Handler.prototype._rootModule = function() {
@@ -957,7 +966,11 @@
957
966
  if (_.isNumber(position.lat) && _.isNumber(position.lng)) {
958
967
  return new factory.latLng(position.lat, position.lng);
959
968
  } else {
960
- return position;
969
+ if (_.isFunction(position.getServiceObject)) {
970
+ return position.getServiceObject().getPosition();
971
+ } else {
972
+ return position;
973
+ }
961
974
  }
962
975
  }
963
976
  }
@@ -1,3 +1,3 @@
1
1
  module Gmaps4rails
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -11,13 +11,13 @@ describe("Gmaps.Google.Builders.Marker", function() {
11
11
  var serviceObject, infowindow;
12
12
  beforeEach(function() {
13
13
  spyOn(subject_klass.prototype, 'create_marker');
14
- spyOn(subject_klass.prototype, 'create_infowindow');
14
+ spyOn(subject_klass.prototype, 'create_infowindow_on_click');
15
15
  });
16
16
 
17
17
  it("sets vars", function() {
18
18
  instance = new subject_klass();
19
19
  expect(subject_klass.prototype.create_marker).toHaveBeenCalled();
20
- expect(subject_klass.prototype.create_infowindow).toHaveBeenCalled();
20
+ expect(subject_klass.prototype.create_infowindow_on_click).toHaveBeenCalled();
21
21
  });
22
22
 
23
23
  describe("marker_options", function() {
@@ -38,24 +38,60 @@ describe("Gmaps.Objects.Handler", function() {
38
38
  expect(_.isEqual(subject.marker_options, subject._default_marker_options())).toBeTruthy();
39
39
  });
40
40
 
41
- it("redefines builders", function() {
42
- var MarkerBuilder = function(){};
43
- subject = new subjectClass('Specs', { primitives: primitives, builders: { Marker: MarkerBuilder } });
44
- expect(subject.builders.Marker).toBe(MarkerBuilder);
41
+ describe("redefines builders", function() {
42
+ var MarkerBuilder = jasmine.createSpy('MarkerBuilder');
43
+
44
+ beforeEach(function() {
45
+ subject = new subjectClass('Specs', { primitives: primitives, builders: { Marker: MarkerBuilder } });
46
+ });
47
+
48
+ it("redefines builders", function() {
49
+ expect(subject.builders.Marker).toBe(MarkerBuilder);
50
+ });
51
+
52
+ it("doesnt leak for new instance", function() {
53
+ var instance = new subjectClass('Specs', { primitives: primitives });
54
+ expect(instance.builders.Marker).not.toBe(MarkerBuilder);
55
+ });
45
56
  });
46
57
 
47
- it("redefines models", function() {
48
- var MarkerModel = function(){};
49
- subject = new subjectClass('Specs', { primitives: primitives, models: { Marker: MarkerModel } });
50
- expect(subject.models.Marker).toBe(MarkerModel);
58
+ describe("redefine models", function() {
59
+ var MarkerModel = jasmine.createSpy('MarkerModel');
60
+
61
+ beforeEach(function() {
62
+ subject = new subjectClass('Specs', { primitives: primitives, models: { Marker: MarkerModel } });
63
+ });
64
+
65
+ it("redefines models", function() {
66
+ expect(subject.models.Marker).toBe(MarkerModel);
67
+ });
68
+
69
+ it("doesnt leak for new instance", function() {
70
+ var instance = new subjectClass('Specs', { primitives: primitives });
71
+ expect(instance.models.Marker).not.toBe(MarkerModel);
72
+ });
73
+
51
74
  });
52
75
 
53
- it("redefines marker_options", function() {
76
+ describe("redefines marker_options", function() {
54
77
  var marker_options = { foo: 1 };
55
- subject = new subjectClass('Specs', { primitives: primitives, markers: marker_options });
56
- expect(subject.marker_options.foo).toBe(marker_options.foo);
78
+
79
+ beforeEach(function() {
80
+ subject = new subjectClass('Specs', { primitives: primitives, markers: marker_options });
81
+ });
82
+
83
+ it("redefines marker_options", function() {
84
+ expect(subject.marker_options.foo).toBe(marker_options.foo);
85
+ });
86
+
87
+ it("doesnt leak for new instance", function() {
88
+ var instance = new subjectClass('Specs', { primitives: primitives });
89
+ expect(instance.marker_options.foo).not.toBe(marker_options.foo);
90
+ });
91
+
57
92
  });
58
93
 
94
+
59
95
  it("Clusterer: default model if clusterer required", function() {
60
96
  subject = new subjectClass('Specs', {
61
97
  primitives: primitives,
@@ -30,6 +30,7 @@
30
30
  # - [ lat, lng]
31
31
  # - { lat: , lng: }
32
32
  # - a google.maps.LatLng
33
+ # - a gmaps4rails object
33
34
  latLngFromPosition: (position)->
34
35
  if _.isArray(position)
35
36
  return new factory.latLng(position[0], position[1])
@@ -37,7 +38,10 @@
37
38
  if _.isNumber(position.lat) and _.isNumber(position.lng)
38
39
  return new factory.latLng(position.lat, position.lng)
39
40
  else
40
- position
41
+ if _.isFunction position.getServiceObject
42
+ position.getServiceObject().getPosition()
43
+ else
44
+ position
41
45
  }
42
46
 
43
47
  factory
@@ -1,12 +1,11 @@
1
1
  @Gmaps.Objects.Builders = (builderClass, objectClass, primitivesProvider)->
2
2
 
3
- objectClass.PRIMITIVES = primitivesProvider
4
-
5
- builderClass.OBJECT = objectClass
6
- builderClass.PRIMITIVES = primitivesProvider
7
-
8
3
  return {
9
4
  build: (args, provider_options, internal_options)->
5
+ objectClass.PRIMITIVES = primitivesProvider
6
+ builderClass.OBJECT = objectClass
7
+ builderClass.PRIMITIVES = primitivesProvider
8
+
10
9
  builder = new builderClass(args, provider_options, internal_options)
11
10
  builder.build()
12
11
  }
@@ -11,6 +11,7 @@ class @Gmaps.Objects.Handler
11
11
  constructor: (@type, options = {})->
12
12
  @setPrimitives options
13
13
  @setOptions options
14
+ @_cacheAllBuilders()
14
15
  @resetBounds()
15
16
 
16
17
  buildMap: (options, onMapLoad = ->)->
@@ -104,6 +105,10 @@ class @Gmaps.Objects.Handler
104
105
  resource.setMap(@getMap())
105
106
  resource
106
107
 
108
+ _cacheAllBuilders: ->
109
+ that = @
110
+ _.each ['Bound', 'Circle', 'Clusterer', 'Kml', 'Map', 'Marker', 'Polygon', 'Polyline'], (kind)-> that._builder(kind)
111
+
107
112
  _clusterize: ->
108
113
  _.isObject @marker_options.clusterer
109
114
 
@@ -111,9 +116,9 @@ class @Gmaps.Objects.Handler
111
116
  @clusterer = @_builder('Clusterer').build({ map: @getMap() }, @marker_options.clusterer )
112
117
 
113
118
  _default_marker_options: ->
114
- {
119
+ _.clone {
115
120
  singleInfowindow: true
116
- maxRandomDistance: 100
121
+ maxRandomDistance: 0
117
122
  clusterer:
118
123
  maxZoom: 5
119
124
  gridSize: 50
@@ -125,7 +130,7 @@ class @Gmaps.Objects.Handler
125
130
  @["__builder#{name}"]
126
131
 
127
132
  _default_models: ->
128
- models = @_rootModule().Objects
133
+ models = _.clone(@_rootModule().Objects)
129
134
  if @_clusterize()
130
135
  models
131
136
  else
@@ -136,7 +141,7 @@ class @Gmaps.Objects.Handler
136
141
  string.charAt(0).toUpperCase() + string.slice(1)
137
142
 
138
143
  _default_builders: ->
139
- @_rootModule().Builders
144
+ _.clone @_rootModule().Builders
140
145
 
141
146
  _rootModule: ->
142
147
  @__rootModule ?= Gmaps[@type]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Roth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-30 00:00:00.000000000 Z
12
+ date: 2014-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec