Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7673ad
commit 15e90db
Showing
24 changed files
with
974 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Gmaps4rails | ||
module GmapsHelper | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
<% content_for :head do %> | ||
<%= stylesheet_link_tag 'gmaps4rails' %> | ||
<% #enable_css enables user to avoid this css to be loaded | ||
if enable_css == true %> | ||
<% content_for :head do %> | ||
<%= stylesheet_link_tag 'gmaps4rails' %> | ||
<% end %> | ||
<% end %> | ||
<% content_for :scripts do %> | ||
<script src="http://www.google.com/jsapi"></script> | ||
<script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer.js'></script> | ||
<%=javascript_include_tag 'gmaps4rails' %> | ||
<script type="text/javascript" charset="utf-8"> | ||
<% options.each do |key, value| %> | ||
Gmaps4Rails.<%= key %> = <%=raw value.is_a?(String) ? "'#{value}'" : value %>; | ||
<% end %> | ||
var builder = <%=raw options["processing"] == "json" ? builder : "'#{builder}'" %>; | ||
|
||
window.onload = function() { | ||
Gmaps4Rails.initialize(builder); | ||
<% #true is passed here to trigger map initialization %> | ||
<%=raw options.to_gmaps4rails(true) %> | ||
} | ||
</script> | ||
<% end %> | ||
<div id="<%= options['map_container_id'] || "map_container" %>"> | ||
<div id="<%= options['map_id'] || "gmaps4rails_map" %>"></div> | ||
</div> | ||
<div id="<%= options["map_options"].nil? || options['map_options']['container_id'].nil? ? "map_container" : options['map_options']['container_id'] %>"> | ||
<div id="<%= options["map_options"].nil? || options['map_options']['id'].nil? ? "gmaps4rails_map" : options['map_options']['id'] %>"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<% content_for :head do %> | ||
<%= stylesheet_link_tag '../../../public/stylesheets/gmaps4rails' %> | ||
<% end %> | ||
<% content_for :scripts do %> | ||
<script src="http://www.google.com/jsapi"></script> | ||
<script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer.js'></script> | ||
<%=javascript_include_tag '../../../public/stylesheets/gmaps4rails' %> | ||
<script type="text/javascript" charset="utf-8"> | ||
<% options.each do |key, value| %> | ||
Gmaps4Rails.<%= key %> = <%=raw value.is_a?(String) ? "'#{value}'" : value %>; | ||
<% end %> | ||
var builder = <%=raw options["processing"] == "json" ? builder : "'#{builder}'" %>; | ||
|
||
window.onload = function() { | ||
Gmaps4Rails.initialize(); | ||
Gmaps4Rails.create_markers(builder); | ||
} | ||
</script> | ||
<% end %> | ||
|
||
<div id="<%= options['container_id'] || "map_container" %>"> | ||
<div id="<%= options['id'] || "gmaps4rails_map" %>"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module ApplicationHelper | ||
|
||
def gmaps4rails_map(builder, options = {}) | ||
render :partial => 'gmaps4rails/gmaps4rails', :locals => { :builder => builder, :options => options } | ||
end | ||
|
||
def gmaps4rails(builder, options = {}) | ||
options.merge!({ "processing" => 'json' }) | ||
render :partial => 'gmaps4rails/gmaps4rails', :locals => { :builder => builder, :options => options } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// var triangleCoords = [ | ||
// // { | ||
// // "strokeColor": "#FF0000", | ||
// // "strokeOpacity": 0.3, | ||
// // "strokeWeight": 1, | ||
// // "fillColor": "#FF0000", | ||
// // "fillOpacity": 0.7 | ||
// // }, | ||
// [ | ||
// {"longitude": -80.190262, "latitude": 25.774252}, | ||
// {"longitude": -66.118292, "latitude": 18.466465}, | ||
// {"longitude": -64.75737, "latitude": 32.321384} | ||
// ]]; | ||
// | ||
// Gmaps4Rails.polygons = triangleCoords; | ||
|
||
// var flightPlanCoordinates = [ | ||
// <%# @traj = User.destination({"from" => "Nice", "to" => "Paris"}, {"language" => "fr", "waypoints" => ["Toulon","Toulouse", "Lorient", "Bourges", "Strasbourg", "Namur"] }, "pretty") %> | ||
// <%# @traj.each do |traj| %> | ||
// <%#= raw traj["polylines"] + "," %> | ||
// <%# end %> | ||
// <%= raw "[{\"coded_array\":\"{cfgGmgxb@F@\"},{\"coded_array\":\"scfgGkgxb@PxGHpOjArJRnEPp@jAtBjC`GZbDSpEJTjAZR\\\\JfDpBpJN|B^nCXXj@L|AhAxAf@`@Zt@|Ad@jBP|FZvEPlJpAvU|Cv\\\\HzBDvMPnFTdBXv@hBbB^j@bF~MVz@dAxHfEdQXt@xA|Bp@nBdFnWt@xFbCnMP|BDdOn@jH`AxE`@pA|ApDdBnC\"},{\"coded_array\":\"cecgGeslb@KdA@nJPrNt@|IElDHlB`AhIl@tA`@b@j@b@fHxDhAfAfB|BfApB|A|DpBfJl@rFDdDPnBpKto@n@lCb@`Ap@fA`CtCpAdDlAdJbAlKNlC?rEJ~Bv@zDzEzNdH`XlI`UpVzk@\"},{\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ded_array\":\"abegGixz`@I`@D^n@xAh@rFX`A`B~ZlAfMlA~l@j@bF\"},{\"coded_array\":\"gudgGkjw`@ZtDlAzIhCb_@bApH^tVEfBc@vEMrCs@bFCxK{@fPc@bGe@fCk@x@\"},{\"coded_array\":\"qsdgGmvr`@_A~@]nAOtEB|FkArKPtSv@pMy@xJUtAw@hK\"},{\"coded_array\":\"e{dgGsxo`@gAlR{AhKDhTOpAgBdHmCtUm@rHKzI@jG\"},{\"coded_array\":\"ajegGgdl`@Mh]I|Bs@vD{Kfc@UnBBjM^nT\"},{\"coded_array\":\"{xegGsph`@LdR|AxMfAnF~ApNh@pBT`@tE~R\"},{\"coded_array\":\"qgegG}~e`@|AdGpAfGn@xMPpAfGxTLpA\\\\xAZ^|@bDt@tGhA|CbA~FDdD\"},{\"coded_array\":\"gmdgG_ac`@FxA\"},{\"coded_array\":\"_mdgGe~b`@GP\"},{\"coded_array\":\"gmdgGs}b`@?zGN`LjBnFbH|[DbA]|@\"},{\"coded_array\":\"_adgGe_a`@g@p@I|@dCdJVdH@vDGt@sIv^sB~JgDtJsDzHMHwArCXfJ\"},{\"coded_array\":\"iydgGkn}_@MNCXFZRNBNR~CAxAM|@gAtBcDfEUf@WrA\"},{\"coded_array\":\"qaegGss|_@Yj@yIdYMfADv@\"},{\"coded_array\":\"mmegGat{_@oBjB\"},{\"coded_array\":\"}pegGup{_@xBxL~@pG\"},{\"coded_array\":\"ckegGizz_@q\\\\dN_]rH\"},{\"coded_array\":\"ufggGoaz_@aEdAiCX\"}]"%>, | ||
// [ | ||
// {"longitude": -122.214897, "latitude": 37.772323}, | ||
// {"longitude": -157.821856, "latitude": 21.291982}, | ||
// {"longitude": 178.431, "latitude": -18.142599}, | ||
// {"longitude": 153.027892, "latitude": -27.46758} | ||
// ], | ||
// [ | ||
// {"longitude": -120.214897, "latitude": 30.772323, "strokeColor": "#ccc" }, | ||
// {"longitude": -10.821856, "latitude": 50.291982} | ||
// ] | ||
// ]; | ||
// | ||
// Gmaps4Rails.polylines = flightPlanCoordinates; | ||
|
||
// var circles = [ | ||
// {"longitude": -122.214897, "latitude": 37.772323, "radius": 1000000}, | ||
// {"longitude": 122.214897, "latitude": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"} | ||
// ]; | ||
|
||
// Gmaps4Rails.direction_settings.origin = "paris"; | ||
// Gmaps4Rails.direction_settings.destination = "marseille"; | ||
// Gmaps4Rails.direction_settings.display_panel = true; | ||
|
||
|
||
//Gmaps4Rails.circles = circles; | ||
|
||
|
||
|
||
<% options.each do |key, value| #loop through options hash | ||
case key | ||
when "map_options" | ||
break | ||
when "direction" %> | ||
Gmaps4Rails.direction_conf.origin = "<%= value["data"]["from"] %>"; | ||
Gmaps4Rails.direction_conf.destination = "<%= value["data"]["to"] %>"; | ||
<% value["options"] ||= [] | ||
value["options"].each do |option_k, option_v| | ||
if option_k == "waypoints" | ||
waypoints = [] | ||
option_v.each do |waypoint| | ||
waypoints << { "location" => waypoint, "stopover" => true }.to_json | ||
end %> | ||
Gmaps4Rails.direction_conf.waypoints = [<%=raw waypoints * (", ") %>]; | ||
<% else #option_k != "waypoint" %> | ||
Gmaps4Rails.direction_conf.<%= option_k %> = <%=raw option_v.is_a?(Numeric) ? option_v : "'#{option_v}'" %>; | ||
<% end | ||
end #end .each %> | ||
Gmaps4Rails.create_direction(); | ||
<% | ||
else #default behaviour in case condition%> | ||
Gmaps4Rails.<%= key %> = <%=raw value["data"] %>; | ||
<% value["options"] ||= [] | ||
value["options"].each do |option_k, option_v| %> | ||
Gmaps4Rails.<%= key %>_conf.<%= option_k %> = <%=raw option_v.is_a?(Numeric) ? option_v : "'#{option_v}'" %>; | ||
<% end %> | ||
Gmaps4Rails.create_<%= key %>(); | ||
<% end | ||
end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
== Google Maps for Rails (gmaps4rails) | ||
|
||
|
||
Gmaps4rails is developped to simply create a Google Map (Gmaps) from: | ||
|
||
- model instances (say Users), | ||
|
||
- your own json | ||
|
||
It's based on Ruby on Rails 3 Engines and uses Google Maps API V3 with Marker Clusterer in option. | ||
|
||
== Installation | ||
|
||
gem install gmaps4rails | ||
|
||
== Requirements | ||
- <%= yield :head %> (in your header) | ||
- <%= yield :scripts %> (in your footer) | ||
- config.serve_static_assets = true (in your production.rb) | ||
- jQuery (used for ajax json, not mandatory if you only use the 'json' option) | ||
|
||
== Basic configuration | ||
In your model, add: | ||
|
||
acts_as_gmappable | ||
|
||
def gmaps4rails_address | ||
self.address #describe how to retrieve the address from your model | ||
end | ||
|
||
Create a migration and add the following fields to your table (here users): | ||
|
||
add_column :users, :latitude, :float #you can change the name, see wiki | ||
add_column :users, :longitude, :float #you can change the name, see wiki | ||
add_column :users, :gmaps, :boolean #not mandatory, see wiki | ||
|
||
== How to? | ||
=== QuickStart! | ||
Say you have a User model and you want to display all the users on a map. | ||
In your view: | ||
|
||
<%= gmaps4rails_map("User") %> | ||
|
||
Done! | ||
|
||
=== Same Result, alternative solution | ||
With this version, you won't need jQuery. | ||
In your controller: | ||
|
||
@json = User.all.to_gmaps4rails | ||
|
||
In your view: | ||
|
||
<%= gmaps4rails(@json) %> | ||
|
||
Done again! | ||
|
||
== Options | ||
|
||
* Info window | ||
|
||
* Custom Marker | ||
|
||
* Scopes | ||
|
||
* Create from your own json | ||
|
||
* Geocode directly your address and retrieve coordinates. | ||
|
||
* Auto-adjust the map to your markers | ||
|
||
* Refresh your map on the fly with Javascript and Ajax | ||
|
||
* {More details in the Wiki}[https://github.com/apneadiving/Google-Maps-for-Rails/wiki] | ||
|
||
== Todo? | ||
|
||
Feel free ton contact us, you have your say. | ||
|
||
== Copyright | ||
MIT license. | ||
|
||
Authors: Benjamin Roth, David Ruyer | ||
|
||
Contributor: Alex Vorobiev |
Oops, something went wrong.