gmaps4rails 1.4.2 → 1.4.3

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.
@@ -6,55 +6,14 @@ if enable_css == true && options[:scripts].nil? %>
6
6
  <% end %>
7
7
  <% end %>
8
8
  <% end %>
9
+
9
10
  <% content_for :scripts do %>
10
- <% if enable_js == true && options[:scripts].try(:to_sym) != :none %>
11
- <% case options[:map_options].try(:[], :provider) %>
12
- <% when "openlayers" %>
13
- <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
14
- <% when "mapquest" %>
15
- <script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key=<%= options[:map_options].try(:[], :provider_key) %>"></script>
16
- <% when "bing" %>
17
- <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
18
- <% else %>
19
- <script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.5&sensor=false&amp;libraries=geometry<%= g_libraries(options[:map_options].try(:[], :libraries)) %>"></script>
20
- <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
21
- <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script>
22
- <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
23
- <% end %>
24
-
25
- <% if Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR < 1 %>
26
- <% unless options[:scripts].try(:to_sym) == :api %>
27
- <%= javascript_include_tag 'gmaps4rails/gmaps4rails.base.js' %>
28
- <% end %>
29
- <% case options[:map_options].try(:[], :provider) %>
30
- <% when "openlayers" %>
31
- <%= javascript_include_tag 'gmaps4rails/gmaps4rails.openlayers.js' %>
32
- <% when "mapquest" %>
33
- <%= javascript_include_tag 'gmaps4rails/gmaps4rails.mapquest.js' %>
34
- <% when "bing" %>
35
- <%= javascript_include_tag 'gmaps4rails/gmaps4rails.bing.js' %>
36
- <% else %>
37
- <%= javascript_include_tag 'gmaps4rails/gmaps4rails.googlemaps.js' %>
38
- <% end %>
39
- <% end %>
40
- <% end %>
41
- <script type="text/javascript" charset="utf-8">
42
11
 
12
+ <%= gmaps4rails_js_files(options[:map_options], options[:scripts], enable_js) %>
13
+ <script type="text/javascript" charset="utf-8">
43
14
  <%=raw options.to_gmaps4rails %>
44
-
45
15
  </script>
46
- <% end %>
47
16
 
17
+ <% end %>
48
18
 
49
- <% case options[:map_options].try(:[], :provider) %>
50
- <% when "mapquest" %>
51
- <div id="<%= gmaps_map_id(options) %>" style="width:750px; height:475px;">
52
- <!-- TODO: change this style dynamically -->
53
- </div>
54
- <% when "bing" %>
55
- <div id="<%= gmaps_map_id(options) %>" class="<%= gmaps_map_class(options) %>"></div>
56
- <% else %>
57
- <div class="<%= gmaps_container_class(options) %>">
58
- <div id="<%= gmaps_map_id(options) %>" class="<%= gmaps_map_class(options) %>"></div>
59
- </div>
60
- <% end %>
19
+ <%= gmaps4rails_html(options[:map_options]) %>
@@ -0,0 +1,12 @@
1
+ <% case map_options.try(:[], :provider) %>
2
+ <% when "mapquest" %>
3
+ <div id="<%= gmaps4rails_map_id(map_options) %>" style="width:750px; height:475px;">
4
+ <!-- TODO: change this style dynamically -->
5
+ </div>
6
+ <% when "bing" %>
7
+ <div id="<%= gmaps4rails_map_id(map_options) %>" class="<%= gmaps4rails_map_class(map_options) %>"></div>
8
+ <% else %>
9
+ <div class="<%= gmaps4rails_container_class(map_options) %>">
10
+ <div id="<%= gmaps4rails_map_id(map_options) %>" class="<%= gmaps4rails_map_class(map_options) %>"></div>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <% if enable_js == true && scripts.try(:to_sym) != :none %>
2
+ <% case map_options.try(:[], :provider) %>
3
+ <% when "openlayers" %>
4
+ <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
5
+ <% when "mapquest" %>
6
+ <script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key=<%= map_options.try(:[], :provider_key) %>"></script>
7
+ <% when "bing" %>
8
+ <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
9
+ <% else %>
10
+ <script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.5&sensor=false&amp;libraries=geometry<%= gmaps4rails_js_libraries(map_options.try(:[], :libraries)) %>"></script>
11
+ <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
12
+ <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script>
13
+ <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
14
+ <% end %>
15
+
16
+ <% if Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR < 1 %>
17
+ <% unless scripts.try(:to_sym) == :api %>
18
+ <%= javascript_include_tag 'gmaps4rails/gmaps4rails.base.js' %>
19
+ <% end %>
20
+ <% case map_options.try(:[], :provider) %>
21
+ <% when "openlayers" %>
22
+ <%= javascript_include_tag 'gmaps4rails/gmaps4rails.openlayers.js' %>
23
+ <% when "mapquest" %>
24
+ <%= javascript_include_tag 'gmaps4rails/gmaps4rails.mapquest.js' %>
25
+ <% when "bing" %>
26
+ <%= javascript_include_tag 'gmaps4rails/gmaps4rails.bing.js' %>
27
+ <% else %>
28
+ <%= javascript_include_tag 'gmaps4rails/gmaps4rails.googlemaps.js' %>
29
+ <% end %>
30
+ <% end %>
31
+ <% end %>
@@ -17,6 +17,10 @@ if defined?(Rails) && Rails::VERSION::MAJOR == 3
17
17
  end
18
18
  end
19
19
 
20
+ end
21
+
22
+ class Railtie < Rails::Railtie
23
+
20
24
  initializer "include acts_as_gmappable within ORM" do
21
25
  ActiveSupport.on_load(:active_record) do
22
26
  ActiveRecord::Base.send(:include, Gmaps4rails::ActsAsGmappable)
@@ -26,7 +30,7 @@ if defined?(Rails) && Rails::VERSION::MAJOR == 3
26
30
  Mongoid::Document.send(:include, Gmaps4rails::ActsAsGmappable)
27
31
  end
28
32
  end
29
-
33
+
30
34
  end
31
35
  end
32
36
  end
@@ -38,7 +38,8 @@ module Gmaps4rails
38
38
 
39
39
  def to_gmaps4rails(&block)
40
40
  json = "["
41
- json << Gmaps4rails.create_json(self, &block) #removes the extra comma
41
+ object_json = Gmaps4rails.create_json(self, &block)
42
+ json << object_json.to_s unless json.nil?
42
43
  json << "]"
43
44
  end
44
45
 
@@ -7,30 +7,38 @@ module Gmaps4railsHelper
7
7
  :map_options => { :auto_adjust => true},
8
8
  :markers => { :data => builder, :options => {:do_clustering => true} }
9
9
  }
10
- render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css, :enable_js => enable_js }
10
+ render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options.with_indifferent_access, :enable_css => enable_css, :enable_js => enable_js }
11
11
  end
12
12
 
13
13
  # complete helper to pass all variables alongside their options
14
14
 
15
15
  def gmaps(options, enable_css = true, enable_js = true )
16
- render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css, :enable_js => enable_js }
16
+ render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options.with_indifferent_access, :enable_css => enable_css, :enable_js => enable_js }
17
17
  end
18
18
 
19
- def g_libraries(libraries_array)
19
+ def gmaps4rails_js_libraries(libraries_array)
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
24
+ def gmaps4rails_map_id(map_options)
25
+ map_options.try(:[], :id) || Gmaps4rails::DEFAULT_MAP_ID
26
26
  end
27
27
 
28
- def gmaps_container_class(options)
29
- options[:map_options].try(:[], :container_class) || "map_container"
28
+ def gmaps4rails_container_class(map_options)
29
+ map_options.try(:[], :container_class) || "map_container"
30
30
  end
31
31
 
32
- def gmaps_map_class(options)
33
- default_class = options[:map_options].try(:[], :provider) == "bing" ? "bing_map" : "gmaps4rails_map"
34
- options[:map_options].try(:[], :class) || default_class
32
+ def gmaps4rails_map_class(map_options)
33
+ default_class = map_options.try(:[], :provider) == "bing" ? "bing_map" : "gmaps4rails_map"
34
+ map_options.try(:[], :class) || default_class
35
+ end
36
+
37
+ def gmaps4rails_js_files(map_options = nil, scripts = nil, enable_js = true)
38
+ render "gmaps4rails/scripts", :map_options => map_options, :scripts => scripts, :enable_js => enable_js
39
+ end
40
+
41
+ def gmaps4rails_html(map_options = nil)
42
+ render "gmaps4rails/html", :map_options => map_options
35
43
  end
36
44
  end
@@ -31,7 +31,6 @@ module Gmaps4rails
31
31
  end
32
32
 
33
33
  def Gmaps4rails.create_general_js(hash, map_id, category)
34
- hash = hash.with_indifferent_access
35
34
  output = Array.new
36
35
  output << "#{map_id}.#{category} = #{hash[:data]};"
37
36
  hash[:options] ||= Array.new
@@ -47,7 +46,6 @@ module Gmaps4rails
47
46
  end
48
47
 
49
48
  def Gmaps4rails.create_direction_js(hash, map_id)
50
- hash = hash.with_indifferent_access
51
49
  output = Array.new
52
50
  output << "#{map_id}.direction_conf.origin = '#{hash["data"]["from"]}';"
53
51
  output << "#{map_id}.direction_conf.destination = '#{hash["data"]["to"]}';"
@@ -77,6 +75,7 @@ module Gmaps4rails
77
75
  # :direction => { :data => hash, :options => hash },
78
76
  # :kml => { :data => json, :options => hash }
79
77
  #}
78
+ #should be with only symbol keys or with indifferent access
80
79
  def Gmaps4rails.create_js_from_hash(hash)
81
80
  result = Array.new
82
81
  map_id = "Gmaps." + Gmaps4rails.get_map_id(hash[:map_options])
@@ -237,10 +237,25 @@
237
237
  strokeWeight: strokeWeight,
238
238
  fillColor: fillColor,
239
239
  fillOpacity: fillOpacity,
240
- clickable: false
240
+ clickable: false,
241
+ map: this.map
241
242
  });
242
- polygon.serviceObject = new_poly;
243
- return new_poly.setMap(this.map);
243
+ return polygon.serviceObject = new_poly;
244
+ };
245
+ Gmaps4Rails.prototype.replacePolylines = function(new_polylines) {
246
+ this.destroy_polylines();
247
+ this.polylines = new_polylines;
248
+ this.create_polylines();
249
+ return this.adjustMapToBounds();
250
+ };
251
+ Gmaps4Rails.prototype.destroy_polylines = function() {
252
+ var polyline, _i, _len, _ref;
253
+ _ref = this.polylines;
254
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
255
+ polyline = _ref[_i];
256
+ polyline.serviceObject.setMap(null);
257
+ }
258
+ return this.polylines = [];
244
259
  };
245
260
  Gmaps4Rails.prototype.create_polylines = function() {
246
261
  var polyline, _i, _len, _ref, _results;
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 2
10
- version: 1.4.2
9
+ - 3
10
+ version: 1.4.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: 2012-01-05 00:00:00 Z
19
+ date: 2012-01-20 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: json
@@ -55,6 +55,8 @@ files:
55
55
  - app/assets/javascripts/gmaps4rails/mapquest.js
56
56
  - app/assets/javascripts/gmaps4rails/openlayers.js
57
57
  - app/views/gmaps4rails/_gmaps4rails.html.erb
58
+ - app/views/gmaps4rails/_html.html.erb
59
+ - app/views/gmaps4rails/_scripts.html.erb
58
60
  - lib/generators/gmaps4rails/install_generator.rb
59
61
  - lib/generators/templates/README
60
62
  - lib/gmaps4rails.rb