Class: Cloudkicker::Map
Instance Method Summary
collapse
#add_ajax_marker_functions, #add_marker_function, #get_map_points_function
Methods included from MapEvents
#add_events, #ajax_markers_event, #map_drag_event
#add_bookmarking_functions
#add_map_control
Constructor Details
#initialize(options = {}) ⇒ Map
Returns a new instance of Map.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/critical_juncture/map.rb', line 9
def initialize(options={})
configure
@lat = options.delete(:lat) || @ck_config['map']['lat']
@long = options.delete(:long) || @ck_config['map']['long']
@map_control = options.delete(:map_control) || @ck_config['map']['map_control']['visible']
@map_control_type = options.delete(:map_control_type) || @ck_config['map']['map_control']['type'].to_sym
@zoom = options.delete(:zoom) || @ck_config['map']['zoom']
@style_id = options.delete(:style_id) || @ck_config['map']['style']['id']
@bounds = options.delete(:bounds) || @ck_config['map']['bounds']['enabled']
@bound_points = options.delete(:points) || 0
if @bounds && @bound_points == 0
raise "You must provide at least one point (via :bound_points) if you are using bounds set to true"
end
@bound_zoom = options.delete(:bound_zoom) || @ck_config['map']['bounds']['zoom'] @enable_bookmarking = options.delete(:enable_bookmarking) || @ck_config['map']['bookmarking']['enabled']
@ajax_markers = options.delete(:ajax_markers) || @ck_config['map']['markers']['ajax']['enabled']
@ajax_url = options.delete(:ajax_url) || @ck_config['map']['markers']['ajax']['url']
@markers = []
@scroll_wheel_zoom_enabled = options.delete(:scroll_wheel_zoom_enabled) || @ck_config['map']['scroll_wheel_zoom']['enabled']
end
|
Instance Method Details
#bounding_box(points) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/critical_juncture/map.rb', line 107
def bounding_box(points)
cloud_map_points = []
points.each do |point|
cloud_map_points << "new CM.LatLng(#{point.latitude}, #{point.longitude})"
end
"new CM.LatLngBounds(#{cloud_map_points.join(',')})"
end
|
31
32
33
34
|
# File 'lib/critical_juncture/map.rb', line 31
def configure
app_root = RAILS_ROOT if defined?(RAILS_ROOT)
@ck_config = YAML.load( File.open("#{app_root}/config/cloud_kicker.yml", 'r') )
end
|
#markers ⇒ Object
103
104
105
|
# File 'lib/critical_juncture/map.rb', line 103
def markers
@markers
end
|
#to_js(map_id = 'map') ⇒ Object
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/critical_juncture/map.rb', line 36
def to_js(map_id='map')
js = []
js << <<-JS
<script type=\"text/javascript\" src=\"#{CLOUDMADE_SRC}\"></script>
JS
js << '<script type="text/javascript">'
js << <<-JS
// set up the array of added markers for use later
var addedMarkers = [];
JS
js << <<-JS
$(document).ready(function() {
// create a new cloudmade tile object with our api key and the map style we want
var cloudmade = new CM.Tiles.CloudMade.Web({key: '#{CLOUDMADE_API_KEY}', styleId: #{@style_id}});
// create a new map object on the DOM element reference by map_id and the tile object above
var map = new CM.Map('#{map_id}', cloudmade);
// set up options here like turning on or off certain map features or setting the map center
JS
unless @scroll_wheel_zoom_enabled
js << <<-JS
map.disableScrollWheelZoom();
JS
end
if @map_control
js << add_map_control(@map_control_type)
end
js << add_events(:ajax_markers => @ajax_markers,
:enable_bookmarking => @enable_bookmarking)
js << set_map_center(@lat, @long, @zoom, @bounds, @bound_points, @bound_zoom)
unless @ajax_markers
@markers.each do |marker|
js << marker
end
end
js << '}); //end $(document).ready'
if @ajax_markers
js << add_ajax_marker_functions(@ajax_url)
end
if @enable_bookmarking
js << add_bookmarking_functions
end
js << '</script>'
js.join("\n")
end
|