Class Ym4r::GmPlugin::GMarker
In: lib/gm_plugin/overlay.rb
Parent: Object

A graphical marker positionned through geographic coordinates (in the WGS84 datum). An HTML info window can be set to be displayed when the marker is clicked on.

Methods

create   new  

Included Modules

MappingObject

Attributes

address  [RW] 
info_window  [RW] 
info_window_tabs  [RW] 
options  [RW] 
point  [RW] 

Public Class methods

The points argument can be either a GLatLng object or an array of 2 floats. The options keys can be: :icon, :clickable, :title, :info_window and :info_window_tabs, as well as :max_width. The value of the info_window key is a string of HTML code that will be displayed when the markers is clicked on. The value of the info_window_tabs key is an array of GInfoWindowTab objects or a hash directly, in which case it will be transformed to an array of GInfoWindowTabs, with the keys as the tab headers and the values as the content.

[Source]

    # File lib/gm_plugin/overlay.rb, line 8
 8:       def initialize(position, options = {})
 9:         if position.is_a?(Array)
10:           @point = GLatLng.new(position)
11:         elsif position.is_a?(String)
12:           @point = Variable.new("INVISIBLE") #default coordinates: won't appear anyway
13:           @address = position
14:         else
15:           @point = position
16:         end
17:         @info_window = options.delete(:info_window)
18:         @info_window_tabs = options.delete(:info_window_tabs)
19:         if options.has_key?(:max_url)
20:           @info_window_options = {:max_url => options.delete(:max_url) } 
21:         else
22:           @info_window_options = {}
23:         end
24:         @options = options
25:       end

Public Instance methods

Creates a marker: If an info_window or info_window_tabs is present, the response to the click action from the user is setup here.

[Source]

    # File lib/gm_plugin/overlay.rb, line 27
27:       def create
28:         if @options.empty?
29:           creation = "new GMarker(#{MappingObject.javascriptify_variable(@point)})"
30:         else
31:           creation = "new GMarker(#{MappingObject.javascriptify_variable(@point)},#{MappingObject.javascriptify_variable(@options)})"
32:         end
33:         if @info_window && @info_window.is_a?(String)
34:           creation = "addInfoWindowToMarker(#{creation},#{MappingObject.javascriptify_variable(@info_window)},#{MappingObject.javascriptify_variable(@info_window_options)})"
35:         elsif @info_window_tabs && @info_window_tabs.is_a?(Hash)
36:           creation = "addInfoWindowTabsToMarker(#{creation},#{MappingObject.javascriptify_variable(@info_window_tabs.to_a.collect{|kv| GInfoWindowTab.new(kv[0],kv[1] ) })},#{MappingObject.javascriptify_variable(@info_window_options)})"
37:         elsif @info_window_tabs 
38:           creation = "addInfoWindowTabsToMarker(#{creation},#{MappingObject.javascriptify_variable(Array(@info_window_tabs))},#{MappingObject.javascriptify_variable(@info_window_options)})"
39:         end
40:         if @address.nil?
41:           creation
42:         else
43:           "addGeocodingToMarker(#{creation},#{MappingObject.javascriptify_variable(@address)})"
44:         end
45:       end

[Validate]