Hello, I am using the ym4r_gm plugin with rails, and I am trying to use the marker group feature. The main functionality I am trying to develop is summed up by the following point from the ym4r_gm documentation.
Marker groups can be used for: + Keeping an index of markers, for example, in order to show one of these markers in reponse to a click on a link (the way Google Local does with the results of the search).
My initial page load, which plots the first set of markers on the map works fine with the marker group. However, when I update the map via ajax, the new markers are re-plotted, but it seems the marker_group is lost, as I can no longer click on the links to show the marker on the map.
Does anyone have an idea of why I am loosing the ability to click on my link to show the marker pop-up on the map?
Below is the code I am using:
#first controller function that is called def initialize_map @map = GMap.new("map_div") @map.control_init(:large_map => true,:map_type => true) @map.interface_init({ :dragging => true, :info_window=> true, :double_click_zoom => true, :scroll_wheel_zoom => true }) plot_points_on_map(find_points) end
def plot_points_on_map(@points) @markers = Hash.new for point in @points marker = GMarker.new(point.address, :title => "geocoded", :info_window => point.name, :icon => :icon_point) @markers[point.id] = marker end @marker_group = GMarkerGroup.new(true, @markers) @map.overlay_global_init(@marker_group, "markerGroup") end
Then in my partial _results.rhtml I have the following anchor <% for point in @points %> <a href="#" onclick="markerGroup.showMarker(<%= point.id %>);return false;">View on map</a> <% end -%>
I have a form with various controls, that call the following when submitted via ajax
def update_points_using_criteria @points = find_points @map = Variable.new("map") plot_points_on_map(@points) end end
And the corresponding rjs file
page << @map.clear_overlays @markers.each_pair {|point_id, marker| page << @map.add_overlay(marker) } page.replace_html 'results-wide', :partial => 'results'