ym4r 0.0.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +24 -8
- data/lib/ym4r.rb +3 -4
- data/lib/ym4r/google_maps.rb +7 -0
- data/lib/ym4r/google_maps/api_key.rb +10 -0
- data/lib/ym4r/google_maps/config/config.yml +1 -0
- data/lib/ym4r/google_maps/control.rb +59 -0
- data/lib/ym4r/google_maps/helper.rb +19 -0
- data/lib/ym4r/google_maps/map.rb +94 -0
- data/lib/ym4r/google_maps/mapping.rb +70 -0
- data/lib/ym4r/google_maps/overlay.rb +125 -0
- data/lib/ym4r/google_maps/point.rb +34 -0
- data/lib/ym4r/yahoo_maps.rb +2 -0
- data/lib/ym4r/yahoo_maps/app_id.rb +5 -0
- data/lib/ym4r/yahoo_maps/building_block.rb +4 -0
- data/lib/ym4r/yahoo_maps/building_block/exception.rb +21 -0
- data/lib/ym4r/yahoo_maps/building_block/geocoding.rb +81 -0
- data/lib/ym4r/yahoo_maps/building_block/local_search.rb +156 -0
- data/lib/ym4r/yahoo_maps/building_block/map_image.rb +75 -0
- data/lib/ym4r/yahoo_maps/building_block/traffic.rb +120 -0
- data/lib/ym4r/yahoo_maps/flash.rb +7 -0
- data/lib/ym4r/yahoo_maps/flash/latlon.rb +18 -0
- data/lib/ym4r/yahoo_maps/flash/map.rb +74 -0
- data/lib/ym4r/yahoo_maps/flash/mapping.rb +71 -0
- data/lib/ym4r/yahoo_maps/flash/marker.rb +43 -0
- data/lib/ym4r/yahoo_maps/flash/overlay.rb +44 -0
- data/lib/ym4r/yahoo_maps/flash/tool.rb +30 -0
- data/lib/ym4r/yahoo_maps/flash/widget.rb +33 -0
- data/rakefile.rb +4 -4
- data/test/test_geocoding.rb +3 -3
- data/test/test_local_search.rb +2 -2
- data/test/test_map_image.rb +3 -3
- data/test/test_maps.rb +14 -0
- data/test/test_traffic.rb +1 -1
- metadata +30 -9
- data/lib/ym4r/app_id.rb +0 -3
- data/lib/ym4r/building_block/geocoding.rb +0 -81
- data/lib/ym4r/building_block/local_search.rb +0 -156
- data/lib/ym4r/building_block/map_image.rb +0 -76
- data/lib/ym4r/building_block/traffic.rb +0 -120
- data/lib/ym4r/exception.rb +0 -18
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'ym4r/yahoo_maps/app_id'
|
2
|
+
require 'ym4r/yahoo_maps/flash/mapping'
|
3
|
+
require 'ym4r/yahoo_maps/flash/latlon'
|
4
|
+
require 'ym4r/yahoo_maps/flash/marker'
|
5
|
+
require 'ym4r/yahoo_maps/flash/widget'
|
6
|
+
require 'ym4r/yahoo_maps/flash/tool'
|
7
|
+
require 'ym4r/yahoo_maps/flash/overlay'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
class LatLon < Struct.new(:lat,:lon)
|
5
|
+
include MappingObject
|
6
|
+
def create
|
7
|
+
"new LatLon(#{lat},#{lon})"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class LatLonRect < Struct.new(:min_lat, :min_lon, :max_lat, :max_lon)
|
11
|
+
include MappingObject
|
12
|
+
def create
|
13
|
+
"new LatLonRect(#{min_lat},#{min_lon},#{max_lat},#{max_lon})"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
|
5
|
+
module MapViews
|
6
|
+
MAP = Variable.new("MapViews.MAP")
|
7
|
+
HYBRID = Variable.new("MapViews.HYBRID")
|
8
|
+
SATELLITE = Variable.new("MapViews.SATELLITE")
|
9
|
+
end
|
10
|
+
|
11
|
+
class Map
|
12
|
+
include MappingObject
|
13
|
+
|
14
|
+
attr_reader :container
|
15
|
+
attr_accessor :zoom, :latlon, :location, :view_type
|
16
|
+
|
17
|
+
EVENT_INITIALIZE = "Map.EVENT_INITIALIZE"
|
18
|
+
EVENT_MAP_GEOCODE_ERROR = "Map.EVENT_MAP_GEOCODE_ERROR"
|
19
|
+
EVENT_MAP_GEOCODE_SUCCESS = "Map.EVENT_MAP_GEOCODE_SUCCESS"
|
20
|
+
EVENT_MARKER_GEOCODE_ERROR = "Map.EVENT_MARKER_GEOCODE_ERROR"
|
21
|
+
EVENT_MARKER_GEOCODE_SUCCESS = "Map.EVENT_MARKER_GEOCODE_SUCCESS"
|
22
|
+
EVENT_MOVE = "Map.EVENT_MOVE"
|
23
|
+
EVENT_PAN_START = "Map.EVENT_PAN_START"
|
24
|
+
EVENT_PAN_STOP = "Map.EVENT_PAN_STOP"
|
25
|
+
EVENT_TOOL_ADDED = "Map.EVENT_TOOL_ADDED"
|
26
|
+
EVENT_TOOL_CHANGE = "Map.EVENT_TOOL_CHANGE"
|
27
|
+
EVENT_TOOL_REMOVED = "Map.EVENT_TOOL_REMOVED"
|
28
|
+
EVENT_ZOOM = "Map.EVENT_ZOOM"
|
29
|
+
EVENT_ZOOM_STOP = "Map.EVENT_ZOOM_STOP"
|
30
|
+
EVENT_ZOOM_START = "Map.EVENT_ZOOM_START"
|
31
|
+
|
32
|
+
#+container+ is the DIV element in the page that will host the SWF map
|
33
|
+
def initialize(container, options={})
|
34
|
+
@container = container
|
35
|
+
@latlon = options[:latlon]
|
36
|
+
@location = options[:location] || ""
|
37
|
+
@zoom = options[:zoom] || 14
|
38
|
+
@view_type = options[:view_type] || MapViews::MAP
|
39
|
+
@init = ""
|
40
|
+
end
|
41
|
+
|
42
|
+
#returns HTML code to add the necessary include and css code to initialize the map
|
43
|
+
def header
|
44
|
+
"<script type='text/javascript' src='http://api.maps.yahoo.com/v3.0/fl/javascript/apiloader.js?appid=#{Ym4r::APP_ID}'></script>\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
def header_width_height(width,height)
|
48
|
+
"<style type='text/css'>\n##{@container} {\n height: #{@height}px;\n width: #{@width}px;\n}\n</style>\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
def record_init(code)
|
52
|
+
@init << code
|
53
|
+
end
|
54
|
+
|
55
|
+
#creates the map and add any initialization javascript code returned by the block (like addition of a set of initial markers or other custom code).
|
56
|
+
def to_html(with_script_tag = true)
|
57
|
+
html = ""
|
58
|
+
html << "<script type=\"text/javascript\">\n" if with_script_tag
|
59
|
+
html << @init
|
60
|
+
html << "</script>\n" if with_script_tag
|
61
|
+
html
|
62
|
+
end
|
63
|
+
|
64
|
+
def create
|
65
|
+
unless @latlon.nil?
|
66
|
+
"new Map('#{@container}','#{Ym4r::APP_ID}',#{@latlon.to_javascript},#{@zoom},#{@view_type.to_javascript})"
|
67
|
+
else
|
68
|
+
"new Map('#{@container}','#{Ym4r::APP_ID}','#{@location}',#{@zoom},#{@view_type.to_javascript})"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
|
5
|
+
module MappingObject
|
6
|
+
attr_reader :variable
|
7
|
+
|
8
|
+
#special method for add_event_listener since the user need to pass reference to methods and the general method_missing won't work for that
|
9
|
+
def add_event_listener(event, method, context)
|
10
|
+
"#{to_javascript}.addEventListener(#{event},#{method},#{context});\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def remove_event_listener(event, method, context)
|
14
|
+
"#{to_javascript}.removeEventListener(#{event},#{method},#{context});\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
#creates javascript code for missing methods
|
18
|
+
def method_missing(name,*args)
|
19
|
+
args.collect! do |arg|
|
20
|
+
if arg.is_a?(MappingObject)
|
21
|
+
arg.to_javascript
|
22
|
+
elsif arg.is_a?(String)
|
23
|
+
"\"#{escape_javascript(arg)}\""
|
24
|
+
else
|
25
|
+
arg.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"#{to_javascript}.#{javascriptify(name.to_s)}(#{args.join(",")});\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
#lifted from rails
|
32
|
+
def escape_javascript(javascript)
|
33
|
+
javascript.gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
34
|
+
end
|
35
|
+
|
36
|
+
#transform a ruby-type method name (like qsd_fghj) to a Yahoo! Map style one (like qsdFghj)
|
37
|
+
def javascriptify(method_name)
|
38
|
+
method_name.gsub(/_(\w)/){|s| $1.upcase}
|
39
|
+
end
|
40
|
+
|
41
|
+
#Declare Mapping Object (Map, Tool, Marker,...) of name variable
|
42
|
+
def declare(variable)
|
43
|
+
@variable = variable
|
44
|
+
"var #{variable} = #{create};\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
#Returns a Javascript script representing the object
|
48
|
+
def to_javascript
|
49
|
+
unless @variable.nil?
|
50
|
+
@variable
|
51
|
+
else
|
52
|
+
create
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#Creates a Mapping Object in Javascript
|
57
|
+
#To be implemented by subclasses if needed
|
58
|
+
def create
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Variable
|
63
|
+
include MappingObject
|
64
|
+
|
65
|
+
def initialize(variable)
|
66
|
+
@variable = variable
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
module Marker
|
5
|
+
EVENT_INITIALIZE = "Marker.EVENT_INITIALIZE"
|
6
|
+
end
|
7
|
+
|
8
|
+
class CustomPOIMarker < Struct.new(:index, :title, :description, :marker_color, :stroke_color)
|
9
|
+
include MappingObject
|
10
|
+
|
11
|
+
def create
|
12
|
+
"new CustomPOIMarker('#{index}','#{title}','#{description}','#{marker_color}','#{stroke_color}')";
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class CustomImageMarker < Struct.new(:url)
|
17
|
+
include MappingObject
|
18
|
+
|
19
|
+
def create
|
20
|
+
"new CutomImageMarker('#{url}')"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class CustomSWFMarker < Struct.new(:url)
|
25
|
+
include MappingObject
|
26
|
+
|
27
|
+
def create
|
28
|
+
"new CustomSWFMarker('#{url}')"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class WaypointMarker < Struct.new(:index)
|
33
|
+
include MappingObject
|
34
|
+
|
35
|
+
def create
|
36
|
+
"new WaypointMarker('#{index}')"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
module Overlay
|
5
|
+
EVENT_INITIALIZE = "Overlay.EVENT_INITIALIZE"
|
6
|
+
end
|
7
|
+
|
8
|
+
class CustomSWFOverlay < Struct.new(:url)
|
9
|
+
include MappingObject
|
10
|
+
|
11
|
+
def create
|
12
|
+
"new CustomSWFOverlay('#{url}')"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class GeoRSSOverlay < Struct.new(:url)
|
17
|
+
include MappingObject
|
18
|
+
|
19
|
+
def create
|
20
|
+
"new GeoRSSOverlay('#{url}')"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class LocalSearchOverlay
|
25
|
+
include MappingObject
|
26
|
+
|
27
|
+
EVENT_SEARCH_ERROR = "LocalSearchOverlay.EVENT_SEARCH_ERROR"
|
28
|
+
EVENT_SEARCH_SUCCESS = "LocalSearchOverlay.EVENT_SEARCH_SUCCESS"
|
29
|
+
|
30
|
+
def create
|
31
|
+
"new LocalSearchOverlay()"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class TrafficOverlay
|
36
|
+
include MappingObject
|
37
|
+
|
38
|
+
def create
|
39
|
+
"new TrafficOverlay()"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
module Tool
|
5
|
+
EVENT_INITIALIZE = "Tool.EVENT_INITIALIZE"
|
6
|
+
end
|
7
|
+
|
8
|
+
class CustomSWFTool < Struct.new(:url,:icon_url)
|
9
|
+
include MappingObject
|
10
|
+
|
11
|
+
EVENT_LOADED = "CustomSWFTool.EVENT_LOADED"
|
12
|
+
|
13
|
+
def create
|
14
|
+
"new CustomSWFTool('#{url}','#{icon_url}')"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class PanTool
|
19
|
+
include MappingObject
|
20
|
+
|
21
|
+
EVENT_DRAG_STOP = "PanTool.EVENT_DRAG_STOP"
|
22
|
+
EVENT_DRAG_START = "PanTool.EVENT_DRAG_START"
|
23
|
+
|
24
|
+
def create
|
25
|
+
"new PanTool()"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ym4r
|
2
|
+
module YahooMaps
|
3
|
+
module Flash
|
4
|
+
module Widget
|
5
|
+
EVENT_INITIALIZE = "Widget.EVENT_INITIALIZE"
|
6
|
+
end
|
7
|
+
|
8
|
+
class NavigatorWidget
|
9
|
+
include MappingObject
|
10
|
+
|
11
|
+
def create
|
12
|
+
"new NavigatorWidget()"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class SatelliteControlWidget
|
17
|
+
include MappingObject
|
18
|
+
|
19
|
+
def create
|
20
|
+
"new SatelliteControlWidget()"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class ToolBarWidget
|
25
|
+
include MappingObject
|
26
|
+
|
27
|
+
def create
|
28
|
+
"new ToolBarWidget()"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/rakefile.rb
CHANGED
@@ -14,7 +14,7 @@ end
|
|
14
14
|
desc "Generate the documentation"
|
15
15
|
Rake::RDocTask::new do |rdoc|
|
16
16
|
rdoc.rdoc_dir = 'ym4r-doc/'
|
17
|
-
rdoc.title = "
|
17
|
+
rdoc.title = "YM4R Documentation"
|
18
18
|
rdoc.options << '--line-numbers' << '--inline-source'
|
19
19
|
rdoc.rdoc_files.include('README')
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
@@ -24,8 +24,8 @@ spec = Gem::Specification::new do |s|
|
|
24
24
|
s.platform = Gem::Platform::RUBY
|
25
25
|
|
26
26
|
s.name = 'ym4r'
|
27
|
-
s.version = "0.
|
28
|
-
s.summary = "Using
|
27
|
+
s.version = "0.1.2"
|
28
|
+
s.summary = "Using Google Maps and Yahoo! Maps from Ruby and Rails"
|
29
29
|
s.description = <<EOF
|
30
30
|
EOF
|
31
31
|
s.author = 'Guilhem Vellut'
|
@@ -34,7 +34,7 @@ EOF
|
|
34
34
|
|
35
35
|
s.requirements << 'none'
|
36
36
|
s.require_path = 'lib'
|
37
|
-
s.files = FileList["lib/**/*.rb", "test/**/*.rb", "README","MIT-LICENSE","rakefile.rb"]
|
37
|
+
s.files = FileList["lib/**/*.rb", "lib/**/*.yml","test/**/*.rb", "README","MIT-LICENSE","rakefile.rb"]
|
38
38
|
s.test_files = FileList['test/test*.rb']
|
39
39
|
|
40
40
|
s.has_rdoc = true
|
data/test/test_geocoding.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
3
3
|
require 'ym4r'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
|
-
include Ym4r::BuildingBlock
|
6
|
+
include Ym4r::YahooMaps::BuildingBlock
|
7
7
|
|
8
8
|
class TestGeocoding< Test::Unit::TestCase
|
9
9
|
|
@@ -27,11 +27,11 @@ class TestGeocoding< Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_garbage_location
|
30
|
-
assert_raise(
|
30
|
+
assert_raise(BadRequestException) {Geocoding::get(:location => "AZEAEAEAEAEAE")}
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_no_location
|
34
|
-
assert_raise(
|
34
|
+
assert_raise(MissingParameterException) {Geocoding::get(:hello => "world")}
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
data/test/test_local_search.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
3
3
|
require 'ym4r'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
|
-
include Ym4r::BuildingBlock
|
6
|
+
include Ym4r::YahooMaps::BuildingBlock
|
7
7
|
|
8
8
|
class TestLocalSearch< Test::Unit::TestCase
|
9
9
|
|
@@ -40,7 +40,7 @@ class TestLocalSearch< Test::Unit::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_no_query
|
43
|
-
assert_raise(
|
43
|
+
assert_raise(MissingParameterException) do
|
44
44
|
LocalSearch::get(:street => "1 Infinite Loop",
|
45
45
|
:city => "Cupertino",
|
46
46
|
:state => "CA",
|
data/test/test_map_image.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
3
3
|
require 'ym4r'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
|
-
include Ym4r::BuildingBlock
|
6
|
+
include Ym4r::YahooMaps::BuildingBlock
|
7
7
|
|
8
8
|
class TestMapImage< Test::Unit::TestCase
|
9
9
|
|
@@ -21,11 +21,11 @@ class TestMapImage< Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_no_location
|
24
|
-
assert_raise(
|
24
|
+
assert_raise(MissingParameterException) {MapImage::get(:image_type => "gif")}
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_bad_parameter
|
28
|
-
assert_raise(
|
28
|
+
assert_raise(BadRequestException) do
|
29
29
|
MapImage::get(:street => "1 Infinite Loop",
|
30
30
|
:city => "Cupertino",
|
31
31
|
:state => "CA",
|
data/test/test_maps.rb
ADDED