Lo there all,
i have a function that builds a bunch of markers to go on a google
map. I would like to update them with rjs.
Here is what i have so far.
def map_main_layout
@zoom = params[:zoom].to_i
@zoom = 14 if params[:zoom].nil?
@map = GMap.new("map_div")
# @map.control_init(:large_map => true, :map_type => true) #
(inserts map control)
# place the map where we want it ( center and zoom level )
@map.center_zoom_init([@group.group_map_stat.lat.to_f,
@group.group_map_stat.long.to_f], @zoom)
@map.set_map_type_init(GMapType::G_HYBRID_MAP)
@sites = @group.sites
@sites.each do |site|
# draw the circles
site.map_stat.circle_image(@zoom)
end
@all_markers = make_map_markers(@sites, @zoom)
@map.overlay_global_init(GMarkerGroup.new(true, @all_markers),
"myGroup")
end
def make_map_markers(sites, zoom)
_all_markers = Hash.new
sites.each_with_index do |site, i|
# load the circles
text = site.map_stat.marker_window_html()
# r = site.map_stat.radius.to_i
zoomhash = {13 => 0.5, 14 => 1, 15 => 2, 16 => 4}
r = (site.map_stat.radius.to_f * zoomhash[@zoom.to_i].to_f).to_i
# title tooltip for the image
title = "%s %s => %s" % [@group.name, site.site_name,
(KeyWord.stat_description(site.status_sensor.last_value)[0])]
# create the icon image ( the pivot circle )
icon = GIcon.new(:image => "/images/tmp/#{site.id}.png",
:icon_size => GSize.new((r*2),(r*2)),
:icon_anchor => GPoint.new(r,r),
:info_window_anchor => GPoint.new(r,r))
# place the marker on the map
marker = GMarker.new([site.map_stat.lat.to_f ,
site.map_stat.long.to_f],
:title => title, :icon => icon, :info_window
=> text)
_all_markers[i] = marker
end
return _all_markers
end
def update_map_markers
@zoom = params[:zoom].to_i
@zoom = 14 if params[:zoom].nil?
@map = Variable.new("map")
@all_markers = Variable.new("myGroup") # the actual marker
group, not the markers, this is the container
@group.sites.each { |site| site.map_stat.circle_image(@zoom)}
@site_marks = make_map_markers(@group.sites, @zoom)
@marker = GMarker.new([75.89,-42.767],:title => "Update",
:info_window => "I have been placed through RJS")
end
I am using a simple form_remote_tag in the view, and in the rjs file i have
page << @map.clear_overlays
@site_marks.each {|mark| page << @map.add_overlay(mark)}
now, when i execute the button, the markers go away, but are not redrawn.
Anybody help me please ?
thanks again
shawn