I am working on building a Google Map application that lets a user
search a database by clicking on several check boxes to filter
results. I have attached an observe_form call that sends the selected
checkboxes to my controller. The controller then searches the
database and re-renders the Google map (rendered as a partial). The
map is rendered and I call the initialize method on the map again.
The issue I am having is that when I perform the new search and update
the map, it update the points that are on the map.
Any help is appreciated.
The search results code and RJS is here:
@tutors = Tutor.find(:all, :conditions => ["work_lat !=
'''' and
work_long != '''' and id in (select tutor_id from
subjects_tutors where
subject_id in (#{@query}))"])
respond_to do |format|
format.js {
render :update do |page|
page.replace ''mapresults'', :partial =>
"map", :locals =>
{:tutors => @tutors}
page.call "initialize"
end
}
end
Here''s the map rendering code:
<script type="text/javascript">
if (window.addEventListener) {
window.addEventListener("load", initialize, false);
}
function createMarker(point,html) {
var marker1 = new GMarker(point);
GEvent.addListener(marker1, "click", function() {
marker1.openInfoWindowHtml(html);
});
return marker1;
}
function initialize() {
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
<% unless params[:student_lat] and params[:student_long] %>
map.centerAndZoom(new GPoint(-122.443882, 37.769079), 5);
<% else %>
map.centerAndZoom(new GPoint(<%= params[:student_long].to_f %>,
<%params[:student_lat].to_f %>), 5);
<% end %>
<% unless @tutors.size == 0 %>
<% @tutors.each do |tutor|%>
var point = new GPoint(<%=tutor[:work_long]%>,<%=tutor[:work_lat]
%>);
var marker = createMarker(point,''<div><h3><%=
link_to
h(tutor[:first] + " " + tutor[:last]), edit_tutor_path(tutor) %>
</
h3><p><%= mail_to tutor.emails.primary.address %><br
/><%tutor.phones.primary.digits %><br
/><strong>Rating</strong>: <%tutor.rating %>/5
stars</p></div>'');
map.addOverlay(marker);
<% end %>
<% end %>
}
</script>
-
Justin Williams
Owner, Second Gear
http://secondgearllc.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---