gmaps4rails 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -10
- data/app/controllers/gmaps4rails/gmaps_controller.rb +5 -2
- data/lib/acts_as_gmappable/base.rb +21 -0
- data/lib/array.rb +13 -0
- data/lib/gmaps4rails.rb +3 -1
- data/public/javascripts/gmaps4rails.js +0 -1
- metadata +5 -5
- data/app/views/gmaps4rails/gmaps/index.js.erb +0 -19
data/README.rdoc
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
== Gmaps4rails
|
2
2
|
|
3
|
-
Gmaps4rails is developped to simply create a Google Map (Gmaps)
|
4
|
-
|
5
|
-
|
3
|
+
Gmaps4rails is developped to simply create a Google Map (Gmaps) from:
|
4
|
+
|
5
|
+
- model instances (say Users),
|
6
|
+
|
7
|
+
- your own json
|
8
|
+
|
9
|
+
It's based on Ruby on Rails 3 Engines and uses Google Maps API V3 with Marker Clusterer in option.
|
10
|
+
|
6
11
|
|
7
12
|
== Installation
|
8
13
|
|
9
14
|
gem install gmaps4rails
|
10
15
|
|
11
16
|
== Requirements
|
12
|
-
- jQuery (used for ajax json)
|
13
17
|
- <%= yield :head %> (in your header)
|
14
18
|
- <%= yield :scripts %> (in your footer)
|
15
19
|
- config.serve_static_assets = true (in your production.rb)
|
20
|
+
- jQuery (used for ajax json, not mandatory if you only use the 'json' option)
|
16
21
|
|
17
|
-
==
|
18
|
-
Say you have a User model.
|
22
|
+
== Basic configuration
|
19
23
|
In your model, add:
|
20
24
|
|
21
25
|
acts_as_gmappable
|
@@ -24,16 +28,33 @@ In your model, add:
|
|
24
28
|
self.address #describe how to retrieve the address from your model
|
25
29
|
end
|
26
30
|
|
27
|
-
Create a migration and add the following fields to your table:
|
31
|
+
Create a migration and add the following fields to your table (here users):
|
28
32
|
|
29
33
|
add_column :users, :latitude, :float
|
30
34
|
add_column :users, :longitude, :float
|
31
35
|
add_column :users, :gmaps, :boolean
|
32
36
|
|
37
|
+
== How to?
|
38
|
+
=== QuickStart!
|
39
|
+
Say you have a User model and you want to display all the users on a map.
|
33
40
|
In your view:
|
34
41
|
|
35
42
|
<%= gmaps4rails_map("User") %>
|
36
43
|
|
44
|
+
Done!
|
45
|
+
|
46
|
+
=== Same Result, alternative solution
|
47
|
+
With this version, you won't need jQuery.
|
48
|
+
In your controller:
|
49
|
+
|
50
|
+
@json = User.all.to_gmaps4rails
|
51
|
+
|
52
|
+
In your view:
|
53
|
+
|
54
|
+
<%= gmaps4rails_map(@json, { "processing" => 'json' }) %>
|
55
|
+
|
56
|
+
Done again!
|
57
|
+
|
37
58
|
== Options
|
38
59
|
|
39
60
|
=== Add an info window
|
@@ -93,12 +114,9 @@ Then in your view:
|
|
93
114
|
Or with options as well:
|
94
115
|
|
95
116
|
<%= gmaps4rails_map(@json, {"processing" => 'json', "map_center_longitude" => "90"}) %>
|
96
|
-
|
97
117
|
|
98
118
|
== Todo?
|
99
119
|
|
100
|
-
Maybe use Geokit to handle the geocoding stuff.
|
101
|
-
|
102
120
|
Feel free ton contact me, you have your say. I hope I'll have time enough to improve it.
|
103
121
|
|
104
122
|
== Copyright
|
@@ -9,11 +9,14 @@ module Gmaps4rails
|
|
9
9
|
|
10
10
|
# The split returns the array [scope_name, arg1, arg2, ...]
|
11
11
|
if @scope && !@scope.empty? && @model.gmaps4rails_trusted_scopes.include?(@scope.split(/\(| *, *|\)/)[0])
|
12
|
-
|
12
|
+
object = eval("#{@model}.#{@scope}") # Cannot use send with lambda scope
|
13
13
|
# because the arguments have to be separated
|
14
|
+
@objects = object.to_gmaps4rails
|
14
15
|
else
|
15
|
-
@objects = @model.all
|
16
|
+
@objects = @model.all.to_gmaps4rails
|
16
17
|
end
|
18
|
+
|
19
|
+
render :json => @objects
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -3,6 +3,17 @@ require 'uri'
|
|
3
3
|
require 'crack'
|
4
4
|
|
5
5
|
module Gmaps4rails
|
6
|
+
|
7
|
+
def Gmaps4rails.create_json(object)
|
8
|
+
"{\"description\": \"#{object.gmaps4rails_infowindow}\",
|
9
|
+
\"longitude\": \"#{object.gmaps4rails_longitude}\",
|
10
|
+
\"latitude\": \"#{object.gmaps4rails_latitude}\",
|
11
|
+
\"picture\": \"#{object.gmaps4rails_marker_picture['picture']}\",
|
12
|
+
\"width\": \"#{object.gmaps4rails_marker_picture['width']}\",
|
13
|
+
\"height\": \"#{object.gmaps4rails_marker_picture['height']}\"
|
14
|
+
}"
|
15
|
+
end
|
16
|
+
|
6
17
|
module ActsAsGmappable
|
7
18
|
|
8
19
|
module Base
|
@@ -40,6 +51,16 @@ module Gmaps4rails
|
|
40
51
|
def self.gmaps4rails_trusted_scopes
|
41
52
|
[]
|
42
53
|
end
|
54
|
+
|
55
|
+
def to_gmaps4rails
|
56
|
+
json = "["
|
57
|
+
if (!(self.gmaps4rails_latitude == "" || self.gmaps4rails_longitude == ""))
|
58
|
+
json += Gmaps4rails.create_json(self)
|
59
|
+
json += ","
|
60
|
+
end
|
61
|
+
json.chop!
|
62
|
+
json += "]"
|
63
|
+
end
|
43
64
|
|
44
65
|
def get_coordinates
|
45
66
|
if self.gmaps4rails_address.nil? || self.gmaps4rails_address.empty?
|
data/lib/array.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Array
|
2
|
+
def to_gmaps4rails
|
3
|
+
json = "["
|
4
|
+
each do |object|
|
5
|
+
if (!(object.gmaps4rails_latitude == "" || object.gmaps4rails_longitude == ""))
|
6
|
+
json += Gmaps4rails.create_json(object)
|
7
|
+
json += ","
|
8
|
+
end
|
9
|
+
end
|
10
|
+
json.chop!
|
11
|
+
json += "]"
|
12
|
+
end
|
13
|
+
end
|
data/lib/gmaps4rails.rb
CHANGED
@@ -2,6 +2,7 @@ if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
2
2
|
module Gmaps4rails
|
3
3
|
require "rails"
|
4
4
|
require "action_controller"
|
5
|
+
require 'array'
|
5
6
|
require 'application_helper'
|
6
7
|
require 'acts_as_gmappable/base'
|
7
8
|
|
@@ -9,7 +10,8 @@ if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
9
10
|
initializer "static assets" do |app|
|
10
11
|
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
11
12
|
end
|
12
|
-
|
13
|
+
end
|
14
|
+
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps4rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Roth
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-02-
|
19
|
+
date: 2011-02-15 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -45,10 +45,10 @@ files:
|
|
45
45
|
- app/controllers/gmaps4rails/gmaps_controller.rb
|
46
46
|
- app/helpers/gmaps4rails/gmaps_helper.rb
|
47
47
|
- app/views/gmaps4rails/_gmaps4rails.html.erb
|
48
|
-
- app/views/gmaps4rails/gmaps/index.js.erb
|
49
48
|
- config/routes.rb
|
50
49
|
- lib/acts_as_gmappable/base.rb
|
51
50
|
- lib/application_helper.rb
|
51
|
+
- lib/array.rb
|
52
52
|
- lib/gmaps4rails.rb
|
53
53
|
- lib/rails/generators/gmaps4rails/gmaps4rails_generator.rb
|
54
54
|
- lib/rails/generators/gmaps4rails/templates/initializer.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
[
|
2
|
-
<%
|
3
|
-
@objects.each do |object|
|
4
|
-
# lat = object.gmaps4rails_latitude.nil? ? "" : object.gmaps4rails_latitude
|
5
|
-
# long = object.gmaps4rails_longitude.nil? ? "" : object.gmaps4rails_longitude
|
6
|
-
if (!(object.gmaps4rails_latitude == "" || object.gmaps4rails_longitude == ""))
|
7
|
-
%>
|
8
|
-
{"description": "<%=raw object.gmaps4rails_infowindow %>",
|
9
|
-
"longitude": "<%= object.gmaps4rails_longitude %>",
|
10
|
-
"latitude": "<%= object.gmaps4rails_latitude %>",
|
11
|
-
"picture": "<%= object.gmaps4rails_marker_picture["picture"] %>",
|
12
|
-
"width": "<%= object.gmaps4rails_marker_picture["width"] %>",
|
13
|
-
"height": "<%= object.gmaps4rails_marker_picture["height"] %>"
|
14
|
-
} <%= ',' unless object == @objects.last %>
|
15
|
-
<%
|
16
|
-
end
|
17
|
-
end
|
18
|
-
%>
|
19
|
-
]
|