gmaps4rails 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +1 -0
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +1 -1
- data/lib/generators/gmaps4rails/install_generator.rb +1 -1
- data/lib/gmaps4rails/base.rb +80 -75
- data/lib/gmaps4rails/extensions/hash.rb +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -46,13 +46,13 @@ To make Rails serve the assets (javascripts, stylesheets and marker images) you
|
|
46
46
|
You even don't need the `yield :head` if you include `require gmaps4rails` in your CSS manifest.
|
47
47
|
|
48
48
|
- if you are using Rails 3.0:
|
49
|
-
|
49
|
+
see para below to be sure everything will work in production.
|
50
50
|
|
51
51
|
- finally you can just copy assets to your application's public/stylesheets, public/javascripts/gmaps4rails and public/images. It's recommended to do this in production so that you can let your webserver serve them rather than go through Rails each time they are requested. There's a generator to help you with that:
|
52
52
|
|
53
53
|
rails generate gmaps4rails:install
|
54
54
|
|
55
|
-
This will copy the coffeescript files if you're running Rails 3.1 or the js files
|
55
|
+
This will copy the coffeescript files if you're running Rails 3.1 or the js files for Rails 3.0.x
|
56
56
|
|
57
57
|
== Basic configuration
|
58
58
|
In your model, add:
|
@@ -16,7 +16,7 @@ if enable_css == true and options[:scripts].nil? %>
|
|
16
16
|
<% else %>
|
17
17
|
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry<%= g_libraries(options[:map_options].try(:[], :libraries)) %>"></script>
|
18
18
|
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/src/infobox.js"></script>
|
19
|
-
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/
|
19
|
+
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.1/src/markerclusterer.js"></script>
|
20
20
|
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
|
21
21
|
<% end %>
|
22
22
|
|
@@ -12,7 +12,7 @@ module Gmaps4rails
|
|
12
12
|
copy_file '../../../app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee', 'app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee'
|
13
13
|
copy_file '../../../app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee', 'app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee'
|
14
14
|
copy_file '../../../app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee', 'app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee'
|
15
|
-
copy_file '../../../
|
15
|
+
copy_file '../../../public/stylesheets/gmaps4rails.css', 'app/assets/stylesheets/gmaps4rails.css'
|
16
16
|
else
|
17
17
|
#I don't copy manifests, kind of useless
|
18
18
|
copy_file '../../../public/javascripts/gmaps4rails/gmaps4rails.base.js', 'public/javascripts/gmaps4rails.base.js'
|
data/lib/gmaps4rails/base.rb
CHANGED
@@ -42,14 +42,6 @@ module Gmaps4rails
|
|
42
42
|
def Gmaps4rails.sidebar(object)
|
43
43
|
return "\"sidebar\": \"#{object.gmaps4rails_sidebar}\"," if object.respond_to?("gmaps4rails_sidebar")
|
44
44
|
end
|
45
|
-
|
46
|
-
def Gmaps4rails.get_map_id(hash)
|
47
|
-
hash.nil? || hash.try(:[], "id").nil? ? DEFAULT_MAP_ID : hash["id"]
|
48
|
-
end
|
49
|
-
|
50
|
-
def Gmaps4rails.get_constructor(hash)
|
51
|
-
hash.nil? || hash.try(:[], "provider").nil? ? "Gmaps4RailsGoogle()" : "Gmaps4Rails#{hash["provider"].capitalize}()"
|
52
|
-
end
|
53
45
|
|
54
46
|
# Returns picture options if gmaps4rails_marker_picture is defined in the model
|
55
47
|
def Gmaps4rails.picture(object)
|
@@ -70,7 +62,6 @@ module Gmaps4rails
|
|
70
62
|
# * address: string, mandatory
|
71
63
|
# * lang: to set the language one wants the result to be translated (default is english)
|
72
64
|
# * raw: to get the raw response from google, default is false
|
73
|
-
|
74
65
|
def Gmaps4rails.geocode(address, lang="en", raw = false)
|
75
66
|
if address.nil? || address.empty?
|
76
67
|
raise Gmaps4rails::GeocodeInvalidQuery, "You must provide an address"
|
@@ -89,7 +80,6 @@ module Gmaps4rails
|
|
89
80
|
# * start_end: Hash { "from" => string, "to" => string}, mandatory
|
90
81
|
# * options: details given in the github's wiki
|
91
82
|
# * output: could be "pretty", "raw" or "clean"; filters the output from google
|
92
|
-
|
93
83
|
#output could be raw, pretty or clean
|
94
84
|
def Gmaps4rails.destination(start_end, options={}, output="pretty")
|
95
85
|
if start_end["from"].nil? || start_end["to"].empty?
|
@@ -106,7 +96,6 @@ module Gmaps4rails
|
|
106
96
|
end #end destination
|
107
97
|
|
108
98
|
# To create valid js, this method escapes everything but Numeric, true or false
|
109
|
-
|
110
99
|
def Gmaps4rails.filter(data)
|
111
100
|
return data if data.is_a?(Numeric) || data.is_a?(TrueClass) || data.is_a?(FalseClass)
|
112
101
|
"'#{data}'"
|
@@ -180,11 +169,74 @@ module Gmaps4rails
|
|
180
169
|
end #end resp test
|
181
170
|
end
|
182
171
|
|
172
|
+
###### JS CREATION #######
|
173
|
+
|
183
174
|
def Gmaps4rails.js_function_name(hash)
|
184
175
|
"load_" + Gmaps4rails.get_map_id(hash[:map_options])
|
185
176
|
end
|
186
177
|
|
187
|
-
def Gmaps4rails.
|
178
|
+
def Gmaps4rails.get_map_id(hash)
|
179
|
+
hash.nil? || hash[:id].nil? ? DEFAULT_MAP_ID : hash[:id]
|
180
|
+
end
|
181
|
+
|
182
|
+
def Gmaps4rails.get_constructor(hash)
|
183
|
+
hash.nil? || hash[:provider].nil? ? "Gmaps4RailsGoogle()" : "Gmaps4Rails#{hash[:provider].capitalize}()"
|
184
|
+
end
|
185
|
+
|
186
|
+
def Gmaps4rails.create_map_js(map_hash, map_id)
|
187
|
+
output = Array.new
|
188
|
+
skipped_keys = [:class, :container_class]
|
189
|
+
map_hash.each do |option_k, option_v|
|
190
|
+
unless skipped_keys.include? option_k.to_sym
|
191
|
+
case option_k.to_sym
|
192
|
+
when :bounds, :raw #particular case, render the content unescaped
|
193
|
+
output << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
194
|
+
else
|
195
|
+
output << "#{map_id}.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
output
|
200
|
+
end
|
201
|
+
|
202
|
+
def Gmaps4rails.create_general_js(hash, map_id, category)
|
203
|
+
hash = hash.with_indifferent_access
|
204
|
+
output = Array.new
|
205
|
+
output << "#{map_id}.#{category} = #{hash[:data]};"
|
206
|
+
hash[:options] ||= Array.new
|
207
|
+
hash[:options].each do |option_k, option_v|
|
208
|
+
if option_k.to_sym == :raw
|
209
|
+
output << "#{map_id}.#{category}_conf.#{option_k} = #{option_v};"
|
210
|
+
else
|
211
|
+
output << "#{map_id}.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
output << "#{map_id}.create_#{category}();"
|
215
|
+
output
|
216
|
+
end
|
217
|
+
|
218
|
+
def Gmaps4rails.create_direction_js(hash, map_id)
|
219
|
+
hash = hash.with_indifferent_access
|
220
|
+
output = Array.new
|
221
|
+
output << "#{map_id}.direction_conf.origin = '#{hash["data"]["from"]}';"
|
222
|
+
output << "#{map_id}.direction_conf.destination = '#{hash["data"]["to"]}';"
|
223
|
+
hash[:options] ||= Array.new
|
224
|
+
hash[:options].each do |option_k, option_v|
|
225
|
+
if option_k.to_sym == :waypoints
|
226
|
+
waypoints = Array.new
|
227
|
+
option_v.each do |waypoint|
|
228
|
+
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
229
|
+
end
|
230
|
+
output << "#{map_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
231
|
+
else #option_k != "waypoint"
|
232
|
+
output << "#{map_id}.direction_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
233
|
+
end
|
234
|
+
end #end .each
|
235
|
+
output << "#{map_id}.create_direction();"
|
236
|
+
output
|
237
|
+
end
|
238
|
+
|
239
|
+
def Gmaps4rails.create_js_from_hash(hash)
|
188
240
|
#the variable 'options' must have the following structure
|
189
241
|
#{
|
190
242
|
# :map_options => hash,
|
@@ -195,78 +247,31 @@ module Gmaps4rails
|
|
195
247
|
# :direction => { :data => hash, :options => hash },
|
196
248
|
# :kml => { :data => json, :options => hash }
|
197
249
|
#}
|
198
|
-
# "map_options", "scripts" and "direction" must be treated separately because there content is slightly different from the others:
|
199
|
-
# - "map_options" and "scripts" don't contain interesting data for the view
|
200
|
-
# - "direction" has a hash as a data and waypoints options must be processed properly
|
201
|
-
#
|
202
|
-
#TODO: clean up this method
|
203
250
|
result = Array.new
|
204
|
-
map_id = "Gmaps." +
|
251
|
+
map_id = "Gmaps." + Gmaps4rails.get_map_id(hash[:map_options])
|
205
252
|
|
206
253
|
#means we are creating a new map
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
unless hash[:map_options].nil?
|
213
|
-
hash[:map_options].each do |option_k, option_v|
|
214
|
-
case option_k.to_sym
|
215
|
-
when :bounds #particular case, render the content unescaped
|
216
|
-
result << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
217
|
-
when :raw #particular case, render the content unescaped
|
218
|
-
result << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
219
|
-
when :class #do nothing
|
220
|
-
when :container_class #do nothing
|
221
|
-
else
|
222
|
-
result << "#{map_id}.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
result << "#{map_id}.initialize();"
|
227
|
-
end
|
228
|
-
|
254
|
+
result << "#{map_id} = new #{Gmaps4rails.get_constructor hash[:map_options] }" + ";"
|
255
|
+
result << "function #{Gmaps4rails.js_function_name hash }() {"
|
256
|
+
result << Gmaps4rails.create_map_js(hash[:map_options], map_id) unless hash[:map_options].nil?
|
257
|
+
result << "#{map_id}.initialize();"
|
258
|
+
|
229
259
|
hash.each do |category, content| #loop through options hash
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
content[:options] ||= Array.new
|
237
|
-
content[:options].each do |option_k, option_v|
|
238
|
-
if option_k.to_sym == :waypoints
|
239
|
-
waypoints = Array.new
|
240
|
-
option_v.each do |waypoint|
|
241
|
-
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
242
|
-
end
|
243
|
-
result << "#{map_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
244
|
-
else #option_k != "waypoint"
|
245
|
-
result << "#{map_id}.direction_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
246
|
-
end
|
247
|
-
end #end .each
|
248
|
-
result << "#{map_id}.create_direction();"
|
249
|
-
else #default behaviour
|
250
|
-
result << "#{map_id}.#{category} = #{content[:data]};"
|
251
|
-
content[:options] ||= Array.new
|
252
|
-
content[:options].each do |option_k, option_v|
|
253
|
-
if option_k.to_sym == :raw
|
254
|
-
result << "#{map_id}.#{category}_conf.#{option_k} = #{option_v};"
|
255
|
-
else
|
256
|
-
result << "#{map_id}.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
257
|
-
end
|
260
|
+
skipped_categories = [:map_options, :last_map, :scripts]
|
261
|
+
unless skipped_categories.include? category.to_sym
|
262
|
+
if category.to_sym == :direction
|
263
|
+
result << Gmaps4rails.create_direction_js(content, map_id)
|
264
|
+
else
|
265
|
+
result << Gmaps4rails.create_general_js(content, map_id, category)
|
258
266
|
end
|
259
|
-
|
260
|
-
end
|
267
|
+
end
|
261
268
|
end
|
262
269
|
result << "#{map_id}.adjustMapToBounds();"
|
263
270
|
result << "#{map_id}.callback();"
|
264
271
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
result << "window.onload = function() { Gmaps.loadMaps(); };"
|
269
|
-
end
|
272
|
+
result << "};"
|
273
|
+
if hash[:last_map].nil? || hash[:last_map] == true
|
274
|
+
result << "window.onload = function() { Gmaps.loadMaps(); };"
|
270
275
|
end
|
271
276
|
|
272
277
|
result * ('
|
@@ -2,8 +2,8 @@ class Hash
|
|
2
2
|
|
3
3
|
# this method extracts all info from the hash to create javascript
|
4
4
|
# this javascript is then rendered raw to the view so it can be interpreted and executed
|
5
|
-
def to_gmaps4rails
|
6
|
-
Gmaps4rails.create_js_from_hash(self.with_indifferent_access
|
5
|
+
def to_gmaps4rails
|
6
|
+
Gmaps4rails.create_js_from_hash(self.with_indifferent_access)
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps4rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-20 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: crack
|
17
|
-
requirement: &
|
17
|
+
requirement: &2152433280 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2152433280
|
26
26
|
description: ! 'Enables easy display of items (taken from a Rails 3 model) on a Google
|
27
27
|
Maps (JS API V3), OpenLayers, Mapquest and Bing. Geocoding + Directions included.
|
28
28
|
Provides much options: markers customization, infowindows, auto-adjusted zoom, polylines,
|