gmaps4rails 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +30 -31
- data/lib/gmaps4rails.rb +0 -5
- data/lib/gmaps4rails/geocoding.rb +0 -2
- data/lib/gmaps4rails/js_builder.rb +126 -82
- data/lib/gmaps4rails/version.rb +1 -1
- data/spec/base/base_spec.rb +1 -41
- data/spec/dummy/app/assets/javascripts/application.js +3 -3
- data/spec/dummy/app/models/user.rb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +14 -2
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -415,37 +415,36 @@ class @Gmaps4Rails
|
|
415
415
|
if @map_options.auto_adjust or @map_options.bounds isnt null
|
416
416
|
@boundsObject = @createLatLngBounds()
|
417
417
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
if @map_options.auto_adjust or @map_options.bounds.length > 0
|
418
|
+
#if autodjust is true, must get bounds from markers polylines etc...
|
419
|
+
if @map_options.auto_adjust
|
420
|
+
#from markers
|
421
|
+
@extendBoundsWithMarkers()
|
422
|
+
|
423
|
+
#from polylines:
|
424
|
+
for polyline in @polylines
|
425
|
+
polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray()
|
426
|
+
for point in polyline_points
|
427
|
+
@boundsObject.extend point
|
428
|
+
|
429
|
+
#from polygons:
|
430
|
+
for polygon in @polygons
|
431
|
+
polygon_points = polygon.serviceObject.latLngs.getArray()[0].getArray()
|
432
|
+
for point in polygon_points
|
433
|
+
@boundsObject.extend point
|
434
|
+
|
435
|
+
#from circles
|
436
|
+
for circle in @circles
|
437
|
+
@boundsObject.extend(circle.serviceObject.getBounds().getNorthEast())
|
438
|
+
@boundsObject.extend(circle.serviceObject.getBounds().getSouthWest())
|
439
|
+
|
440
|
+
#in every case, I've to take into account the bounds set up by the user
|
441
|
+
for bound in @map_options.bounds
|
442
|
+
#create points from bounds provided
|
443
|
+
#TODO:only works with google maps
|
444
|
+
bound = @createLatLng(bound.lat, bound.lng)
|
445
|
+
@boundsObject.extend bound
|
446
|
+
|
447
|
+
#SECOND_STEP: ajust the map to the bounds
|
449
448
|
|
450
449
|
#if autozoom is false, take user info into account
|
451
450
|
if !@map_options.auto_zoom
|
data/lib/gmaps4rails.rb
CHANGED
@@ -8,11 +8,6 @@ module Gmaps4rails
|
|
8
8
|
ActionView::Base.send :include, Gmaps4railsHelper
|
9
9
|
end
|
10
10
|
|
11
|
-
initializer "deprecation warning" do |app|
|
12
|
-
warn "[Gmaps4rails]: DEPRECATION: Javascript Gmaps.map.map is now deprecated and will be removed in later version. Please use Gmaps.map.serviceObject instead."
|
13
|
-
warn "[Gmaps4rails]: Be sure to run 'rails g gmaps4rails:install' to get js and css files in your app they are not added automatically anymore see Readme on Github"
|
14
|
-
end
|
15
|
-
|
16
11
|
end
|
17
12
|
|
18
13
|
class Railtie < Rails::Railtie
|
@@ -48,7 +48,6 @@ module Gmaps4rails
|
|
48
48
|
#parse result if result received properly
|
49
49
|
if response.is_a?(Net::HTTPSuccess)
|
50
50
|
#parse the json
|
51
|
-
#parse = Crack::JSON.parse(response.body)
|
52
51
|
parse = JSON.parse(response.body)
|
53
52
|
#check if google went well
|
54
53
|
if parse["status"] == "OK"
|
@@ -78,7 +77,6 @@ module Gmaps4rails
|
|
78
77
|
def Gmaps4rails.handle_destination_response(request, response, output)
|
79
78
|
if response.is_a?(Net::HTTPSuccess)
|
80
79
|
#parse the json
|
81
|
-
#parse = Crack::JSON.parse(response.body)
|
82
80
|
parse = JSON.parse(response.body)
|
83
81
|
#check if google went well
|
84
82
|
if parse["status"] == "OK"
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module Gmaps4rails
|
2
2
|
|
3
3
|
def Gmaps4rails.create_js_from_hash(hash)
|
4
|
-
::Gmaps4rails::JsBuilder.new
|
4
|
+
::Gmaps4rails::JsBuilder.new(hash).create_js
|
5
5
|
end
|
6
6
|
|
7
7
|
class JsBuilder
|
8
8
|
|
9
|
-
DEFAULT_MAP_ID
|
10
|
-
|
11
|
-
|
9
|
+
DEFAULT_MAP_ID = "map"
|
10
|
+
DATA_KEYS = [:markers, :polylines, :polygons, :circles, :direction, :kml]
|
11
|
+
|
12
|
+
#the 'option_hash' must have the following structure
|
12
13
|
#{
|
13
14
|
# :map_options => hash,
|
14
15
|
# :markers => { :data => json, :options => hash },
|
@@ -18,102 +19,145 @@ module Gmaps4rails
|
|
18
19
|
# :direction => { :data => hash, :options => hash },
|
19
20
|
# :kml => { :data => json, :options => hash }
|
20
21
|
#}
|
21
|
-
#should be with only symbol keys or with indifferent access
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
#should be with only symbol keys or with indifferent access
|
23
|
+
def initialize(option_hash)
|
24
|
+
@js = Array.new
|
25
|
+
@hash = option_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_js
|
29
|
+
@js << "#{gmap_id} = new #{ map_constructor };"
|
30
|
+
@js << "Gmaps.#{js_function_name} = function() {"
|
31
|
+
|
32
|
+
process_map_options
|
33
|
+
|
34
|
+
@js << "#{gmap_id}.initialize();"
|
35
|
+
|
36
|
+
process_data
|
37
|
+
|
38
|
+
@js << "#{gmap_id}.adjustMapToBounds();"
|
39
|
+
@js << "#{gmap_id}.callback();"
|
40
|
+
@js << "};"
|
41
|
+
@js << "Gmaps.oldOnload = window.onload;\n window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };" if load_map?
|
42
|
+
|
43
|
+
@js * ("\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_map_options
|
47
|
+
return unless map_options
|
48
|
+
map_options.each do |option_key, option_value|
|
49
|
+
next if [:class, :container_class].include? option_key.to_sym
|
50
|
+
case option_key.to_sym
|
51
|
+
when :bounds, :raw #particular case, render the content unescaped
|
52
|
+
@js << "#{gmap_id}.map_options.#{option_key} = #{option_value};"
|
53
|
+
else
|
54
|
+
@js << "#{gmap_id}.map_options.#{option_key} = #{option_value.to_json};"
|
40
55
|
end
|
41
56
|
end
|
42
|
-
|
43
|
-
result << "#{map_id}.callback();"
|
57
|
+
end
|
44
58
|
|
45
|
-
|
46
|
-
|
47
|
-
|
59
|
+
def process_data
|
60
|
+
data.each do |name, hash|
|
61
|
+
datum = ::Gmaps4rails::JsBuilder::Datum.new(gmap_id, name, hash)
|
62
|
+
@js.concat datum.create_js
|
48
63
|
end
|
49
|
-
|
50
|
-
result * ('
|
51
|
-
')
|
52
64
|
end
|
53
65
|
|
54
|
-
def
|
55
|
-
|
66
|
+
def map_options
|
67
|
+
@hash[:map_options]
|
56
68
|
end
|
57
|
-
|
58
|
-
def
|
59
|
-
hash.
|
69
|
+
|
70
|
+
def data
|
71
|
+
@hash.select{|key, value| DATA_KEYS.include?(key.to_sym) }
|
60
72
|
end
|
61
|
-
|
62
|
-
def
|
63
|
-
hash.nil? || hash[:
|
73
|
+
|
74
|
+
def load_map?
|
75
|
+
@hash[:last_map].nil? || @hash[:last_map] == true
|
76
|
+
end
|
77
|
+
|
78
|
+
def js_function_name
|
79
|
+
"load_" + map_id
|
64
80
|
end
|
65
81
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
def gmap_id
|
83
|
+
@gmap_id ||= "Gmaps." + map_id
|
84
|
+
end
|
85
|
+
|
86
|
+
def map_id
|
87
|
+
@map_id ||= map_options.try(:[],:id) || DEFAULT_MAP_ID
|
88
|
+
end
|
89
|
+
|
90
|
+
def map_constructor
|
91
|
+
map_options.try(:[],:provider) ? "Gmaps4Rails#{map_options[:provider].capitalize}()" : "Gmaps4RailsGoogle()"
|
92
|
+
end
|
93
|
+
|
94
|
+
class Datum
|
95
|
+
# example:
|
96
|
+
# - name: :markers
|
97
|
+
# - hash: { :data => json, :options => hash }
|
98
|
+
def initialize(gmap_id, name, hash)
|
99
|
+
@gmap_id, @hash, @name, @js = gmap_id, hash, name, Array.new
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_js
|
103
|
+
if @name.to_sym == :direction
|
104
|
+
create_direction_js
|
105
|
+
else
|
106
|
+
create_standard_js
|
77
107
|
end
|
78
108
|
end
|
79
|
-
|
80
|
-
|
109
|
+
|
110
|
+
def create_standard_js
|
111
|
+
@js << "#{@gmap_id}.#{@name} = #{value};"
|
81
112
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
hash[:options] ||= Array.new
|
86
|
-
hash[:options].each do |option_k, option_v|
|
87
|
-
if option_k.to_sym == :raw
|
88
|
-
output << "#{map_id}.#{category}_conf.#{option_k} = #{option_v};"
|
89
|
-
else
|
90
|
-
output << "#{map_id}.#{category}_conf.#{option_k} = #{option_v.to_json};"
|
91
|
-
end
|
113
|
+
set_configuration_variables
|
114
|
+
|
115
|
+
@js << "#{@gmap_id}.create_#{@name}();"
|
92
116
|
end
|
93
|
-
output << "#{map_id}.create_#{category}();"
|
94
|
-
output
|
95
|
-
end
|
96
117
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
118
|
+
def create_direction_js
|
119
|
+
@js << "#{@gmap_id}.direction_conf.origin = '#{value["from"]}';"
|
120
|
+
@js << "#{@gmap_id}.direction_conf.destination = '#{value["to"]}';"
|
121
|
+
|
122
|
+
set_direction_variables
|
123
|
+
|
124
|
+
@js << "#{@gmap_id}.create_direction();"
|
125
|
+
end
|
126
|
+
|
127
|
+
def set_configuration_variables
|
128
|
+
return unless options
|
129
|
+
options.each do |option_key, option_value|
|
130
|
+
@js << if option_key.to_sym == :raw
|
131
|
+
"#{@gmap_id}.#{@name}_conf.#{option_key} = #{option_value};"
|
132
|
+
else
|
133
|
+
"#{@gmap_id}.#{@name}_conf.#{option_key} = #{option_value.to_json};"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def set_direction_variables
|
139
|
+
return unless options
|
140
|
+
options.each do |option_key, option_value|
|
141
|
+
if option_key.to_sym == :waypoints
|
142
|
+
waypoints = Array.new
|
143
|
+
option_value.each do |waypoint|
|
144
|
+
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
145
|
+
end
|
146
|
+
@js << "#{@gmap_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
147
|
+
else
|
148
|
+
@js << "#{@gmap_id}.direction_conf.#{option_key} = #{option_value.to_json};"
|
107
149
|
end
|
108
|
-
output << "#{map_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
109
|
-
else #option_k != "waypoint"
|
110
|
-
output << "#{map_id}.direction_conf.#{option_k} = #{option_v.to_json};"
|
111
150
|
end
|
112
|
-
end
|
113
|
-
|
114
|
-
|
151
|
+
end
|
152
|
+
|
153
|
+
def options
|
154
|
+
@hash[:options]
|
155
|
+
end
|
156
|
+
|
157
|
+
def value
|
158
|
+
@hash[:data]
|
159
|
+
end
|
115
160
|
end
|
116
|
-
|
117
161
|
end
|
118
162
|
|
119
163
|
|
data/lib/gmaps4rails/version.rb
CHANGED
data/spec/base/base_spec.rb
CHANGED
@@ -1,45 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "JS building methods" do
|
4
|
-
|
5
|
-
subject { ::Gmaps4rails::JsBuilder.new }
|
6
|
-
|
7
|
-
describe "constructor name retrieval" do
|
8
|
-
it "should render google if nothing passed" do
|
9
|
-
subject.get_constructor(nil).should eq "Gmaps4RailsGoogle()"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should render proper provider when provided" do
|
13
|
-
options_hash = { "provider" => "bing" }
|
14
|
-
subject.get_constructor(options_hash.with_indifferent_access).should eq "Gmaps4RailsBing()"
|
15
|
-
|
16
|
-
options_hash = { "provider" => "mapquest" }
|
17
|
-
subject.get_constructor(options_hash.with_indifferent_access).should eq "Gmaps4RailsMapquest()"
|
18
|
-
|
19
|
-
options_hash = { "provider" => "openlayers" }
|
20
|
-
subject.get_constructor(options_hash.with_indifferent_access).should eq "Gmaps4RailsOpenlayers()"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "map ID retrieval" do
|
25
|
-
it "should return the default ID when nothing is passed" do
|
26
|
-
options_hash = nil
|
27
|
-
subject.get_map_id(options_hash).should eq subject.class::DEFAULT_MAP_ID
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return the default ID when no id is passed within map_options" do
|
31
|
-
options_hash = { "foo" => "bar" }
|
32
|
-
subject.get_map_id(options_hash).should eq subject.class::DEFAULT_MAP_ID
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should return the proper ID when id passed" do
|
36
|
-
options_hash = { "id" => "foo" }
|
37
|
-
subject.get_map_id(options_hash.with_indifferent_access).should eq "foo"
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
3
|
describe "to_gmaps4rails for hash" do
|
44
4
|
it "should accept hashes with indifferent access" do
|
45
5
|
hash1 = {:markers => {:data => @json, :options => {:do_clustering => true, :draggable => true } }}
|
@@ -163,7 +123,7 @@ describe "to_gmaps4rails for hash" do
|
|
163
123
|
|
164
124
|
it "should not call map builder if not last_map" do
|
165
125
|
hash = {:last_map => false}
|
166
|
-
hash.to_gmaps4rails.should_not include "window.onload
|
126
|
+
hash.to_gmaps4rails.should_not include "window.onload"
|
167
127
|
end
|
168
128
|
|
169
129
|
it "should call map builder if last_map" do
|
@@ -10,6 +10,6 @@
|
|
10
10
|
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
11
|
// GO AFTER THE REQUIRES BELOW.
|
12
12
|
//
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
// require jquery
|
14
|
+
// require jquery_ujs
|
15
|
+
//= require_tree ./gmaps4rails
|
@@ -70,12 +70,24 @@ window.onload =alert('ok');
|
|
70
70
|
<%#= gmaps(:map_options => { :auto_adjust => true },
|
71
71
|
:markers => {
|
72
72
|
:data => @json,
|
73
|
-
|
73
|
+
:options => {:do_clustering => true}
|
74
74
|
}) %>
|
75
75
|
|
76
|
+
<%#= gmaps("markers" => { "data" => @json, "options" => {
|
77
|
+
"picture" => "/logo.png",
|
78
|
+
"width" => 30, "marker_length" => 32 } }) %>
|
79
|
+
|
80
|
+
|
76
81
|
<%#= gmaps( {:map_options => { :disableDefaultUI => true, :auto_adjust => true, :center_on_user => true, :detect_location => true, :center_latitude => 41.574361,
|
77
82
|
:center_longitude => -72.949219 }}) %>
|
78
|
-
|
83
|
+
<%#= gmaps(:map_options => {:type => "ROADMAP"},
|
84
|
+
:markers => {:data => @json,
|
85
|
+
:options => {"list_container" => "markers_list" }
|
86
|
+
})%>
|
87
|
+
<div id="markers_list"></div>
|
88
|
+
<%= gmaps(:markers => {:data => @json}, :map_options =>
|
89
|
+
{:auto_adjust => false, :bounds => '[{"lat":42.3124,"lng":-71.1712},{"lat":42.3997,"lng":-71.0531}]', :auto_zoom => false }) %>
|
90
|
+
<%#= gmaps(:markers => {:data => @json, :options => {:do_clustering => false, "custom_infowindow_class" => "yellow", :raw => "{ flat: true, draggable: true}" } },
|
79
91
|
:polygons => {:data => '[[
|
80
92
|
{"lng": 5.190262, "lat": 25.774252},
|
81
93
|
{"lng": 7.118292, "lat": 45.466465},
|
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: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -346,7 +346,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
346
346
|
version: '0'
|
347
347
|
segments:
|
348
348
|
- 0
|
349
|
-
hash:
|
349
|
+
hash: 3704430434536150863
|
350
350
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
351
351
|
none: false
|
352
352
|
requirements:
|
@@ -355,7 +355,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
355
|
version: '0'
|
356
356
|
segments:
|
357
357
|
- 0
|
358
|
-
hash:
|
358
|
+
hash: 3704430434536150863
|
359
359
|
requirements: []
|
360
360
|
rubyforge_project:
|
361
361
|
rubygems_version: 1.8.21
|