#Local Search control. Report to the Google Maps API documentation for details.
#The first argument of the constructor is one of the following : :top_right, :top_left, :bottom_right, :bottom_left.
#The second and third arguments of the constructor are the offset width and height respectively in pixels.
class GLocalSearchControl < Struct.new(:anchor, :offset_width, :offset_height)
include MappingObject
def create
offset_width ||= 10
offset_height ||= 20
js_anchor = if anchor == :top_right
"G_ANCHOR_TOP_RIGHT"
elsif anchor == :top_left
"G_ANCHOR_TOP_LEFT"
elsif anchor == :bottom_right
"G_ANCHOR_BOTTOM_RIGHT"
else
"G_ANCHOR_BOTTOM_LEFT"
end
"new google.maps.LocalSearch(), new GControlPosition(#{js_anchor}, new GSize(#{offset_width},#{offset_height}))"
end
end
map.rb (replaces self.header at line 28)
#Outputs the header necessary to use the Google Maps API, by including the JS files of the API, as well as a file containing YM4R/GM helper functions. By default, it also outputs a style declaration for VML elements. This default can be overriddent by passing :with_vml => false as option to the method. You can also pass a :host option in order to select the correct API key for the location where your app is currently running, in case the current environment has multiple possible keys. Usually, in this case, you should pass it @request.host. If you have defined only one API key for the current environment, the :host option is ignored. Finally you can override all the key settings in the configuration by passing a value to the :key key. You can pass a language for the map type buttons with the :hl option (possible values are: Japanese (ja), French (fr), German (de), Italian (it), Spanish (es), Catalan (ca), Basque (eu) and Galician (gl): no values means english). Finally, you can pass :local_search => true to get the header css and js information needed for the local search control. If you do want local search you must also add :local_search => true to the @map.control_init method.
def self.header(options = {})
options[:with_vml] = true unless options.has_key?(:with_vml)
options[:hl] ||= ''
options[:local_search] = false unless options.has_key?(:local_search)
api_key = ApiKey.get(options)
a = "\n"
a << "\n" unless options[:without_js]
a << "" if options[:with_vml]
a << "" if options[:local_search]
a << "\n" if options[:local_search]
a << "" if options[:local_search]
a
end
map.rb (replaces 'control_init' at line 65)
#Initializes the controls: you can pass a hash with keys :small_map, :large_map, :small_zoom, :scale, :map_type, :overview_map and a boolean value as the value (usually true, since the control is not displayed by default) and :local_search
def control_init(controls = {})
@init_end << add_control(GSmallMapControl.new) if controls[:small_map]
@init_end << add_control(GLargeMapControl.new) if controls[:large_map]
@init_end << add_control(GSmallZoomControl.new) if controls[:small_zoom]
@init_end << add_control(GScaleControl.new) if controls[:scale]
@init_end << add_control(GMapTypeControl.new) if controls[:map_type]
@init_end << add_control(GOverviewMapControl.new) if controls[:overview_map]
@init_end << add_control(GLocalSearchControl.new(:bottom_right)) if controls[:local_search]
end