cloud_kicker 0.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bob Burbach
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = Cloud Kicker
2
+
3
+ Rails abstraction layer for creating maps using the Cloudmade web framework.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Critical Juncture. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cloud_kicker"
8
+ gem.summary = 'Rails abstraction layer for creating maps using the Cloudmade web framework.'
9
+ gem.description = <<-EOF
10
+ Rails abstraction layer for creating maps using the Cloudmade web framework. Makes creating maps with custom
11
+ color schemes, ajax markers and customizable marker info windows quick and easy.
12
+ EOF
13
+ gem.email = "govpulse@gmail.com"
14
+ gem.homepage = "http://github.com/trifecta/cloud_kicker"
15
+ gem.authors = ["Bob Burbach"]
16
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "cloud_kicker #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0.pre1
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cloud_kicker}
8
+ s.version = "0.0.0.pre1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bob Burbach"]
12
+ s.date = %q{2010-03-28}
13
+ s.description = %q{ Rails abstraction layer for creating maps using the Cloudmade web framework. Makes creating maps with custom
14
+ color schemes, ajax markers and customizable marker info windows quick and easy.
15
+ }
16
+ s.email = %q{govpulse@gmail.com}
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "cloud_kicker.gemspec",
29
+ "example/cloud_kicker.yml",
30
+ "lib/critical_juncture/cloud_kicker.rb",
31
+ "lib/critical_juncture/control_elements.rb",
32
+ "lib/critical_juncture/map.rb",
33
+ "lib/critical_juncture/map/map_bookmarking.rb",
34
+ "lib/critical_juncture/map/map_events.rb",
35
+ "lib/critical_juncture/map/map_location.rb",
36
+ "lib/critical_juncture/markers/ajax_markers.rb",
37
+ "lib/critical_juncture/markers/marker.rb",
38
+ "test/helper.rb",
39
+ "test/test_cloud_kicker.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/trifecta/cloud_kicker}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.6}
45
+ s.summary = %q{Rails abstraction layer for creating maps using the Cloudmade web framework.}
46
+ s.test_files = [
47
+ "test/helper.rb",
48
+ "test/test_cloud_kicker.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,23 @@
1
+ map:
2
+ lat: 37.778605
3
+ long: -122.391369
4
+ zoom: 10
5
+ style:
6
+ id: 2
7
+
8
+ map_control:
9
+ visible: true
10
+ type: :large
11
+ bounds:
12
+ enabled: false
13
+ zoom: 2 #used when only a single point is passed to bound_points
14
+ bookmarking:
15
+ enabled: false
16
+
17
+ markers:
18
+ ajax:
19
+ enabled: false
20
+ url: ''
21
+
22
+ scroll_wheel_zoom:
23
+ enabled: true
@@ -0,0 +1,10 @@
1
+ require 'map'
2
+ require 'control_elements'
3
+
4
+ Dir["#{File.join(File.dirname(__FILE__), 'map', '*.rb')}"].each do |filename|
5
+ require filename
6
+ end
7
+
8
+ Dir["#{File.join(File.dirname(__FILE__), 'markers', '*.rb')}"].each do |filename|
9
+ require filename
10
+ end
@@ -0,0 +1,42 @@
1
+ module Cloudkicker
2
+ module ControlElements
3
+
4
+ # add create a map control with type, position and padding
5
+ #
6
+ # Params:
7
+ # map_control_type
8
+ # The size of the control on the map
9
+ # Options - :large, :small
10
+ # position
11
+ # Where the control is located on the map
12
+ # Options - :top_right
13
+ # padding_x
14
+ # Amount of padding in the x direction in pixels - depends on where the position is set to,
15
+ # but always from the outer edge of the map
16
+ # padding_y
17
+ # Amount of padding in the y direction in pixels - depends on where the position is set to,
18
+ # but always from the outer edge of the map
19
+
20
+ def add_map_control(map_control_type, position = :top_right, padding_x = 10, padding_y = 10)
21
+ control_position = case position
22
+ when :top_right
23
+ 'CM.TOP_RIGHT'
24
+ end
25
+
26
+ control_type = case @map_control_type.to_sym
27
+ when :large
28
+ 'CM.LargeMapControl()'
29
+ when :small
30
+ 'CM.SmallMapControl()'
31
+ end
32
+
33
+ js = <<-JS
34
+ // create a new control position and add padding
35
+ var control_position = new CM.ControlPosition(#{control_position}, new CM.Size(#{padding_x}, #{padding_y}));
36
+ map.addControl(new #{control_type}, #{control_position});
37
+ JS
38
+
39
+ return js
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ module CloudKicker
2
+ module MapBookmarking
3
+ def add_bookmarking_functions
4
+ add_location_to_anchor
5
+ end
6
+
7
+ private
8
+
9
+ def add_location_to_anchor
10
+ <<-JS
11
+ function add_location_to_anchor(map){
12
+ var center = map.getCenter();
13
+ var anchor = '#center_lat=' + center.lat() + '&center_lng=' + center.lng() + '&zoom=' + map.getZoom();
14
+ window.location.hash = anchor;
15
+ return false;
16
+ }
17
+ JS
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,69 @@
1
+ module Cloudkicker
2
+ module MapEvents
3
+
4
+ def add_events(options={})
5
+ ajax_markers = options.delete(:ajax_markers)
6
+ enable_bookmarking = options.delete(:enable_bookmarking)
7
+
8
+ js << <<-JS
9
+ /*************************/
10
+ /* add events to the map */
11
+ /*************************/
12
+ JS
13
+
14
+ if ajax_markers
15
+ js << ajax_markers_event
16
+ end
17
+
18
+ js << map_drag_event(enable_bookmarking)
19
+
20
+ return js
21
+ end
22
+
23
+
24
+ # Fires on map load and uses the ajax markers module to get markers from server
25
+ def ajax_markers_event
26
+ js = <<-JS
27
+ // get the markers for the area shown in the map (the bounds) on load
28
+ CM.Event.addListener(map, 'load', function() {
29
+ getMapPoints(map.getBounds());
30
+ });
31
+ JS
32
+
33
+ return js
34
+ end
35
+
36
+ def map_drag_event(enable_bookmarking)
37
+ js = []
38
+
39
+ js << <<-JS
40
+ // we get markers dynamically from the server
41
+ // here we set up the array of added markers and turn on the loading indicator
42
+ var added_markers = [];
43
+ $('.mapMarkerLoader img').show();
44
+
45
+ // show the map marker loading indicator and get the markers for the area shown in
46
+ // the map (the bounds)
47
+ CM.Event.addListener(map, 'dragend', function() {
48
+ $('.mapMarkerLoader img').show();
49
+ getMapPoints(map.getBounds());
50
+ JS
51
+
52
+ # if we're bookmarking then add the location to the url
53
+ if enable_bookmarking
54
+ js << <<-JS
55
+ //and add the new map location to the url so it's bookmarkable
56
+ add_location_to_anchor(map);
57
+ JS
58
+ end
59
+
60
+ # close our dragend map listener regarless
61
+ js << <<-JS
62
+ });
63
+ JS
64
+
65
+ return js
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,62 @@
1
+ module Cloudkicker
2
+ module MapLocation
3
+
4
+ def set_map_center(lat long, zoom, bounds, bound_points, bound_zoom)
5
+ js = []
6
+
7
+ js << <<-JS
8
+ // check to see if this page has a map location in the url
9
+ if (self.document.location.hash) {
10
+ JS
11
+
12
+ js << add_bookmarking
13
+
14
+ js << <<-JS
15
+ // no location present in the url so use the app defaults
16
+ else {
17
+ JS
18
+
19
+ js << add_default_center(lat, long, zoom, bounds, bound_points, bound_zoom)
20
+
21
+ js << ' } //close our else from above when checking if a location was present in the url'
22
+
23
+ return js
24
+ end
25
+
26
+ def add_bookmarking
27
+ # set up javascript to use map location in url if present (ie it was bookmarked)
28
+ js = <<-JS
29
+ var params = {};
30
+ $.each(self.document.location.hash.split(/&/), function(i, key_and_val){
31
+ var results = key_and_val.split(/=/);
32
+ var key = results[0].replace(/^#/, '');
33
+ var val = results[1];
34
+ params[key] = val;
35
+ });
36
+
37
+ // if all the required params are present then set a new map center and zoom
38
+ if (params.center_lat && params.center_lng && params.zoom) {
39
+ map.setCenter(new CM.LatLng(params.center_lat, params.center_lng), params.zoom);
40
+ }
41
+ }
42
+ JS
43
+
44
+ return js
45
+ end
46
+
47
+ def add_default_center(lat, long, zoom, bounds, bound_points, bound_zoom)
48
+ js = []
49
+
50
+ if bounds
51
+ if bound_points.size > 1
52
+ js << " map.zoomToBounds(#{bounding_box(bound_points)})"
53
+ else bound_points.size == 1
54
+ js << " map.setCenter(new CM.LatLng(#{bound_points.first.latitude}, #{bound_points.first.longitude}), #{bound_zoom});"
55
+ end
56
+ else
57
+ js << " map.setCenter(new CM.LatLng(#{lat}, #{long}), #{zoom});"
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,136 @@
1
+ module Cloudkicker
2
+ class Map
3
+ include Cloudkicker::ControlElements
4
+ include Cloudkicker::MapLocation
5
+ include Cloudkicker::MapBookmarking
6
+ include Cloudkicker::MapEvents
7
+
8
+ def initialize(options={})
9
+ configure
10
+ map:
11
+ lat:
12
+ long:
13
+ map_control:
14
+ map_control_type:
15
+ zoom:
16
+ style_id:
17
+ bounds:
18
+ bound_zoom:
19
+ enable_bookmarking:
20
+ ajax_markers:
21
+ ajax_url:
22
+ markers:
23
+ scroll_wheel_zoom_enabled:
24
+
25
+
26
+
27
+ @lat = options.delete(:lat) || @ck_config['map']['lat']
28
+ @long = options.delete(:long) || @ck_config['map']['long']
29
+ @map_control = options.delete(:map_control) || @ck_config['map']['map_control']['visible']
30
+ @map_control_type = options.delete(:map_control_type) || @ck_config['map']['map_control']['type'].to_sym
31
+ @zoom = options.delete(:zoom) || @ck_config['map']['zoom']
32
+ @style_id = options.delete(:style_id) || @ck_config['map']['style']['id']
33
+ @bounds = options.delete(:bounds) || @ck_config['map']['bounds']['enabled']
34
+ @bound_points = options.delete(:points) || 0
35
+ if @bounds && @bound_points == 0
36
+ raise "You must provide at least one point (via :bound_points) if you are using bounds set to true"
37
+ end
38
+ @bound_zoom = options.delete(:bound_zoom) || @ck_config['map']['bounds']['zoom'] #used when only a single point is passed to bound_points
39
+ @enable_bookmarking = options.delete(:enable_bookmarking) || @ck_config['map']['bookmarking']['enabled']
40
+ @ajax_markers = options.delete(:ajax_markers) || @ck_config['map']['markers']['ajax']['enabled']
41
+ @ajax_url = options.delete(:ajax_url) || @ck_config['map']['markers']['ajax']['url']
42
+ @markers = []
43
+ @disable_scroll_wheel_zoom = options.delete(:disable_scroll_wheel_zoom) || @ck_config['map']['scroll_wheel_zoom']['enabled']
44
+ end
45
+
46
+ def configure
47
+ app_root = RAILS_ROOT if defined?(RAILS_ROOT)
48
+ @ck_config = YAML.load( File.open("#{app_root}/config/cloud_kicker.yml", 'r') )
49
+ end
50
+
51
+ def to_js(map_id='map')
52
+ js = []
53
+ js << <<-JS
54
+ <script type=\"text/javascript\" src=\"#{CLOUDMADE_SRC}\"></script>
55
+ <script type="text/javascript">
56
+ $(document).ready(function() {
57
+
58
+ // create a new cloudmade tile object with our api key and the map style we want
59
+ var cloudmade = new CM.Tiles.CloudMade.Web({key: '#{CLOUDMADE_API_KEY}', styleId: #{@style_id}});
60
+
61
+ // create a new map object on the DOM element reference by map_id and the tile object above
62
+ var map = new CM.Map('#{map_id}', cloudmade);
63
+
64
+ // set up options here like turning on or off certain map features or setting the map center
65
+ JS
66
+
67
+ if @disableScrollWheelZoom
68
+ js << <<-JS
69
+ map.disableScrollWheelZoom();
70
+ JS
71
+ end
72
+
73
+ if @map_control
74
+ js << add_map_control(@map_control_type)
75
+ end
76
+
77
+ js << set_map_center(@lat, @long, @zoom, @bounds, @bound_points, @bound_zoom)
78
+
79
+ js << add_map_events(:ajax_markers => @ajax_markers,
80
+ :enable_bookmarking => @enable_bookmarking)
81
+
82
+ unless @ajax_markers
83
+ @markers.each do |marker|
84
+ js << marker
85
+ end
86
+ end
87
+
88
+ js << '}); //end $(document).ready'
89
+
90
+
91
+ if @ajax_markers
92
+ js << add_ajax_marker_functions(@ajax_url)
93
+ end
94
+
95
+ if @enable_bookmarking
96
+ js << add_bookmarking_functions
97
+ end
98
+
99
+ js << '</script>'
100
+ js.join("\n")
101
+ end
102
+
103
+ def markers
104
+ @markers
105
+ end
106
+
107
+ def bounding_box(points)
108
+ # lats = []
109
+ # longs = []
110
+ # points.each do |point|
111
+ # lats << point.latitude
112
+ # longs << point.longitude
113
+ # end
114
+ #
115
+ # max_lat = lats.max
116
+ # min_lat = lats.min
117
+ # max_long = longs.max
118
+ # min_long = longs.min
119
+ #
120
+ # north_east_lat = max_lat + (max_lat - min_lat)
121
+ # north_east_long = max_long + (max_long - min_long)
122
+ #
123
+ # south_west_lat = min_lat - (max_lat - min_lat)
124
+ # south_west_long = min_long - (max_long - min_long)
125
+
126
+ cloud_map_points = []
127
+
128
+ points.each do |point|
129
+ cloud_map_points << "new CM.LatLng(#{point.latitude}, #{point.longitude})"
130
+ end
131
+
132
+ "new CM.LatLngBounds(#{cloud_map_points.join(',')})"
133
+ end
134
+ end
135
+
136
+ end
@@ -0,0 +1,82 @@
1
+ module Cloudkicker
2
+ module AjaxMarkers
3
+
4
+ def add_ajax_marker_functions(url)
5
+ js = []
6
+ js << add_marker_function
7
+ js << get_map_points_function(url)
8
+ return js
9
+ end
10
+
11
+ def add_marker_function
12
+ <<-JS
13
+ function add_markers(markers) {
14
+ $.each(added_markers, function(i, added_marker){
15
+ map.removeOverlay(added_marker);
16
+ });
17
+ added_markers = [];
18
+
19
+ $.each(markers, function(i, marker){
20
+ var myMarkerLatLng = new CM.LatLng(marker.lat,marker.lng);
21
+
22
+ var icon = new CM.Icon();
23
+ if(marker.tower) {
24
+ icon.image = "/images/dot_med.png";
25
+ }
26
+ else
27
+ {
28
+ icon.image = "/images/dot_med_blue.png";
29
+ }
30
+
31
+ icon.iconSize = new CM.Size(21, 21);
32
+ //icon.shadow = "/images/map_marker_shadow.png";
33
+ //icon.shadowSize = new CM.Size(31, 48);
34
+ //icon.iconAnchor = new CM.Point(20, 48);
35
+
36
+ var myMarker = new CM.Marker(myMarkerLatLng, {
37
+ title: marker.licensee,
38
+ icon: icon
39
+ });
40
+
41
+ CM.Event.addListener(myMarker, 'click', function(latlng){
42
+ if(marker.tower) {
43
+ map.openInfoWindow(myMarkerLatLng, parseTemplate($("#cell_tower_template").html(), marker), {maxWidth: 400, pixelOffset: new CM.Size(0,-10)});
44
+ }
45
+ else
46
+ {
47
+ map.openInfoWindow(myMarkerLatLng, parseTemplate($("#cell_site_template").html(), marker), {maxWidth: 400, pixelOffset: new CM.Size(0,-10)});
48
+ }
49
+ });
50
+
51
+
52
+ added_markers.push(myMarker);
53
+ map.addOverlay(myMarker);
54
+ });
55
+
56
+ $('.mapMarkerLoader img').hide();
57
+ }
58
+ JS
59
+ end
60
+
61
+ def get_map_points_function(url)
62
+ <<-JS
63
+ function getMapPoints(CMBounds) {
64
+ var sw_CMLatLng = CMBounds.getSouthWest();
65
+ var sw_point = [sw_CMLatLng.lat(), sw_CMLatLng.lng()]
66
+ var ne_CMLatLng = CMBounds.getNorthEast();
67
+ var ne_point = [ne_CMLatLng.lat(), ne_CMLatLng.lng()]
68
+
69
+ $.ajax({
70
+ type:"GET",
71
+ url:'#{url}',
72
+ data:"per_page=200&fields=limited&search[conditions][descend_by_created_at]=1&search[conditions][within_bounds][sw_point][]=" + sw_point[0] + "&search[conditions][within_bounds][sw_point][]=" + sw_point[1] + "&search[conditions][within_bounds][ne_point][]=" + ne_point[0] + "&search[conditions][within_bounds][ne_point][]=" + ne_point[1],
73
+ dataType:'json',
74
+ success: add_markers
75
+ });
76
+ }
77
+
78
+ JS
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,62 @@
1
+ module Cloudkicker
2
+ class Marker
3
+ def initialize(options={})
4
+ raise 'Map is required' unless options[:map]
5
+ raise 'Lat is required' unless options[:lat]
6
+ raise 'Long is required' unless options[:long]
7
+ @map = options.delete(:map)
8
+ @lat = options.delete(:lat)
9
+ @long = options.delete(:long)
10
+ @id = self.object_id
11
+ @title = options.delete(:title) || ''
12
+ @info = options.delete(:info) || ''
13
+
14
+
15
+ @info.gsub!(/\s+/, ' ')
16
+ @max_width = options.delete(:info_max_width) || 400
17
+ add_marker
18
+ end
19
+
20
+ private
21
+
22
+ def add_marker
23
+ js = []
24
+ js << create_marker(@id, @lat, @long, @title)
25
+ js << add_info_window_to_marker(@id, @info, @max_width)
26
+ js << ''
27
+ # js << ' map.setCenter(myMarkerLatLng, 14);'
28
+ js << " map.addOverlay(myMarker_#{@id});"
29
+
30
+ @map.markers << js.join("\n")
31
+ end
32
+
33
+ def create_marker(id, lat, long, title)
34
+ <<-JS
35
+ var myMarkerLatLng_#{id} = new CM.LatLng(#{lat},#{long});
36
+ var icon = new CM.Icon();
37
+
38
+ icon.image = "/images/map_marker.png";
39
+ icon.iconSize = new CM.Size(31, 48);
40
+ icon.shadow = "/images/map_marker_shadow.png";
41
+ icon.shadowSize = new CM.Size(31, 48);
42
+ icon.iconAnchor = new CM.Point(20, 48);
43
+
44
+ var myMarker_#{id} = new CM.Marker(myMarkerLatLng_#{id}, {
45
+ title: '#{title}',
46
+ icon: icon
47
+ });
48
+ JS
49
+ end
50
+
51
+ def add_info_window_to_marker(id, info, max_width)
52
+ # Add listener to marker
53
+ # TODO single quotes should be esacaped not deleted. Escaping doesn't seem to be working at the moment though... clearly missing something
54
+ <<-JS
55
+ CM.Event.addListener(myMarker_#{id}, 'click', function(latlng) {
56
+ map.openInfoWindow(myMarkerLatLng_#{id}, '#{info.gsub(/'/,"")}', {maxWidth: #{max_width}, pixelOffset: new CM.Size(-8,-50)});
57
+ });
58
+ JS
59
+ end
60
+
61
+ end
62
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'cloud_kicker'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCloudKicker < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud_kicker
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ - pre1
10
+ version: 0.0.0.pre1
11
+ platform: ruby
12
+ authors:
13
+ - Bob Burbach
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-28 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: " Rails abstraction layer for creating maps using the Cloudmade web framework. Makes creating maps with custom \n color schemes, ajax markers and customizable marker info windows quick and easy.\n"
34
+ email: govpulse@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.rdoc
42
+ files:
43
+ - .document
44
+ - .gitignore
45
+ - LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - VERSION
49
+ - cloud_kicker.gemspec
50
+ - example/cloud_kicker.yml
51
+ - lib/critical_juncture/cloud_kicker.rb
52
+ - lib/critical_juncture/control_elements.rb
53
+ - lib/critical_juncture/map.rb
54
+ - lib/critical_juncture/map/map_bookmarking.rb
55
+ - lib/critical_juncture/map/map_events.rb
56
+ - lib/critical_juncture/map/map_location.rb
57
+ - lib/critical_juncture/markers/ajax_markers.rb
58
+ - lib/critical_juncture/markers/marker.rb
59
+ - test/helper.rb
60
+ - test/test_cloud_kicker.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/trifecta/cloud_kicker
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">"
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 3
84
+ - 1
85
+ version: 1.3.1
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Rails abstraction layer for creating maps using the Cloudmade web framework.
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/test_cloud_kicker.rb