Permalink
Browse files

Minor clean up

  • Loading branch information...
1 parent 700cb21 commit 99a144f5528bad48112fdf35115262204a656288 @yawningman yawningman committed Apr 25, 2009
View
@@ -1,49 +0,0 @@
-h2. N.B:
-
- * In some places the 'map' variable is directly referenced and will cause issues if there are two maps
- or a map with a name other than map. Suggest making the Google::Map avaible globally through some interface.
-
- * Track the "maps" that the user has created by keeping a hash by name, the main map being called "main".
- Other objects can then refer to these maps using the abstraction
-
-h2. Intuitive Marker updates
-
- * The :draggable logic for 'hiding' the info window when the marker is 'picked up'
- can perhaps detect if an info window was open and then 'show' it again when the marker is 'dropped',
- this seems intuitive
-
-h2. Eschaton general
-
- * When in ruby and ruby objects are availble return those, otherwise return their javascript equivalents in the form of strings.
- i.e if map.center = Google::Location return that, otherwise return 'map.getCenter()'. This will make sure "predictable" results occur when the generated
- script executes
-
-h2. Eschaton dev
-
- * See Google::Circle and refactor into various 'shape' classes.
- Rename draw_circle in eschaton.js to 'draw_shape' and metafy as need be!
-
- * Eschaton generator to generate eschaton slices in the 'lib' folder.
-
-h2. Eschaton Enhancments
-
- * map.add_lines :from => location, :to => [other_location, another_location], :thickness => 10, :opacity => 0.7
-
- * Map#add_geo_rss(url) : Render a geo rss feed on the map
-
- * Keyboard navigation needs focus on div, sort this, how ???
-
-h2. Higher level ideas, trippy shit
-
- * Have a concept of 'marker' groups, in which you can add markers to these groups and perform actions on the groups.
- Say we have two groups, 'Wikipedia' and 'Flickr' and marker in each group. We could then say stuff like
- wikipedia_group.show && flickr_group.hide or wikipedia_group.hide && flickr_group.show.
-
- Basically to get a handle of groups of markers and perform actions on them.
- Perhpas we could treat all overlays like this(markers, lines etc)
-
- * Abstract the concept of a "route", have the abilty to add "Waypoints" to the route that can have a marker, tooltip and info
- window etc. This should be an eschaton plugin
-
- * Integrate with google spreadsheets so that spreadsheet data with a 'name' and 'location' column can be shown on the map,
- that would be slick to show people!
View
@@ -5,8 +5,6 @@ Google Maps and Rails. If you have an issue please feed-it-back on Github issues
Enough talk, lets code!
- #-----------------------------------------------------------------#
-
map = Google::Map.new(:center => {:latitude => -33.947, :longitude => 18.462},
:controls => [:large_map_3D, :map_type])
@@ -15,9 +13,9 @@ Enough talk, lets code!
marker = map.add_marker :location => location
marker.open_info_window :text => 'Awesome, you added a marker!'
end
-
- #-----------------------------------------------------------------#
-
+
+...
+
# Create a satellite map, zoomed at 16.
map = Google::Map.new(:controls => [:small_map, :map_type],
:type => :satellite, :zoom => 16)
@@ -31,13 +29,13 @@ Enough talk, lets code!
# ... and draw a line in between them
map.add_line :between_markers => markers, :tooltip => {:text => "Short Hike I do everyday with my dog"}
- #-----------------------------------------------------------------#
+...
# Draw a polygon, yellow with a green border ..
map.add_polygon :vertices => [[-34.2023, 18.3794], [-34.2029, 18.3797], [-34.2022, 18.3811]],
:fill_colour => 'yellow', :border_colour => 'green'
- #-----------------------------------------------------------------#
+...
# A draggable marker that talks when its being dragged and dropped
marker = map.add_marker :location => {:latitude => -33.947, :longitude => 18.462},
@@ -53,7 +51,7 @@ Enough talk, lets code!
marker.open_info_window :text => "Yes, I was getting tired of flying..."
end
-and always remember...
+and remember that
{:latitude => -33.947, :longitude => 18.462} == [-33.947, 18.462]
@@ -1,13 +1,35 @@
module Eschaton
# Helps with writing methods that take a +options+ hash.
+ #
+ # ==== Examples
+ # # A sample initializer in which the PreparedOptions is used.
+ # def initialize(options = {})
+ # prepared_options = options.prepare_options do |prepared_options|
+ # prepared_options.default! :var => :map, :center => :best_fit, :zoom => :best_fit,
+ # :keyboard_navigation => false
+ #
+ # prepared_options.validate_presence_of :center, :controls, :zoom, :type,
+ # :keyboard_navigation
+ # end
+ #
+ # # ...work with prepared options here
+ # end
class PreparedOptions
def initialize(options = {})
self.options = options.clone
self.options.symbolize_keys!
end
-
+
+ # Used to access option values.
+ #
+ # If a single option is passed in the single value is returned.
+ # prepared_options[:name] #=> "yawningman"
+ # prepared_options[:project] #=> "eschaton"
+ #
+ # If multiple options are passed in, a hash of those options is returned.
+ # prepared_options[:name, :project] #=> {:name => "yawningman", :project => "eschaton"}
def [](*options)
if options.size == 1
self.options[options.first]
@@ -22,32 +44,60 @@ def [](*options)
end
end
+ # Assigns an option a value.
+ #
+ # prepared_options[:name] => "yawningman"
+ # prepared_options[:project] => "eschaton"
def []=(option, value)
self.options[option] = value
end
# Returns a value indicating if the +option+ is present.
+ #
+ # prepared_options = PreparedOptions.new(:name => "yawningman")
+ #
+ # prepared_options.has_option?(:name) #=> true
+ # prepared_options.has_option?(:project) #=> false
def has_option?(option)
self.options.has_key?(option)
end
# Returns a value indicating if the +option+ has a value.
+ #
+ # prepared_options = PreparedOptions.new(:name => "yawningman", :project => nil)
+ #
+ # prepared_options.has_value?(:name) #=> true
+ # prepared_options.has_value?(:project) #=> false
def has_value?(option)
self[option].not_nil?
end
- # Defaults options if they are not present of have a nil value.
+ # Defaults options if they are not present or have a nil value.
+ #
+ # prepared_options = PreparedOptions.new(:name => "yawningman", :project => nil)
+ # prepared_options.default! :zoom_level => 10, :project => "eschaton"
#
- # prepared_options.default! :always_sync => true, :sync_interval => 10.seconds
+ # prepared_options[:zoom_level] #=> 10
+ # prepared_options[:project] #=> "eschaton"
def default!(defaults)
defaults.each do |option, default_value|
self[option] = default_value unless self.has_value?(option)
end
end
- # Validates that the given +options+ are present and do not have blank values
+ # Validates that the given +options+ are present and do not have blank values.
+ # If the validation fails, a ArgumentError will be raised indicating what required options
+ # are missing.
+ #
+ # prepared_options = PreparedOptions.new(:name => "yawningman", :project => nil)
+ #
+ # prepared_options.validate_presence_of :name, :project #=> Raises ArgumentError
+ #
+ # prepared_options[:project] = ''
+ # prepared_options.validate_presence_of :name, :project #=> Raises ArgumentError
#
- # prepared_options.validate_presence_of :name, :project
+ # prepared_options[:project] = 'eschaton'
+ # prepared_options.validate_presence_of :name, :project #=> No error raised
def validate_presence_of(*options)
missing_options = options.select do |required_option|
self[required_option].blank?
@@ -71,7 +121,7 @@ def update(option)
self[option] = yield(self[option])
end
- def inspect
+ def inspect # :nodoc:
output = "#{self.options.size} Options:\n"
self.options.each do |option, value|
@@ -19,13 +19,5 @@ def run_javascript(&block)
Eschaton.with_global_script script, &block
end
end
-
- def link_to_presentation_model(model_name, name)
- link_to_function name do |script|
- Eschaton.with_global_script(script) do
- yield model_name.presentation_modelify.new(script)
- end
- end
- end
end
@@ -9,21 +9,34 @@ class Bounds < MapObject
# * +south_west_point+ - Optional. The south west point of the rectangle.
# * +north_east_point+ - Optional. The north east point of the rectangle.
def initialize(options = {})
- options.default!
+ options.default! :var => :bounds
super
self.south_west_point = Google::OptionsHelper.to_location(options[:south_west_point])
self.north_east_point = Google::OptionsHelper.to_location(options[:north_east_point])
- end
- def to_s
- "new GLatLngBounds(#{self.south_west_point.to_js}, #{self.north_east_point.to_js})"
+ if create_var?
+ points = [self.south_west_point, self.north_east_point].compact
+ self << "#{self.var} = new GLatLngBounds(#{points.join(', ')});"
+ end
+ end
+
+ # Extends the bounds with the given +locations+. Which can be Location or Bounds.
+ def extend(*locations)
+ locations.arify.each do |location|
+ if location.is_a?(Google::Bounds)
+ self << "#{self}.extend(#{location.south_west_point});"
+ self << "#{self}.extend(#{location.north_east_point});"
+ else
+ location = Google::OptionsHelper.to_location(location)
+ self << "#{self}.extend(#{location});"
+ end
+ end
end
- alias to_js to_s
- def to_json(options = nil)
- to_js
+ def center
+ "#{self}.getCenter()"
end
protected
@@ -3,6 +3,29 @@ module Google
# Represents a overlay that can be added to a Map using Map#add_ground_overlay. If a method or event is not documented here please
# see googles online[http://code.google.com/apis/maps/documentation/reference.html#GGroundOverlay] docs for details.
# See MapObject#listen_to on how to use # events not listed on this object.
+ #
+ # ==== Examples:
+ #
+ # The below samples where taken from here[http://graargh.returnstrue.com/rajdeep/maps/iiml/customlayout3/iiml_campuslayout_7.html].
+ # Credit goes to Rajdeep Dua for creating the original example.
+ #
+ # # Using points
+ # map.add_ground_overlay :image => "http://graargh.returnstrue.com/rajdeep/maps/iiml/customlayout3/base_combined_16.jpg",
+ # :south_west_point => [26.9303, 80.888], :north_east_point => [26.9417, 80.909]
+ #
+ # bounds = Google::Bounds.new(:south_west_point => [26.930, 80.888], :north_east_point => [26.941, 80.909])
+ #
+ # Using the bounds options with a Google::Bounds object(many overlays can now use this same bounds object)
+ # map.add_ground_overlay :image => "http://graargh.returnstrue.com/rajdeep/maps/iiml/customlayout3/base_combined_16.jpg",
+ # :bounds => bounds
+ #
+ # Using the bounds option with a hash(quite long but clear)
+ # map.add_ground_overlay :image => "http://graargh.returnstrue.com/rajdeep/maps/iiml/customlayout3/base_combined_16.jpg",
+ # :bounds => {:south_west_point => [26.930, 80.888], :north_east_point => [26.941, 80.909]}
+ #
+ # # Using the bounds option with a array
+ # map.add_ground_overlay :image => "http://graargh.returnstrue.com/rajdeep/maps/iiml/customlayout3/base_combined_16.jpg",
+ # :bounds => [[26.930, 80.888], [26.941, 80.909]]
class GroundOverlay < MapObject
attr_reader :bounds, :image
Oops, something went wrong. Retry.

0 comments on commit 99a144f

Please sign in to comment.