gmaps4rails 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +7 -1
- data/README.rdoc +2 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +37 -96
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +11 -0
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +85 -9
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +13 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +54 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +1 -1
- data/gmaps4rails.gemspec +1 -0
- data/lib/generators/gmaps4rails/install_generator.rb +28 -12
- data/lib/gmaps4rails/acts_as_gmappable.rb +3 -46
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
- data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
- data/lib/gmaps4rails/base.rb +80 -22
- data/lib/gmaps4rails/extensions/{array.rb → enumerable.rb} +1 -1
- data/lib/gmaps4rails/js_builder.rb +9 -17
- data/lib/gmaps4rails/json_builder.rb +1 -7
- data/lib/gmaps4rails/model_handler.rb +79 -0
- data/lib/gmaps4rails/version.rb +1 -1
- data/lib/gmaps4rails/view_helper.rb +4 -6
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +35 -112
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +12 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +123 -7
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +12 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +53 -2
- data/spec/dummy/app/views/users/index.html.erb +88 -85
- data/spec/fixtures/google_direction_valid.json +65 -0
- data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
- data/spec/fixtures/google_places_valid.json +45 -0
- data/spec/fixtures/google_wrong_geocoding.json +4 -0
- data/spec/lib/base_spec.rb +59 -0
- data/spec/lib/direction_spec.rb +53 -0
- data/spec/lib/geocoder_spec.rb +46 -0
- data/spec/{base/base_spec.rb → lib/js_builder_spec.rb} +0 -6
- data/spec/lib/json_builder_spec.rb +232 -0
- data/spec/lib/places_spec.rb +25 -0
- data/spec/models/user_spec.rb +75 -357
- data/spec/spec_helper.rb +1 -0
- data/spec/support/geocoding.rb +27 -1
- metadata +47 -12
- data/lib/gmaps4rails/geocoding.rb +0 -113
- data/lib/gmaps4rails/google_places.rb +0 -76
- data/spec/base/geocoding_spec.rb +0 -17
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gmaps4rails (1.5.
|
4
|
+
gmaps4rails (1.5.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -33,6 +33,7 @@ GEM
|
|
33
33
|
activesupport (3.2.3)
|
34
34
|
i18n (~> 0.6)
|
35
35
|
multi_json (~> 1.0)
|
36
|
+
addressable (2.2.8)
|
36
37
|
arel (3.0.2)
|
37
38
|
builder (3.0.0)
|
38
39
|
childprocess (0.3.1)
|
@@ -42,6 +43,7 @@ GEM
|
|
42
43
|
coffee-script-source
|
43
44
|
execjs
|
44
45
|
coffee-script-source (1.2.0)
|
46
|
+
crack (0.3.1)
|
45
47
|
database_cleaner (0.7.2)
|
46
48
|
diff-lcs (1.1.3)
|
47
49
|
erubis (2.7.0)
|
@@ -152,6 +154,9 @@ GEM
|
|
152
154
|
polyglot
|
153
155
|
polyglot (>= 0.3.1)
|
154
156
|
tzinfo (0.3.32)
|
157
|
+
webmock (1.8.7)
|
158
|
+
addressable (>= 2.2.7)
|
159
|
+
crack (>= 0.1.7)
|
155
160
|
|
156
161
|
PLATFORMS
|
157
162
|
ruby
|
@@ -171,3 +176,4 @@ DEPENDENCIES
|
|
171
176
|
rails (~> 3.2.1)
|
172
177
|
rspec-rails
|
173
178
|
sqlite3
|
179
|
+
webmock
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
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]
|
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
2
|
|
3
3
|
Gmaps4rails is developed to simply create a Google Map:
|
4
4
|
|
@@ -124,4 +124,4 @@ MIT license.
|
|
124
124
|
|
125
125
|
Authors: Benjamin Roth, David Ruyer
|
126
126
|
|
127
|
-
Contributors
|
127
|
+
{Contributors}[https://github.com/apneadiving/Google-Maps-for-Rails/graphs/contributors]
|
@@ -70,6 +70,14 @@ class @Gmaps4Rails
|
|
70
70
|
@markerClusterer = null # contains all marker clusterers
|
71
71
|
@markerImages = []
|
72
72
|
|
73
|
+
#Polyline Styling
|
74
|
+
@polylines_conf = #default style for polylines
|
75
|
+
strokeColor: "#FF0000"
|
76
|
+
strokeOpacity: 1
|
77
|
+
strokeWeight: 2
|
78
|
+
clickable: false
|
79
|
+
zIndex: null
|
80
|
+
|
73
81
|
#tnitializes the map
|
74
82
|
initialize : ->
|
75
83
|
@serviceObject = @createMap()
|
@@ -228,73 +236,7 @@ class @Gmaps4Rails
|
|
228
236
|
#save polygon in list
|
229
237
|
polygon.serviceObject = new_poly
|
230
238
|
|
231
|
-
|
232
|
-
#/////////////////// POLYLINES //////////////////////
|
233
|
-
#////////////////////////////////////////////////////
|
234
|
-
|
235
|
-
#replace old markers with new markers on an existing map
|
236
|
-
replacePolylines : (new_polylines) ->
|
237
|
-
#reset previous polylines and kill them from map
|
238
|
-
@destroy_polylines()
|
239
|
-
#set new polylines
|
240
|
-
@polylines = new_polylines
|
241
|
-
#create
|
242
|
-
@create_polylines()
|
243
|
-
#.... and adjust map boundaries
|
244
|
-
@adjustMapToBounds()
|
245
|
-
|
246
|
-
destroy_polylines : ->
|
247
|
-
for polyline in @polylines
|
248
|
-
#delete polylines from map
|
249
|
-
polyline.serviceObject.setMap(null)
|
250
|
-
#empty array
|
251
|
-
@polylines = []
|
252
|
-
|
253
|
-
#polylines is an array of arrays. It loops.
|
254
|
-
create_polylines : ->
|
255
|
-
for polyline in @polylines
|
256
|
-
@create_polyline polyline
|
257
|
-
|
258
|
-
#creates a single polyline, triggered by create_polylines
|
259
|
-
create_polyline : (polyline) ->
|
260
|
-
polyline_coordinates = []
|
261
|
-
|
262
|
-
#2 cases here, either we have a coded array of LatLng or we have an Array of LatLng
|
263
|
-
for element in polyline
|
264
|
-
#if we have a coded array
|
265
|
-
if element.coded_array?
|
266
|
-
decoded_array = new google.maps.geometry.encoding.decodePath(element.coded_array)
|
267
|
-
#loop through every point in the array
|
268
|
-
for point in decoded_array
|
269
|
-
polyline_coordinates.push(point)
|
270
|
-
|
271
|
-
#or we have an array of latlng
|
272
|
-
else
|
273
|
-
#by convention, a single polyline could be customized in the first array or it uses default values
|
274
|
-
if element == polyline[0]
|
275
|
-
strokeColor = element.strokeColor || @polylines_conf.strokeColor
|
276
|
-
strokeOpacity = element.strokeOpacity || @polylines_conf.strokeOpacity
|
277
|
-
strokeWeight = element.strokeWeight || @polylines_conf.strokeWeight
|
278
|
-
clickable = element.clickable || @polylines_conf.clickable
|
279
|
-
zIndex = element.zIndex || @polylines_conf.zIndex
|
280
|
-
|
281
|
-
#add latlng if positions provided
|
282
|
-
if element.lat? && element.lng?
|
283
|
-
latlng = @createLatLng(element.lat, element.lng)
|
284
|
-
polyline_coordinates.push(latlng)
|
285
|
-
|
286
|
-
# Construct the polyline
|
287
|
-
new_poly = new google.maps.Polyline
|
288
|
-
path: polyline_coordinates
|
289
|
-
strokeColor: strokeColor
|
290
|
-
strokeOpacity: strokeOpacity
|
291
|
-
strokeWeight: strokeWeight
|
292
|
-
clickable: clickable
|
293
|
-
zIndex: zIndex
|
294
|
-
|
295
|
-
#save polyline
|
296
|
-
polyline.serviceObject = new_poly
|
297
|
-
new_poly.setMap(@serviceObject)
|
239
|
+
|
298
240
|
|
299
241
|
#////////////////////////////////////////////////////
|
300
242
|
#///////////////////// MARKERS //////////////////////
|
@@ -421,47 +363,46 @@ class @Gmaps4Rails
|
|
421
363
|
@extendBoundsWithMarkers()
|
422
364
|
|
423
365
|
#from polylines:
|
424
|
-
|
425
|
-
polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray()
|
426
|
-
for point in polyline_points
|
427
|
-
@boundsObject.extend point
|
366
|
+
@updateBoundsWithPolylines()
|
428
367
|
|
429
368
|
#from polygons:
|
430
|
-
|
431
|
-
polygon_points = polygon.serviceObject.latLngs.getArray()[0].getArray()
|
432
|
-
for point in polygon_points
|
433
|
-
@boundsObject.extend point
|
369
|
+
@updateBoundsWithPolygons()
|
434
370
|
|
435
371
|
#from circles
|
436
|
-
|
437
|
-
@boundsObject.extend(circle.serviceObject.getBounds().getNorthEast())
|
438
|
-
@boundsObject.extend(circle.serviceObject.getBounds().getSouthWest())
|
372
|
+
@updateBoundsWithCircles()
|
439
373
|
|
440
374
|
#in every case, I've to take into account the bounds set up by the user
|
441
|
-
|
442
|
-
#create points from bounds provided
|
443
|
-
#TODO:only works with google maps
|
444
|
-
bound = @createLatLng(bound.lat, bound.lng)
|
445
|
-
@boundsObject.extend bound
|
375
|
+
@extendMapBounds()
|
446
376
|
|
447
377
|
#SECOND_STEP: ajust the map to the bounds
|
448
|
-
|
449
|
-
#if autozoom is false, take user info into account
|
450
|
-
if !@map_options.auto_zoom
|
451
|
-
map_center = @boundsObject.getCenter()
|
452
|
-
@map_options.center_latitude = map_center.lat()
|
453
|
-
@map_options.center_longitude = map_center.lng()
|
454
|
-
@serviceObject.setCenter(map_center)
|
455
|
-
else
|
456
|
-
@fitBounds()
|
378
|
+
@adaptMapToBounds()
|
457
379
|
|
458
380
|
#////////////////////////////////////////////////////
|
459
|
-
|
381
|
+
#/////////////////// POLYLINES //////////////////////
|
460
382
|
#////////////////////////////////////////////////////
|
461
383
|
|
462
|
-
|
463
|
-
|
464
|
-
|
384
|
+
#replace old markers with new markers on an existing map
|
385
|
+
replacePolylines : (new_polylines) ->
|
386
|
+
#reset previous polylines and kill them from map
|
387
|
+
@destroy_polylines()
|
388
|
+
#set new polylines
|
389
|
+
@polylines = new_polylines
|
390
|
+
#create
|
391
|
+
@create_polylines()
|
392
|
+
#.... and adjust map boundaries
|
393
|
+
@adjustMapToBounds()
|
394
|
+
|
395
|
+
destroy_polylines : ->
|
396
|
+
for polyline in @polylines
|
397
|
+
#delete polylines from map
|
398
|
+
polyline.serviceObject.setMap(null)
|
399
|
+
#empty array
|
400
|
+
@polylines = []
|
401
|
+
|
402
|
+
#polylines is an array of arrays. It loops.
|
403
|
+
create_polylines : ->
|
404
|
+
for polyline in @polylines
|
405
|
+
@create_polyline polyline
|
465
406
|
|
466
407
|
#////////////////////////////////////////////////////
|
467
408
|
#///////////////// Basic functions //////////////////
|
@@ -161,3 +161,14 @@ class @Gmaps4RailsBing extends Gmaps4Rails
|
|
161
161
|
|
162
162
|
centerMapOnUser: ->
|
163
163
|
@serviceObject.setView({ center: @userLocation})
|
164
|
+
|
165
|
+
updateBoundsWithPolylines: ()->
|
166
|
+
|
167
|
+
updateBoundsWithPolygons: ()->
|
168
|
+
|
169
|
+
updateBoundsWithCircles: ()->
|
170
|
+
|
171
|
+
extendMapBounds :->
|
172
|
+
|
173
|
+
adaptMapToBounds: ->
|
174
|
+
@fitBounds()
|
@@ -36,14 +36,6 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
36
36
|
fillOpacity: 0.35
|
37
37
|
clickable: false
|
38
38
|
|
39
|
-
#Polyline Styling
|
40
|
-
@polylines_conf = #default style for polylines
|
41
|
-
strokeColor: "#FF0000"
|
42
|
-
strokeOpacity: 1
|
43
|
-
strokeWeight: 2
|
44
|
-
clickable: false
|
45
|
-
zIndex: null
|
46
|
-
|
47
39
|
#Circle Styling
|
48
40
|
@circles_conf = #default style for circles
|
49
41
|
fillColor: "#00AAFF"
|
@@ -250,7 +242,66 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
250
242
|
kml.setMap(@serviceObject)
|
251
243
|
return kml
|
252
244
|
|
245
|
+
#////////////////////////////////////////////////////
|
246
|
+
#/////////////////// POLYLINES //////////////////////
|
247
|
+
#////////////////////////////////////////////////////
|
248
|
+
|
249
|
+
#creates a single polyline, triggered by create_polylines
|
250
|
+
create_polyline : (polyline) ->
|
251
|
+
polyline_coordinates = []
|
253
252
|
|
253
|
+
#2 cases here, either we have a coded array of LatLng or we have an Array of LatLng
|
254
|
+
for element in polyline
|
255
|
+
#if we have a coded array
|
256
|
+
if element.coded_array?
|
257
|
+
decoded_array = new google.maps.geometry.encoding.decodePath(element.coded_array)
|
258
|
+
#loop through every point in the array
|
259
|
+
for point in decoded_array
|
260
|
+
polyline_coordinates.push(point)
|
261
|
+
|
262
|
+
#or we have an array of latlng
|
263
|
+
else
|
264
|
+
#by convention, a single polyline could be customized in the first array or it uses default values
|
265
|
+
if element == polyline[0]
|
266
|
+
strokeColor = element.strokeColor || @polylines_conf.strokeColor
|
267
|
+
strokeOpacity = element.strokeOpacity || @polylines_conf.strokeOpacity
|
268
|
+
strokeWeight = element.strokeWeight || @polylines_conf.strokeWeight
|
269
|
+
clickable = element.clickable || @polylines_conf.clickable
|
270
|
+
zIndex = element.zIndex || @polylines_conf.zIndex
|
271
|
+
|
272
|
+
#add latlng if positions provided
|
273
|
+
if element.lat? && element.lng?
|
274
|
+
latlng = @createLatLng(element.lat, element.lng)
|
275
|
+
polyline_coordinates.push(latlng)
|
276
|
+
|
277
|
+
# Construct the polyline
|
278
|
+
new_poly = new google.maps.Polyline
|
279
|
+
path: polyline_coordinates
|
280
|
+
strokeColor: strokeColor
|
281
|
+
strokeOpacity: strokeOpacity
|
282
|
+
strokeWeight: strokeWeight
|
283
|
+
clickable: clickable
|
284
|
+
zIndex: zIndex
|
285
|
+
|
286
|
+
#save polyline
|
287
|
+
polyline.serviceObject = new_poly
|
288
|
+
new_poly.setMap(@serviceObject)
|
289
|
+
|
290
|
+
|
291
|
+
updateBoundsWithPolylines: ()->
|
292
|
+
for polyline in @polylines
|
293
|
+
polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray()
|
294
|
+
for point in polyline_points
|
295
|
+
@boundsObject.extend point
|
296
|
+
|
297
|
+
#////////////////////////////////////////////////////
|
298
|
+
#///////////////// KML //////////////////
|
299
|
+
#////////////////////////////////////////////////////
|
300
|
+
|
301
|
+
create_kml : ->
|
302
|
+
for kml in @kml
|
303
|
+
kml.serviceObject = @createKmlLayer kml
|
304
|
+
|
254
305
|
#////////////////////////////////////////////////////
|
255
306
|
#/////////////////// Other methods //////////////////
|
256
307
|
#////////////////////////////////////////////////////
|
@@ -260,4 +311,29 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
260
311
|
|
261
312
|
centerMapOnUser : ->
|
262
313
|
@serviceObject.setCenter(@userLocation)
|
263
|
-
|
314
|
+
|
315
|
+
updateBoundsWithPolygons: ()->
|
316
|
+
for polygon in @polygons
|
317
|
+
polygon_points = polygon.serviceObject.latLngs.getArray()[0].getArray()
|
318
|
+
for point in polygon_points
|
319
|
+
@boundsObject.extend point
|
320
|
+
|
321
|
+
updateBoundsWithCircles: ()->
|
322
|
+
for circle in @circles
|
323
|
+
@boundsObject.extend(circle.serviceObject.getBounds().getNorthEast())
|
324
|
+
@boundsObject.extend(circle.serviceObject.getBounds().getSouthWest())
|
325
|
+
|
326
|
+
extendMapBounds: ()->
|
327
|
+
for bound in @map_options.bounds
|
328
|
+
#create points from bounds provided
|
329
|
+
@boundsObject.extend @createLatLng(bound.lat, bound.lng)
|
330
|
+
|
331
|
+
adaptMapToBounds:()->
|
332
|
+
#if autozoom is false, take user info into account
|
333
|
+
if !@map_options.auto_zoom
|
334
|
+
map_center = @boundsObject.getCenter()
|
335
|
+
@map_options.center_latitude = map_center.lat()
|
336
|
+
@map_options.center_longitude = map_center.lng()
|
337
|
+
@serviceObject.setCenter(map_center)
|
338
|
+
else
|
339
|
+
@fitBounds()
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#######################################################################################################
|
2
2
|
############################################## Map Quest #############################################
|
3
3
|
#######################################################################################################
|
4
|
-
# http://
|
4
|
+
# http://developer.mapquest.com/web/documentation/sdk/javascript/v7.0/api/MQA.Poi.html
|
5
5
|
|
6
6
|
class @Gmaps4RailsMapquest extends Gmaps4Rails
|
7
7
|
|
@@ -131,4 +131,15 @@ class @Gmaps4RailsMapquest extends Gmaps4Rails
|
|
131
131
|
@serviceObject.addShape object
|
132
132
|
|
133
133
|
removeFromMap: (object)->
|
134
|
-
@serviceObject.removeShape object
|
134
|
+
@serviceObject.removeShape object
|
135
|
+
|
136
|
+
updateBoundsWithPolylines: ()->
|
137
|
+
|
138
|
+
updateBoundsWithPolygons: ()->
|
139
|
+
|
140
|
+
updateBoundsWithCircles: ()->
|
141
|
+
|
142
|
+
extendMapBounds :->
|
143
|
+
|
144
|
+
adaptMapToBounds: ->
|
145
|
+
@fitBounds()
|
@@ -18,6 +18,7 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
|
|
18
18
|
@openMarkers = null
|
19
19
|
@markersLayer = null
|
20
20
|
@markersControl = null
|
21
|
+
@polylinesLayer = null
|
21
22
|
|
22
23
|
#////////////////////////////////////////////////////
|
23
24
|
#/////////////// Basic Objects ////////////////////
|
@@ -110,6 +111,7 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
|
|
110
111
|
@serviceObject.removeLayer(@markersLayer) if @markersLayer != null and @serviceObject.getLayer(@markersLayer.id) != null
|
111
112
|
|
112
113
|
extendBoundsWithMarkers: ->
|
114
|
+
console.log "here"
|
113
115
|
for marker in @markers
|
114
116
|
@boundsObject.extend(@createLatLng(marker.lat,marker.lng))
|
115
117
|
|
@@ -187,16 +189,62 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
|
|
187
189
|
null, true, @onPopupClose)
|
188
190
|
feature.popup = popup
|
189
191
|
popup.feature = feature
|
190
|
-
@
|
192
|
+
@map.addPopup popup
|
191
193
|
|
192
194
|
onFeatureUnselect: (evt) ->
|
193
195
|
feature = evt.feature
|
194
196
|
if feature.popup
|
195
197
|
#//popup.feature = null;
|
196
|
-
@
|
198
|
+
@map.removePopup feature.popup
|
197
199
|
feature.popup.destroy()
|
198
200
|
feature.popup = null
|
199
201
|
|
202
|
+
#////////////////////////////////////////////////////
|
203
|
+
#/////////////////// POLYLINES //////////////////////
|
204
|
+
#////////////////////////////////////////////////////
|
205
|
+
|
206
|
+
create_polyline : (polyline) ->
|
207
|
+
|
208
|
+
if(@polylinesLayer == null)
|
209
|
+
@polylinesLayer = new OpenLayers.Layer.Vector("Polylines", null)
|
210
|
+
@serviceObject.addLayer(@polylinesLayer)
|
211
|
+
@polylinesLayer.events.register("featureselected", @polylinesLayer, @onFeatureSelect)
|
212
|
+
@polylinesLayer.events.register("featureunselected", @polylinesLayer, @onFeatureUnselect)
|
213
|
+
@polylinesControl = new OpenLayers.Control.DrawFeature(@polylinesLayer, OpenLayers.Handler.Path)
|
214
|
+
@serviceObject.addControl(@polylinesControl)
|
215
|
+
|
216
|
+
polyline_coordinates = []
|
217
|
+
|
218
|
+
for element in polyline
|
219
|
+
#by convention, a single polyline could be customized in the first array or it uses default values
|
220
|
+
if element == polyline[0]
|
221
|
+
strokeColor = element.strokeColor || @polylines_conf.strokeColor
|
222
|
+
strokeOpacity = element.strokeOpacity || @polylines_conf.strokeOpacity
|
223
|
+
strokeWeight = element.strokeWeight || @polylines_conf.strokeWeight
|
224
|
+
clickable = element.clickable || @polylines_conf.clickable
|
225
|
+
zIndex = element.zIndex || @polylines_conf.zIndex
|
226
|
+
|
227
|
+
#add latlng if positions provided
|
228
|
+
if element.lat? && element.lng?
|
229
|
+
latlng = new OpenLayers.Geometry.Point(element.lng, element.lat)
|
230
|
+
polyline_coordinates.push(latlng)
|
231
|
+
|
232
|
+
line_points = new OpenLayers.Geometry.LineString(polyline_coordinates);
|
233
|
+
line_style = { strokeColor: strokeColor, strokeOpacity: strokeOpacity, strokeWidth: strokeWeight };
|
234
|
+
|
235
|
+
polyline = new OpenLayers.Feature.Vector(line_points, null, line_style);
|
236
|
+
polyline.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"))
|
237
|
+
|
238
|
+
@polylinesLayer.addFeatures([polyline])
|
239
|
+
|
240
|
+
return polyline
|
241
|
+
|
242
|
+
updateBoundsWithPolylines: ()->
|
243
|
+
|
244
|
+
updateBoundsWithPolygons: ()->
|
245
|
+
|
246
|
+
updateBoundsWithCircles: ()->
|
247
|
+
|
200
248
|
# #////////////////////////////////////////////////////
|
201
249
|
# #/////////////////// Other methods //////////////////
|
202
250
|
# #////////////////////////////////////////////////////
|
@@ -207,3 +255,7 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
|
|
207
255
|
centerMapOnUser: ->
|
208
256
|
@serviceObject.setCenter @userLocation
|
209
257
|
|
258
|
+
extendMapBounds :->
|
259
|
+
|
260
|
+
adaptMapToBounds: ->
|
261
|
+
@fitBounds()
|
data/gmaps4rails.gemspec
CHANGED
@@ -7,22 +7,38 @@ module Gmaps4rails
|
|
7
7
|
|
8
8
|
def copy_locale
|
9
9
|
if Rails::VERSION::MINOR >= 1
|
10
|
-
copy_file
|
11
|
-
copy_file
|
12
|
-
copy_file
|
13
|
-
copy_file
|
14
|
-
copy_file
|
15
|
-
copy_file
|
10
|
+
copy_file "#{source_assets_base_path}gmaps4rails.base.js.coffee", "#{destination_assets_base_path}gmaps4rails.base.js.coffee"
|
11
|
+
copy_file "#{source_assets_base_path}gmaps4rails.googlemaps.js.coffee", "#{destination_assets_base_path}gmaps4rails.googlemaps.js.coffee"
|
12
|
+
copy_file "#{source_assets_base_path}gmaps4rails.openlayers.js.coffee", "#{destination_assets_base_path}gmaps4rails.openlayers.js.coffee"
|
13
|
+
copy_file "#{source_assets_base_path}gmaps4rails.bing.js.coffee", "#{destination_assets_base_path}gmaps4rails.bing.js.coffee"
|
14
|
+
copy_file "#{source_assets_base_path}gmaps4rails.mapquest.js.coffee", "#{destination_assets_base_path}gmaps4rails.mapquest.js.coffee"
|
15
|
+
copy_file "../../../public/stylesheets/gmaps4rails.css", "app/assets/stylesheets/gmaps4rails.css"
|
16
16
|
else
|
17
17
|
#I don't copy manifests, kind of useless
|
18
|
-
copy_file
|
19
|
-
copy_file
|
20
|
-
copy_file
|
21
|
-
copy_file
|
22
|
-
copy_file
|
23
|
-
copy_file
|
18
|
+
copy_file "#{source_js_base_path}gmaps4rails.base.js", "#{destination_js_base_path}gmaps4rails.base.js"
|
19
|
+
copy_file "#{source_js_base_path}gmaps4rails.googlemaps.js", "#{destination_js_base_path}gmaps4rails.googlemaps.js"
|
20
|
+
copy_file "#{source_js_base_path}gmaps4rails.bing.js", "#{destination_js_base_path}gmaps4rails.bing.js"
|
21
|
+
copy_file "#{source_js_base_path}gmaps4rails.openlayers.js", "#{destination_js_base_path}gmaps4rails.openlayers.js"
|
22
|
+
copy_file "#{source_js_base_path}gmaps4rails.mapquest.js", "#{destination_js_base_path}gmaps4rails.mapquest.js"
|
23
|
+
copy_file "../../../public/stylesheets/gmaps4rails.css", "public/stylesheets/gmaps4rails.css"
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
def source_assets_base_path
|
28
|
+
'../../../app/assets/javascripts/gmaps4rails/'
|
29
|
+
end
|
30
|
+
|
31
|
+
def destination_assets_base_path
|
32
|
+
'app/assets/javascripts/gmaps4rails/'
|
33
|
+
end
|
34
|
+
|
35
|
+
def source_js_base_path
|
36
|
+
"../../../public/javascripts/gmaps4rails/"
|
37
|
+
end
|
38
|
+
|
39
|
+
def destination_js_base_path
|
40
|
+
"public/javascripts/gmaps4rails/"
|
41
|
+
end
|
26
42
|
|
27
43
|
def show_readme
|
28
44
|
readme 'README' if behavior == :invoke
|
@@ -10,57 +10,14 @@ module Gmaps4rails
|
|
10
10
|
|
11
11
|
# This is a validation method which triggers the geocoding and save its results
|
12
12
|
def process_geocoding
|
13
|
-
|
14
|
-
return true if gmaps4rails_prevent_geocoding?
|
15
|
-
begin
|
16
|
-
coordinates = Gmaps4rails.geocode(self.send(gmaps4rails_options[:address]), gmaps4rails_options[:language], false, gmaps4rails_options[:protocol])
|
17
|
-
rescue GeocodeStatus, GeocodeInvalidQuery => e #address was invalid, add error to address.
|
18
|
-
Rails.logger.warn(e)
|
19
|
-
errors[gmaps4rails_options[:address]] << gmaps4rails_options[:msg] if Gmaps4rails.condition_eval(self, gmaps4rails_options[:validation])
|
20
|
-
rescue GeocodeNetStatus => e #connection error, No need to prevent save.
|
21
|
-
Rails.logger.warn(e)
|
22
|
-
else #if no exception, save the values
|
23
|
-
self.gmaps4rails_save_data(coordinates)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# saves coordinates according to the various options
|
28
|
-
def gmaps4rails_save_data(coordinates)
|
29
|
-
self.send("#{gmaps4rails_options[:lng_column]}=", coordinates.first[:lng])
|
30
|
-
self.send("#{gmaps4rails_options[:lat_column]}=", coordinates.first[:lat])
|
31
|
-
# save normalized address if required
|
32
|
-
self.send("#{gmaps4rails_options[:normalized_address]}=", coordinates.first[:matched_address]) unless gmaps4rails_options[:normalized_address].nil?
|
33
|
-
# Call the callback method to let the user do what he wants with the data
|
34
|
-
self.send(gmaps4rails_options[:callback], coordinates.first[:full_data]) unless gmaps4rails_options[:callback].nil?
|
35
|
-
# update checker if required
|
36
|
-
self.send("#{gmaps4rails_options[:checker]}=", true) if gmaps4rails_check_geocoding?
|
37
|
-
end
|
38
|
-
|
39
|
-
# if process_geocoding is a TrueClass or a FalseClass, 'check_process' and 'checker' play an additional role
|
40
|
-
# if process_geocoding is a Proc or a Symbol, 'check_process' and 'checker' are skipped since process_geocoding bears the whole logic
|
41
|
-
def gmaps4rails_prevent_geocoding?
|
42
|
-
if gmaps4rails_options[:process_geocoding].is_a?(TrueClass) || gmaps4rails_options[:process_geocoding].is_a?(FalseClass)
|
43
|
-
return true if !Gmaps4rails.condition_eval(self, gmaps4rails_options[:process_geocoding])
|
44
|
-
Gmaps4rails.condition_eval(self, gmaps4rails_options[:check_process]) && self.send("#{gmaps4rails_options[:checker]}") == true
|
45
|
-
else
|
46
|
-
!Gmaps4rails.condition_eval(self, gmaps4rails_options[:process_geocoding])
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Do we have to check the geocoding
|
51
|
-
def gmaps4rails_check_geocoding?
|
52
|
-
if gmaps4rails_options[:process_geocoding].is_a?(TrueClass) || gmaps4rails_options[:process_geocoding].is_a?(FalseClass)
|
53
|
-
Gmaps4rails.condition_eval(self, gmaps4rails_options[:check_process])
|
54
|
-
else
|
55
|
-
false
|
56
|
-
end
|
13
|
+
Gmaps4rails::ModelHandler.new(self, gmaps4rails_options).retrieve_coordinates
|
57
14
|
end
|
58
15
|
|
59
16
|
# creates json for one instance
|
60
17
|
def to_gmaps4rails(&block)
|
61
18
|
json = "["
|
62
19
|
object_json = Gmaps4rails.create_json(self, &block)
|
63
|
-
json << object_json.to_s unless
|
20
|
+
json << object_json.to_s unless object_json.nil?
|
64
21
|
json << "]"
|
65
22
|
end
|
66
23
|
|
@@ -97,5 +54,5 @@ module Gmaps4rails
|
|
97
54
|
end
|
98
55
|
end
|
99
56
|
|
100
|
-
end
|
57
|
+
end
|
101
58
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
module BaseNetMethods
|
4
|
+
|
5
|
+
def checked_google_response(&block)
|
6
|
+
raise_net_status unless valid_response?
|
7
|
+
|
8
|
+
raise_query_error unless valid_parsed_response?
|
9
|
+
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
|
13
|
+
def base_url
|
14
|
+
URI.escape base_request
|
15
|
+
end
|
16
|
+
|
17
|
+
def response
|
18
|
+
@response ||= get_response
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_response?
|
22
|
+
response.is_a?(Net::HTTPSuccess)
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_parsed_response?
|
26
|
+
parsed_response["status"] == "OK"
|
27
|
+
end
|
28
|
+
|
29
|
+
def parsed_response
|
30
|
+
@parsed_response ||= JSON.parse(response.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_response
|
34
|
+
url = URI.parse(base_url)
|
35
|
+
http = Gmaps4rails.http_agent
|
36
|
+
http.get_response(url)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|