5

gmaps4railsを使用すると、カスタムマーカーを定義する方法があります。ただし、データベースエントリごとに同じものが表示されます。

Google Latitudeのように、データベースエントリごとに異なるマーカーを表示するにはどうすればよいですか?カテゴリ/グループの画像のみがあり、個々のユーザーがない場合は、できれば独自のデータベース列またはスプライトを使用してください。

4

1 に答える 1

4

apneadivingsの答えに基づいて、2つのおそらくより短い方法が思い浮かびます。

ジェネリック:

def gmaps4rails_marker_picture
    {
    "picture" => self.image_path, # image_path column has to contain something like '/assets/my_pic.jpg'.
    "width" => 32, #beware to resize your pictures properly
    "height" => 32 #beware to resize your pictures properly
    }
end

この場合、画像の名前としてカテゴリ列を再利用します。

def gmaps4rails_marker_picture
    {
    "picture" => "/images/" + self.category + ".png",
    "width" => 32, #beware to resize your pictures properly
    "height" => 32 #beware to resize your pictures properly
    }
end

現在欠けているのは、スプライトを使用する方法だけです。しかし、それはおそらく不可能です。

于 2011-02-18T17:04:23.353 に答える