Skip to content

Instantly share code, notes, and snippets.

@walter
Created August 21, 2011 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walter/1161270 to your computer and use it in GitHub Desktop.
Save walter/1161270 to your computer and use it in GitHub Desktop.
Rails 2.3 override of gmaps4rails partial
<% #thanks to enable_css, user can avoid this css to be loaded
if enable_css == true %>
<% content_for :head do %>
<%= stylesheet_link_tag 'gmaps4rails' %>
<% end %>
<% end %>
<% content_for :scripts do %>
<% if enable_js == true %>
<% @provider = options['map_options'] && options['map_options']['provider'] ? options['map_options']['provider'] : nil -%>
<% case @provider
when "openlayers" %>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<% when "mapquest" %>
<script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key=#{options['map_options'].try(:[], 'provider_key')}"></script>
<% when "bing" %>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<% else %>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;libraries=geometry<%= g_libraries(options['map_options'].try(:[], 'libraries')) %>"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/src/infobox.js"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js"></script>
<% end %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.base.js' %>
<% case @provider
when "openlayers" %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.openlayers.js' %>
<% when "mapquest" %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.mapquest.js' %>
<% when "bing" %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.bing.js' %>
<% else %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.googlemaps.js' %>
<% end %>
<% end %>
<script type="text/javascript" charset="utf-8">
function gmaps4rails_init() {
<% #true is passed here to trigger map initialization %>
<%=raw options.to_gmaps4rails(true) %>
};
window.onload = gmaps4rails_init;
</script>
<% end %>
<% case @provider
when "mapquest" %>
<div id="mapQuest" style="width:750px; height:475px;">
<!-- TODO: change this style dynamically -->
</div>
<% else %>
<% container_id = options['map_options'] && options['map_options']['container_id'] ? options['map_options']['container_id'] : 'map_container' -%>
<% inner_id = options['map_options'] && options['map_options']['id'] ? options['map_options']['id'] : 'gmaps4rails_map' -%>
<div id="<%= container_id -%>" >
<div id="<%= inner_id -%>"<%= ' class="bing_map"' if @provider == 'bing' -%>></div>
</div>
<% end %>
@walter
Copy link
Author

walter commented Sep 6, 2011

Note that this was written pre-1.0.0 release of gmaps4rails, it will likely need tweaking for you.

@walter
Copy link
Author

walter commented Sep 6, 2011

And here's a link to the latest version of gmaps4rails version for reference: https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/app/views/gmaps4rails/_gmaps4rails.html.erb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment