On 13 Dec 2011, at 19:54, skrite <sh...@skrite.net> wrote:
> Jim. > > You are correct, when i show typeof(sites) from when sites = <%= > @mapped_sites => > i get object > when i do typeof(sites) after getting sites from the > url_that_returns_json > i get string > responseText is always going to be text if I remember how prototype handles thing (the text will just happen to be the string representation of the json). If the response content-type was set correctly then response.responseJson (or something like that) should be populated Fred > i suppose that i am not getting returned correctly. > if i look at the source of @mapped_sites > and from the browser look at url_that_returns_json, > they are identical. > > thanks for your help, again. > I have learned a lot the last couple of days :) > > On Dec 12, 6:22 pm, Jim Ruther Nill <jvn...@gmail.com> wrote: >> On Tue, Dec 13, 2011 at 6:08 AM, skrite <sh...@skrite.net> wrote: >>> I am doing something similar here. The website is built on rails 2.3.9 >>> and >>> uses prototype. >> >>> Almost all of what i need to happen does, but i get to the point where >>> the update happens and nothing does. >> >>> // add circles to map as it initializes >>> addCircles(sites, map, markerArray, lineArray); >> >>> var pe = new PeriodicalExecuter(refreshCircleMarkers.curry(markerArray, >>> lineArray, map), 33); >> >>> function refreshCircleMarkers(markerArray, lineArray, map) { >>> // first we remove the existing markers in place >>> for(i=0; i<markerArray.length; i++) { >>> markerArray[i].setMap(null); >>> } >> >> // and empty the array itself> markerArray = []; >> >>> var url = "/group/update_mapv3_circles"; >>> new Ajax.Request(url, { >>> method: 'get', >>> onSuccess: function(response) { >>> var sites = response.responseText; >>> addCircles(sites, map, markerArray, lineArray); >>> } >>> }); >> >> I see nothing wrong. Does the addCircles function expect a JSON >> object for the first param? The only reason I can think why this isn't >> working >> is a type mismatch. >> >> >> >> >> >> >> >> >> >> >> >>> If i do an alert(response.responseText) the alert will show up and >>> display the contents of the @mapped_sites.to_json ( i am using >>> render :json => @mapped_sites.to_json in the controller). >>> Please let me know if you see something i am doing wrong. >>> Thanks for your help on this so far Jim. >> >>> sk >> >>> On Dec 9, 11:49 pm, Jim Ruther Nill <jvn...@gmail.com> wrote: >>>> On Sat, Dec 10, 2011 at 3:56 AM, skrite <sh...@skrite.net> wrote: >>>>> I am intrigued by this solution, Jim. >>>>> i have a couple of questions, as it seems this is a cleaner way than >>>>> what I am trying to do. >>>>> The values that determine the circle color are in the database, and >>>>> can change while the page is loaded. This is why i need them to >>>>> update. >> >>>> i'll still go with my suggestion earlier. To update the colors, just >>> update >>>> the sites variable after completing the ajax request and then call >>>> addCircles >> >>>> your ajax call may look like the following (this is totally untested :D) >> >>>> $.ajax({ >>>> url: your_url_here_that_returns_json_equivalent_of_@mapped_sites, >>>> success: function(data) { >>>> addCircles(data); >>>> } >> >>>> }); >>>>> So, somehow i still need to go to the server for that. I guess i am >>>>> missing the part about how to get the @mapped_sites variable to the >>>>> controller and back again to the page to rebuild the circles. >>>>> Thanks for your time on this. >>>>> sk >> >>>>> On Dec 9, 9:48 am, Jim Ruther Nill <jvn...@gmail.com> wrote: >>>>>> On Fri, Dec 9, 2011 at 11:04 PM, skrite <sh...@skrite.net> wrote: >>>>>>> Hey, thanks for these links, very helpful. >>>>>>> -sk >> >>>>>>> On Dec 8, 7:49 pm, "L.Karthikeyan" <logkart...@gmail.com> wrote: >>>>>>>> Hi, >> >>>>>>>> For this you need to use rjs Ajax request. Please refer the >>>>>>>> following links, you will get an idea. >> >>>>>>>> 1.http://railscasts.com/episodes/43-ajax-with-rjs?autoplay=true, >>>>>>>> 2. >>>>> http://railscasts.com/episodes/229-polling-for-changes?autoplay=true >> >>>>>> one more option is to keep @mapped_sites to a javascript variable so >>> you >>>>>> dont have to use ajax. you might also want to move the makeMarker >>> part >>>>>> to a js function to tidy up the view and just call that function >>> when you >>>>>> need >>>>>> to update the colors >> >>>>>> something along the lines of >> >>>>>> var sites = <%= @mapped_sites.to_json %>; >>>>>> addCircles(sites); >> >>>>>> function addCircles(circles) { >>>>>> for(i=0; i<circles.length; i++) { >>>>>> center = new google.maps.LatLng(circles[i][0], circles[i][1]); >>>>>> siteCircle = makeMarker({ >>>>>> position: center, >>>>>> strokeColor: "#FF0000", >>>>>> strokeOpacity: 0.8, >>>>>> strokeWeight: 2, >>>>>> fillColor: circles[i][7], >>>>>> fillOpacity: 0.75, >>>>>> radius: 560, >>>>>> map: map, >>>>>> center: center, >>>>>> radius: circles[i][2], >>>>>> title: circles[i][5], >>>>>> content: 'content' >>>>>> }); >>>>>> } >> >>>>>> } >> >>>>>> then you just need to update the sites variable using js. no need >>>>>> to go back to the server. >> >>>>>>>> On Thu, Dec 8, 2011 at 1:10 AM, skrite <sh...@skrite.net> wrote: >> >>>>>>>>> Hey all, >>>>>>>>> i have a google map and i am drawing circles on the map like >>> this.. >> >>>>>>>>> var latlng = new google.maps.LatLng(35.931387, >>>>>>>>> -102.31062); >>>>>>>>> var myMapOptions = >>>>>>>>> { >>>>>>>>> zoom: >>>>>>>>> 12, >>>>>>>>> center: >>>>>>>>> latlng, >>>>>>>>> mapTypeId: >>>>>>>>> google.maps.MapTypeId.HYBRID >>>>>>>>> }; >> >>>>>>>>> var map = new >>>>>>>>> google.maps.Map(document.getElementById("map_canvas"), >>>>>>>>> myMapOptions); >>>>>>>>> var infoWindow = new >>>>>>>>> google.maps.InfoWindow(); >>>>>>>>> var markerBounds = new >>>>>>>>> google.maps.LatLngBounds(); >> >>>>>>>>> <% @mapped_sites.each do |row| >>>>>>>>> %> >> >>>>>>>>> // main >>>>>>>>> circle >>>>>>>>> center = new google.maps.LatLng(<%= "#{row[0]}" %>, <%= >>>>>>>>> "#{row[1]}" >>>>>>>>> %>); >>>>>>>>> siteCircle = >>>>>>>>> makeMarker({ >>>>>>>>> position: >>>>>>>>> center, >>>>>>>>> strokeColor: >>>>>>>>> "#FF0000", >>>>>>>>> strokeOpacity: >>>>>>>>> 0.8, >>>>>>>>> strokeWeight: >>>>>>>>> 2, >>>>>>>>> fillColor: '<%= "#{row[7]}" >>>>>>>>> %>', >>>>>>>>> fillOpacity: >>>>>>>>> 0.75, >>>>>>>>> radius: >>>>>>>>> 560, >>>>>>>>> map: >>>>>>>>> map, >>>>>>>>> center: >>>>>>>>> center, >>>>>>>>> radius: <%= "#{row[2]}" >>>>>>>>> %>, >>>>>>>>> title: '<%= "#{row[5]}" >>>>>>>>> %>', >>>>>>>>> content: '<%= "some contnet >>>>>>>>> %>' >>>>>>>>> }); >> >>>>>>>>> markerArray.push(siteCircle); >> >>>>>>>>> my question is, that since the fillColor is going to change >>> from >>>>> time >>>>>>>>> to time, i want to update all the colors of the circles >>>>> periodically. >>>>>>>>> What i don't know how to do is get the equivelent to the >>>>>>>>> @mapped_sites because if i could, i think i could just delete >>> the >>>>>>>>> existing circles and draw new ones. >> >>>>>>>>> How do i get info back from the server periodically to update >>> the >>>>>>>>> circle colors? >> >>>>>>>>> thanks to all. >>>>>>>>> skrite >> >>>>>>>>> -- >>>>>>>>> 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@googlegroups.com >>>>>>> . >>>>>>>>> To unsubscribe from this group, send email to >>>>>>> rubyonrails-talk+unsubscr...@googlegroups.com. >>>>>>>>> For more options, visit this group athttp:// >>>>>>> groups.google.com/group/rubyonrails-talk?hl=en. >> >>>>>>>> -- >> >>>>>>>> Regards, >>>>>>>> L.KarthiKeyan. >> >>>>>>> -- >>>>>>> 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@googlegroups.com >>>>> . >>>>>>> To unsubscribe from this group, send email to >>>>>>> rubyonrails-talk+unsubscr...@googlegroups.com. >>>>>>> For more options, visit this group at >>>>>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >>>>>> -- >>>>>> ------------------------------------------------------------- >>>>>> visit my blog athttp://jimlabs.heroku.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@googlegroups.com >>> . >>>>> To unsubscribe from this group, send email to >>>>> rubyonrails-talk+unsubscr...@googlegroups.com. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >>>> -- >>>> ------------------------------------------------------------- >>>> visit my blog athttp://jimlabs.heroku.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@googlegroups.com. >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> ------------------------------------------------------------- >> visit my blog athttp://jimlabs.heroku.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@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.