apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

custom infowindow #127

Closed bbuegler closed 12 years ago

bbuegler commented 12 years ago

hey i'm sure it's actually not a bug but i've been hurting my head for days now and couldn't get this straightened out. This is most likely due to me being a bloody noob. So here is my problem:

i've been trying to get a custom infowindow - i'm trying to make my first app on Rails 3.1.0 and Ruby 1.8.7. i've included the <%= yield :scripts %> and skipped the <%= yield :head %> since it's apparently not required in my version. my address is computing

def gmaps4rails_address
    self.user.street + self.user.city 
end

and my custom markers are displayed beautifully. i have put together this little piece of code im my controller to show some content in the infowindow and to customise the markers.

  def maps
    @json = Stuff.all.to_gmaps4rails do |stuff, marker|
        marker.infowindow render_to_string(:partial => "/stuffs/mapstuff", :locals => { :stuff => stuff}).gsub(/\n/, '').gsub(/"/, '\"')
        marker.picture({
            :picture => stuff.image.url(:tiny),
            :width   => "30",
            :height  => "30"
        })

        #marker.description stuff.description
        marker.title   stuff.title
        #marker.sidebar "i'm the sidebar"
        marker.json    "\"id\": #{stuff.id}"
    end
end

it works fine too and even renders the partial. my problems started when i began modifiying the infowindow by passing the option custom_info_window_class:

<%= gmaps("markers" => {"data" => @json, "options" => { "custom_infowindow_class" => "yellow","randomize" => true, "max_random_distance" => 1000, "clusterer_maxZoom" => 17 }, "map_options" => { "type" => "HYBRID", "auto_adjust" => true,"center_on_stuff" => true }}) %>

it's hard an cruel but at this point my infowindow gets a new class but not the one i'm pasing. Instead it apparently defaults to: infoBox which allows me to do some styling but from this point on there is no content in my infowindow anylonger, besides the little close infowindow x. has anybody a tip for me?

apneadiving commented 12 years ago

Look here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Markers

Because InfoBox has special process and options, you must have at least in your view:

Gmaps.map.infobox = function(boxText) {
 return {
    content: boxText
}};

boxText contains the infowindow set in your controller.

bbuegler commented 12 years ago

firebug mentions: Gmaps.map is undefined, i have tried:

bbuegler commented 12 years ago

thanks for helping me again after you encouraged me to post here.

apneadiving commented 12 years ago

put this code under your gmaps call in the view and inside a content_for :scripts

bbuegler commented 12 years ago

you Sir, are a boss! there's no error anymore. though the content isn't inside the info_window yet

apneadiving commented 12 years ago

Because I wasn't sure, I redid the example I provide in the wiki and it's working properly.

I guess you've either a problem with the css or with the infoBow options.

bbuegler commented 12 years ago

damn if you knew how much i could hug you - you'd have an instance resistance to winter-depressions. I thank you soo much. I bow to you holding your breath to type such helpfull stuff.