2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/hash.rb', line 2
def to_gmaps4rails(init = false)
result = Array.new
if init == true
unless self["map_options"].nil?
self["map_options"].each do |option_k, option_v|
if option_k == "bounds" result << "Gmaps4Rails.map_options.#{option_k} = #{option_v};"
else
result << "Gmaps4Rails.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
end
end
end
result << "Gmaps4Rails.initialize();"
end each do |category, content| case category
when "map_options"
when "direction"
result << "Gmaps4Rails.direction_conf.origin = '#{content["data"]["from"]}';"
result << "Gmaps4Rails.direction_conf.destination = '#{content["data"]["to"]}';"
content["options"] ||= Array.new
content["options"].each do |option_k, option_v|
if option_k == "waypoints"
waypoints = Array.new
option_v.each do |waypoint|
waypoints << { "location" => waypoint, "stopover" => true }.to_json
end
result << "Gmaps4Rails.direction_conf.waypoints = [#{waypoints * (",")}];"
else result << "Gmaps4Rails.direction_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
end
end result << "Gmaps4Rails.create_direction();"
else result << "Gmaps4Rails.#{category} = #{content["data"]};"
content["options"] ||= Array.new
content["options"].each do |option_k, option_v|
result << "Gmaps4Rails.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
end
result << "Gmaps4Rails.create_#{category}();"
end
end
result << "if(typeof gmaps4rails_callback == 'function') { gmaps4rails_callback(); }"
result * ('
')
end
|