Yves Dufour
2007-Mar-08 07:55 UTC
[Ym4r-user] map not displayed after Ajax.updater request
In my layout header I inserted the standard helper : GMap.header I built the map in my controller , I build either a standard table or a map and display it in the corresponding partial the map is built without any problem with the icons and markers ( @map is correct...) @map = GMap.new("map_div") ... @map.icon_global_init(GIcon.new(:image => "/images/gm_contact.png", .... .. @map.overlay_global_init(GMarkerGroup.new(true, @markers[1]), "contact") .... from a radio button, an Ajax.Updater request is sent to my controller to require either table or map build and display... .... ....build table or map ,according to ajax request parameter if request.xml_http_request? render :partial => ''display_network'' , :layout => false end then in my view <% if @display_type == "0" %> .... display table <% else %> <div id="map_box" style="border:solid 2px grey; margin:1em auto; width:340px; height:340px;"> <%= @map.to_html %> <%= @map.div(:width => 338, :height => 330) %> </div> <% end %> the map_box is displayed (grey line border) , but not the map inside.. no GoogleMap request.... looking at the response source code , I can see the inserted script (with the right data...) <div id="map_box" style="border:solid 2px grey; margin:1em auto; width:340px; height:340px;text-align;"> <script type="text/javascript"> var icon_contact = addOptionsToIcon(new GIcon(),{iconSize : new GSize (20,34),shadowSize : new GSize(37 ,34),image : "/images/gm_contact.png",iconAnchor : new GPoint (10,34),shadow : "/images/gm_shadow.png" ,infoWindowAnchor : new GPoint(9,2)}); .......... var map; window.onload = addCodeToFunction(window.onload,function() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_div")); map.setCenter(new GLatLng(47.7500161647,-2.916641656), 8);GEvent.addListener(map,"click",function processMoveEndEvent () { var centerPoint = map.getCenter(); if (map.getZoom() <= 18) { processNewMapMovement()} }); map.addOverlay(contact); map.addOverlay(reference);map.addControl(new GSmallMapControl()); } }); </script> but that''s all.... no map displayed ... why any clue ? I already used it in other parts of my app without any problem, but never from an Ajax request... is it the key point ? thanks for your help Yves
Guilhem Vellut
2007-Mar-09 22:44 UTC
[Ym4r-user] map not displayed after Ajax.updater request
hello, I think it may come from the fact the map is created in response to the window.onload event, which should have already fired by the time you get your answer from the xmlhttprequest call, which means the code for the map creation may never be called. One solution around this could be to dispense with the onload setup : You can call @map.to_html(:no_load => true) for this (update the plugin beforehand). guilhem On 3/8/07, Yves Dufour <yves_dufour at mac.com> wrote:> > In my layout header I inserted the standard helper : GMap.header > > > I built the map in my controller , I build either a standard table > or a map and display it in the corresponding partial > > > the map is built without any problem with the icons and markers > ( @map is correct...) > > @map = GMap.new("map_div") > ... > @map.icon_global_init(GIcon.new(:image => "/images/gm_contact.png", .... > .. > @map.overlay_global_init(GMarkerGroup.new(true, @markers[1]), "contact") > .... > > from a radio button, an Ajax.Updater request is sent to my > controller to require either table or map build and display... > .... > ....build table or map ,according to ajax request parameter > if request.xml_http_request? > render :partial => ''display_network'' , :layout => false > end > > then in my view > > <% if @display_type == "0" %> > .... display table > <% else %> > <div id="map_box" style="border:solid 2px grey; margin:1em auto; > width:340px; height:340px;"> > <%= @map.to_html %> > <%= @map.div(:width => 338, :height => 330) %> > </div> > <% end %> > > the map_box is displayed (grey line border) , but not the map > inside.. no GoogleMap request.... > > looking at the response source code , I can see the inserted script > (with the right data...) > > <div id="map_box" style="border:solid 2px grey; margin:1em auto; > width:340px; height:340px;text-align;"> > <script type="text/javascript"> > var icon_contact = addOptionsToIcon(new GIcon(),{iconSize : new GSize > (20,34),shadowSize : new GSize(37 > ,34),image : "/images/gm_contact.png",iconAnchor : new GPoint > (10,34),shadow : "/images/gm_shadow.png" > ,infoWindowAnchor : new GPoint(9,2)}); > .......... > var map; > window.onload = addCodeToFunction(window.onload,function() { > if (GBrowserIsCompatible()) { > map = new GMap2(document.getElementById("map_div")); > map.setCenter(new GLatLng(47.7500161647,-2.916641656), > 8);GEvent.addListener(map,"click",function processMoveEndEvent > () { var centerPoint = map.getCenter(); if (map.getZoom() <= 18) > { processNewMapMovement()} }); > map.addOverlay(contact); > map.addOverlay(reference);map.addControl(new GSmallMapControl()); > } > }); > </script> > > but that''s all.... no map displayed ... why any clue ? > > I already used it in other parts of my app without any problem, but > never from an Ajax request... is it the key point ? > thanks for your help > > Yves > > _______________________________________________ > Ym4r-user mailing list > Ym4r-user at rubyforge.org > http://rubyforge.org/mailman/listinfo/ym4r-user >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ym4r-user/attachments/20070309/6466b44e/attachment.html