gmaps4rails 0.11.1 → 1.0.0
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 +6 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +18 -20
- data/lib/gmaps4rails/base.rb +95 -0
- data/lib/gmaps4rails/extensions/hash.rb +3 -67
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +13 -2
- data/public/javascripts/gmaps4rails/all_apis.js +5 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +147 -112
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +182 -171
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +269 -235
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +135 -125
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +227 -218
- data/public/stylesheets/gmaps4rails.css +2 -2
- metadata +9 -111
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/controllers/users_controller.rb +0 -60
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/helpers/users_helper.rb +0 -3
- data/test/dummy/app/models/user.rb +0 -38
- data/test/dummy/config/application.rb +0 -41
- data/test/dummy/config/boot.rb +0 -6
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -26
- data/test/dummy/config/environments/production.rb +0 -49
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/routes.rb +0 -7
- data/test/dummy/db/migrate/20110306182914_create_users.rb +0 -21
- data/test/dummy/db/migrate/20110430081624_add_addresses_to_users.rb +0 -11
- data/test/dummy/db/migrate/20110430083824_remove_address_from_users.rb +0 -9
- data/test/dummy/db/schema.rb +0 -35
- data/test/dummy/db/seeds.rb +0 -7
- data/test/dummy/spec/base/base_spec.rb +0 -127
- data/test/dummy/spec/helpers/gmaps4rails_helper_spec.rb +0 -13
- data/test/dummy/spec/javascripts/support/jasmine_config.rb +0 -23
- data/test/dummy/spec/javascripts/support/jasmine_runner.rb +0 -20
- data/test/dummy/spec/models/user_spec.rb +0 -284
- data/test/dummy/spec/requests/users_spec.rb +0 -22
- data/test/dummy/spec/spec_helper.rb +0 -41
- data/test/dummy/spec/support/factories.rb +0 -20
- data/test/dummy/spec/support/matchers.rb +0 -7
- data/test/dummy31/app/controllers/application_controller.rb +0 -3
- data/test/dummy31/app/controllers/users_controller.rb +0 -83
- data/test/dummy31/app/helpers/application_helper.rb +0 -2
- data/test/dummy31/app/helpers/users_helper.rb +0 -2
- data/test/dummy31/app/models/user.rb +0 -7
- data/test/dummy31/config/application.rb +0 -43
- data/test/dummy31/config/boot.rb +0 -6
- data/test/dummy31/config/environment.rb +0 -5
- data/test/dummy31/config/environments/development.rb +0 -27
- data/test/dummy31/config/environments/production.rb +0 -51
- data/test/dummy31/config/environments/test.rb +0 -39
- data/test/dummy31/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy31/config/initializers/inflections.rb +0 -10
- data/test/dummy31/config/initializers/mime_types.rb +0 -5
- data/test/dummy31/config/initializers/secret_token.rb +0 -7
- data/test/dummy31/config/initializers/session_store.rb +0 -8
- data/test/dummy31/config/initializers/wrap_parameters.rb +0 -12
- data/test/dummy31/config/routes.rb +0 -61
- data/test/dummy31/db/migrate/20110809134019_create_users.rb +0 -13
- data/test/dummy31/db/schema.rb +0 -25
- data/test/dummy31/db/seeds.rb +0 -7
data/README.rdoc
CHANGED
@@ -41,6 +41,8 @@ To make Rails serve the assets (javascripts, stylesheets and marker images) you
|
|
41
41
|
|
42
42
|
* //= require gmaps4rails/openlayers.js
|
43
43
|
|
44
|
+
* //= require gmaps4rails/all_apis.js
|
45
|
+
|
44
46
|
You even don't need the `yield :head` if you include `require gmaps4rails` in your CSS manifest.
|
45
47
|
|
46
48
|
- if you are using Rails 3.0:
|
@@ -97,12 +99,14 @@ Done!
|
|
97
99
|
|
98
100
|
* Refresh your map on the fly with Javascript (and Ajax)
|
99
101
|
|
102
|
+
* KML support
|
103
|
+
|
104
|
+
* Easy multimap
|
105
|
+
|
100
106
|
* {More details in the Wiki}[https://github.com/apneadiving/Google-Maps-for-Rails/wiki]
|
101
107
|
|
102
108
|
== Todo?
|
103
109
|
|
104
|
-
* Integrate Markers with Label: http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.2/
|
105
|
-
|
106
110
|
Feel free ton contact us, you have your say.
|
107
111
|
|
108
112
|
== Copyright
|
@@ -1,28 +1,30 @@
|
|
1
1
|
<% #thanks to enable_css, user can avoid this css to be loaded
|
2
|
-
if enable_css == true %>
|
2
|
+
if enable_css == true && options[:scripts].nil? %>
|
3
3
|
<% content_for :head do %>
|
4
4
|
<%= stylesheet_link_tag 'gmaps4rails' %>
|
5
5
|
<% end %>
|
6
6
|
<% end %>
|
7
7
|
<% content_for :scripts do %>
|
8
|
-
<% if enable_js == true %>
|
9
|
-
<% case options[
|
8
|
+
<% if enable_js == true && options[:scripts].try(:to_sym) != :none %>
|
9
|
+
<% case options[:map_options].try(:[], :provider) %>
|
10
10
|
<% when "openlayers" %>
|
11
11
|
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
|
12
12
|
<% when "mapquest" %>
|
13
|
-
<script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key
|
13
|
+
<script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key=<%= options[:map_options].try(:[], :provider_key) %>"></script>
|
14
14
|
<% when "bing" %>
|
15
15
|
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
|
16
16
|
<% else %>
|
17
|
-
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry<%= g_libraries(options[
|
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
19
|
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.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
|
|
23
|
-
<% if Rails::VERSION::MINOR < 1 %>
|
24
|
-
|
25
|
-
|
23
|
+
<% if Rails::VERSION::MAJOR >= 3 and Rails::VERSION::MINOR < 1 %>
|
24
|
+
<% unless options[:scripts].try(:to_sym) == :api %>
|
25
|
+
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.base.js' %>
|
26
|
+
<% end %>
|
27
|
+
<% case options[:map_options].try(:[], :provider) %>
|
26
28
|
<% when "openlayers" %>
|
27
29
|
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.openlayers.js' %>
|
28
30
|
<% when "mapquest" %>
|
@@ -35,28 +37,24 @@ if enable_css == true %>
|
|
35
37
|
<% end %>
|
36
38
|
<% end %>
|
37
39
|
<script type="text/javascript" charset="utf-8">
|
38
|
-
function gmaps4rails_init() {
|
39
|
-
<% #true is passed here to trigger map initialization %>
|
40
|
-
<%=raw options.to_gmaps4rails(true) %>
|
41
|
-
};
|
42
40
|
|
43
|
-
|
41
|
+
<%=raw options.to_gmaps4rails %>
|
44
42
|
|
45
43
|
</script>
|
46
44
|
<% end %>
|
47
45
|
|
48
46
|
|
49
|
-
<% case options[
|
47
|
+
<% case options[:map_options].try(:[], :provider) %>
|
50
48
|
<% when "mapquest" %>
|
51
|
-
<div id="
|
49
|
+
<div id="<%= gmaps_map_id(options) %>" style="width:750px; height:475px;">
|
52
50
|
<!-- TODO: change this style dynamically -->
|
53
51
|
</div>
|
54
52
|
<% when "bing" %>
|
55
|
-
<div id="<%= options
|
56
|
-
<div id="<%= options
|
53
|
+
<div id="<%= gmaps_container_id(options) %>" >
|
54
|
+
<div id="<%= gmaps_map_id(options) %>" class="bing_map"></div>
|
57
55
|
</div>
|
58
56
|
<% else %>
|
59
|
-
<div
|
60
|
-
<div id="<%= options
|
57
|
+
<div class="<%= gmaps_container_id(options) %>">
|
58
|
+
<div id="<%= gmaps_map_id(options) %>" class="<%= gmaps_map_class(options) %>"></div>
|
61
59
|
</div>
|
62
|
-
<% end %>
|
60
|
+
<% end %>
|
data/lib/gmaps4rails/base.rb
CHANGED
@@ -3,6 +3,7 @@ require 'uri'
|
|
3
3
|
require 'crack'
|
4
4
|
|
5
5
|
module Gmaps4rails
|
6
|
+
DEFAULT_MAP_ID = "map"
|
6
7
|
|
7
8
|
class GeocodeStatus < StandardError; end
|
8
9
|
class GeocodeNetStatus < StandardError; end
|
@@ -41,6 +42,14 @@ module Gmaps4rails
|
|
41
42
|
def Gmaps4rails.sidebar(object)
|
42
43
|
return "\"sidebar\": \"#{object.gmaps4rails_sidebar}\"," if object.respond_to?("gmaps4rails_sidebar")
|
43
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
|
44
53
|
|
45
54
|
# Returns picture options if gmaps4rails_marker_picture is defined in the model
|
46
55
|
def Gmaps4rails.picture(object)
|
@@ -170,5 +179,91 @@ module Gmaps4rails
|
|
170
179
|
Response was: #{response}"
|
171
180
|
end #end resp test
|
172
181
|
end
|
182
|
+
|
183
|
+
def Gmaps4rails.js_function_name(hash)
|
184
|
+
"load_" + Gmaps4rails.get_map_id(hash[:map_options])
|
185
|
+
end
|
186
|
+
|
187
|
+
def Gmaps4rails.create_js_from_hash(hash, edit_map_with_id = false)
|
188
|
+
#the variable 'options' must have the following structure
|
189
|
+
#{
|
190
|
+
# :map_options => hash,
|
191
|
+
# :markers => { :data => json, :options => hash },
|
192
|
+
# :polylines => { :data => json, :options => hash },
|
193
|
+
# :polygons => { :data => json, :options => hash },
|
194
|
+
# :circles => { :data => json, :options => hash },
|
195
|
+
# :direction => { :data => hash, :options => hash },
|
196
|
+
# :kml => { :data => json, :options => hash }
|
197
|
+
#}
|
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
|
+
result = Array.new
|
204
|
+
map_id = edit_map_with_id || Gmaps4rails.get_map_id(hash[:map_options])
|
205
|
+
map_id = "Gmaps." + map_id
|
206
|
+
|
207
|
+
#means we are creating a new map
|
208
|
+
if edit_map_with_id == false
|
209
|
+
|
210
|
+
js_object_constructor = Gmaps4rails.get_constructor(hash[:map_options])
|
211
|
+
result << "#{map_id} = new #{js_object_constructor}" + ";"
|
212
|
+
result << "function #{Gmaps4rails.js_function_name(hash)}() {"
|
213
|
+
#extract map_options
|
214
|
+
unless hash[:map_options].nil?
|
215
|
+
hash[:map_options].each do |option_k, option_v|
|
216
|
+
if option_k.to_sym == :bounds #particular case
|
217
|
+
result << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
218
|
+
else
|
219
|
+
result << "#{map_id}.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
result << "#{map_id}.initialize();"
|
225
|
+
end
|
226
|
+
|
227
|
+
hash.each do |category, content| #loop through options hash
|
228
|
+
if [:map_options, :last_map, :scripts].include? category.to_sym
|
229
|
+
#nothing to do
|
230
|
+
elsif category.to_sym == :direction
|
231
|
+
result << "#{map_id}.direction_conf.origin = '#{content["data"]["from"]}';"
|
232
|
+
result << "#{map_id}.direction_conf.destination = '#{content["data"]["to"]}';"
|
233
|
+
|
234
|
+
content[:options] ||= Array.new
|
235
|
+
content[:options].each do |option_k, option_v|
|
236
|
+
if option_k == "waypoints"
|
237
|
+
waypoints = Array.new
|
238
|
+
option_v.each do |waypoint|
|
239
|
+
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
240
|
+
end
|
241
|
+
result << "#{map_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
242
|
+
else #option_k != "waypoint"
|
243
|
+
result << "#{map_id}.direction_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
244
|
+
end
|
245
|
+
end #end .each
|
246
|
+
result << "#{map_id}.create_direction();"
|
247
|
+
else #default behaviour
|
248
|
+
result << "#{map_id}.#{category} = #{content[:data]};"
|
249
|
+
content[:options] ||= Array.new
|
250
|
+
content[:options].each do |option_k, option_v|
|
251
|
+
result << "#{map_id}.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
252
|
+
end
|
253
|
+
result << "#{map_id}.create_#{category}();"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
result << "#{map_id}.callback();"
|
257
|
+
|
258
|
+
if edit_map_with_id == false
|
259
|
+
result << "};\nGmaps.mapsToLoad.push('#{Gmaps4rails.js_function_name(hash)}');"
|
260
|
+
if hash[:last_map].nil? || hash[:last_map] == true
|
261
|
+
result << "window.onload = Gmaps.loadMaps;"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
result * ('
|
266
|
+
')
|
267
|
+
end
|
173
268
|
|
174
269
|
end
|
@@ -2,72 +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
|
-
|
6
|
-
|
7
|
-
#the variable 'options' must have the following structure
|
8
|
-
#{
|
9
|
-
# "map_options" => hash,
|
10
|
-
# "markers" => { "data" => json, "options" => hash },
|
11
|
-
# "polylines" => { "data" => json, "options" => hash },
|
12
|
-
# "polygons" => { "data" => json, "options" => hash },
|
13
|
-
# "circles" => { "data" => json, "options" => hash },
|
14
|
-
# "direction" => { "data" => hash, "options" => hash }
|
15
|
-
#}
|
16
|
-
# "map_options" and "direction" must be treated separately because there content is slightly different from the others:
|
17
|
-
# - "map_options" has no data
|
18
|
-
# - "direction" has a hash as a data and waypoints options must be processed properly
|
19
|
-
#
|
20
|
-
# in the following code, I loop through the elements of the hash
|
21
|
-
#
|
22
|
-
result = Array.new
|
23
|
-
|
24
|
-
#Don't display js concerning map if no need to be initialized
|
25
|
-
if init == true
|
26
|
-
#because map should be initialized first, we must extract possible map_options
|
27
|
-
unless self["map_options"].nil?
|
28
|
-
self["map_options"].each do |option_k, option_v|
|
29
|
-
if option_k == "bounds" #particular case
|
30
|
-
result << "Gmaps4Rails.map_options.#{option_k} = #{option_v};"
|
31
|
-
else
|
32
|
-
result << "Gmaps4Rails.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
result << "Gmaps4Rails.initialize();"
|
38
|
-
end #if init
|
39
|
-
each do |category, content| #loop through options hash
|
40
|
-
case category
|
41
|
-
when "map_options"
|
42
|
-
#already taken into account above => nothing to do here
|
43
|
-
when "direction"
|
44
|
-
result << "Gmaps4Rails.direction_conf.origin = '#{content["data"]["from"]}';"
|
45
|
-
result << "Gmaps4Rails.direction_conf.destination = '#{content["data"]["to"]}';"
|
46
|
-
|
47
|
-
content["options"] ||= Array.new
|
48
|
-
content["options"].each do |option_k, option_v|
|
49
|
-
if option_k == "waypoints"
|
50
|
-
waypoints = Array.new
|
51
|
-
option_v.each do |waypoint|
|
52
|
-
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
53
|
-
end
|
54
|
-
result << "Gmaps4Rails.direction_conf.waypoints = [#{waypoints * (",")}];"
|
55
|
-
else #option_k != "waypoint"
|
56
|
-
result << "Gmaps4Rails.direction_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
57
|
-
end
|
58
|
-
end #end .each
|
59
|
-
result << "Gmaps4Rails.create_direction();"
|
60
|
-
else #default behaviour in case condition
|
61
|
-
result << "Gmaps4Rails.#{category} = #{content["data"]};"
|
62
|
-
content["options"] ||= Array.new
|
63
|
-
content["options"].each do |option_k, option_v|
|
64
|
-
result << "Gmaps4Rails.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
65
|
-
end
|
66
|
-
result << "Gmaps4Rails.create_#{category}();"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
result << "Gmaps4Rails.callback();"
|
70
|
-
result * ('
|
71
|
-
')
|
5
|
+
def to_gmaps4rails(edit_map_with_id = false)
|
6
|
+
Gmaps4rails.create_js_from_hash(self.with_indifferent_access, edit_map_with_id)
|
72
7
|
end
|
8
|
+
|
73
9
|
end
|
@@ -5,7 +5,7 @@ module Gmaps4railsHelper
|
|
5
5
|
def gmaps4rails(builder, enable_css = true, enable_js = true )
|
6
6
|
options = {
|
7
7
|
"map_options" => { "auto_adjust" => true},
|
8
|
-
"markers" => { "data" => builder }
|
8
|
+
"markers" => { "data" => builder, "options" => { "do_clustering" => true} }
|
9
9
|
}
|
10
10
|
render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css, :enable_js => enable_js }
|
11
11
|
end
|
@@ -20,5 +20,16 @@ module Gmaps4railsHelper
|
|
20
20
|
return "" if libraries_array.nil?
|
21
21
|
"," + libraries_array.join(",")
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
|
+
def gmaps_map_id(options)
|
25
|
+
options[:map_options].try(:[], :id) || Gmaps4rails::DEFAULT_MAP_ID
|
26
|
+
end
|
27
|
+
|
28
|
+
def gmaps_container_id(options)
|
29
|
+
options[:map_options].try(:[], :container_id) || "map_container"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gmaps_map_class(options)
|
33
|
+
options[:map_options].try(:[], :class) || "gmaps4rails_map"
|
34
|
+
end
|
24
35
|
end
|