YM4R and GeoKit Rock
So far YM4R and GeoKit are working out aside from a few oddities. GeoKit install and geocoding was flawless, but I’ve yet to use the advanced finders for distance. At the moment the user/gamer/player (haven’t decided what to call it as of yet) doesn’t have an address associated with it for mapping functionality. Should be easy enough to compute according to tutorials.
YM4R makes the simple things even easier, but due to the very small amount of documentation its been a bit difficult to find examples. It’s probably time to start digging through the plugin code for clarification. YM4R is used for creating your Google Map markers in Ruby code, storing them to single variable and then being able to generate the header javascript, as well as the div/span/whatever the map will be created in. It’s easy enough to wrap some code in a content tag from within a view for a specific map.
<% content_for(:header) do %>
<%= GMap.header %>
<%= javascript_include_tag("markerGroup") %>
<%= @map.to_html %>
<% end %>
The @map variable was created within the controller with all points that will be created, as well as any map settings — like zoom level, lat/long to center in on, as well as managing groups, clusters and anything else. When generating a map with a group of points, it’s possible to have ym4r decide where to zoom in on, as well as what zoom level. This is as easy as a few lines:
sorted_latitudes = @arcades.collect(&:address).collect(&:lat).compact.sort
sorted_longitudes = @arcades.collect(&:address).collect(&:lng).compact.sort
@map.center_zoom_on_bounds_init([ [sorted_latitudes.first, sorted_longitudes.first],
[sorted_latitudes.last, sorted_longitudes.last]])
I’m still working on some of the basics of mapping that aren’t quite as well documented. Things like having a marker point popup on start, or having a link on the page outside of the map that opens a map marker. These kinds of things are simple when you step into javascript, and heavily documented, but not quite as much so with wrapper plugins. I’ll probably mess around with it a bit more, before deciding if straight javascript or ruby is the way to go.
As far as javascript goes, one solution that looks interesting is Mapstraction. There is actually a YM4R wrapper for it as well, although it appears out of date (and undownloadable). The idea is that you can switch which mapping engine you use. Always a plus to give users the ability to decide which mapping engine they prefer, but I imagine it’s at the cost of some features. Google, for instance has quite a few different ways of grouping points so the browser doesn’t crash to a halt. For instance, if you use clustering (which the ym4r gm plugin supports), markers that indistinguishable at far out zoom level will be shown as a single point. This keeps the map clean so that you won’t have a collection of points all on top of each other. We’ll see how it goes with the remaining tasks!