Class: Gmaps4rails::ViewHelper
- Inherits:
-
Object
- Object
- Gmaps4rails::ViewHelper
- Defined in:
- lib/gmaps4rails/view_helper.rb
Constant Summary collapse
- OPENLAYERS =
"http://www.openlayers.org/api/OpenLayers.js"- MAPQUEST =
"http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js"- BING =
"http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"- GOOGLE =
"//maps.google.com/maps/api/js?v=3.8"- GOOGLE_EXT =
"//google-maps-utility-library-v3.googlecode.com/svn/"
Instance Method Summary collapse
-
#dom_attributes ⇒ Object
outputs an object containing the basic information to fill the map’s dom attributes.
-
#get_gem_scripts ⇒ Object
gem’s script aren’t taken into account when asset pipeline is enabled: I assume they’ll be within.
-
#get_vendor_scripts ⇒ Object
vendor_scripts are the js libraries from the map providers.
-
#initialize(options = {}) ⇒ ViewHelper
constructor
options is the hash passed to the ‘gmaps’ helper looks like: { :map_options => hash, :markers => { :data => json, :options => hash }, :polylines => { :data => json, :options => hash }, :polygons => { :data => json, :options => hash }, :circles => { :data => json, :options => hash }, :direction => { :data => hash, :options => hash }, :kml => { :data => json, :options => hash } } should be with only symbol keys or with indifferent access.
-
#js_dependencies_array ⇒ Object
outputs an array containing the path to all required js files this list is deduced from the options passed.
Constructor Details
#initialize(options = {}) ⇒ ViewHelper
options is the hash passed to the ‘gmaps’ helper looks like: {
:map_options => hash,
:markers => { :data => json, :options => hash },
:polylines => { :data => json, :options => hash },
:polygons => { :data => json, :options => hash },
:circles => { :data => json, :options => hash },
:direction => { :data => hash, :options => hash },
:kml => { :data => json, :options => hash }
} should be with only symbol keys or with indifferent access
23 24 25 26 |
# File 'lib/gmaps4rails/view_helper.rb', line 23 def initialize( = {}) @options = @js_array = Array.new end |
Instance Method Details
#dom_attributes ⇒ Object
outputs an object containing the basic information to fill the map’s dom attributes
39 40 41 42 43 44 45 46 |
# File 'lib/gmaps4rails/view_helper.rb', line 39 def dom_attributes ::OpenStruct.new({ :map_id => map_id, :map_class => map_class, :container_class => container_class, :provider => map_provider }) end |
#get_gem_scripts ⇒ Object
gem’s script aren’t taken into account when asset pipeline is enabled: I assume they’ll be within
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gmaps4rails/view_helper.rb', line 50 def get_gem_scripts unless gmaps4rails_pipeline_enabled? @js_array << '/javascripts/gmaps4rails/gmaps4rails.base.js' unless scripts == :api @js_array << case map_provider when "openlayers" then '/javascripts/gmaps4rails/gmaps4rails.openlayers.js' when "mapquest" then '/javascripts/gmaps4rails/gmaps4rails.mapquest.js' when "bing" then '/javascripts/gmaps4rails/gmaps4rails.bing.js' else '/javascripts/gmaps4rails/gmaps4rails.googlemaps.js' end end end |
#get_vendor_scripts ⇒ Object
vendor_scripts are the js libraries from the map providers
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gmaps4rails/view_helper.rb', line 63 def get_vendor_scripts case map_provider when "openlayers" then @js_array << OPENLAYERS when "mapquest" then @js_array << "#{MAPQUEST}?key=#{provider_key}" when "bing" then @js_array << BING else #case googlemaps which is the default @js_array << "#{GOOGLE}&sensor=false&client=#{client}&key=#{provider_key}&libraries=geometry#{google_libraries}&#{google_map_i18n}" @js_array << "#{GOOGLE_EXT}tags/infobox/1.1.9/src/infobox_packed.js" if custom_infowindow_class @js_array << "#{GOOGLE_EXT}tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js" if do_clustering @js_array << "#{GOOGLE_EXT}trunk/richmarker/src/richmarker-compiled.js" if rich_marker end end |
#js_dependencies_array ⇒ Object
outputs an array containing the path to all required js files this list is deduced from the options passed
30 31 32 33 34 35 36 |
# File 'lib/gmaps4rails/view_helper.rb', line 30 def js_dependencies_array if scripts != :none get_vendor_scripts get_gem_scripts end @js_array end |