Module: MapLayers::ViewHelpers
- Defined in:
- lib/map_layers/view_helpers.rb
Overview
Provides methods to generate HTML tags and JavaScript code
Instance Method Summary collapse
-
#map_layers_includes(options = {}) ⇒ Object
Insert javascript include tags.
Instance Method Details
#map_layers_includes(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/map_layers/view_helpers.rb', line 11 def map_layers_includes( = {}) .assert_valid_keys(:google, :multimap, :openstreetmap, :virtualearth, :yahoo, :proxy,:img_path) html = '' if .has_key?(:google) html << "<script type=\"text/javascript\" src=\"http://maps.google.com/maps?file=api&v=2&key=#{[:google]}\"></script>" end if .has_key?(:multimap) html << "<script type=\"text/javascript\" src=\"http://clients.multimap.com/API/maps/1.1/#{[:multimap]}\"></script>" end if .has_key?(:virtualearth) html << "<script type=\"text/javascript\" src=\"http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js\"></script>" end if .has_key?(:yahoo) html << "<script type=\"text/javascript\" src=\"http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=#{[:yahoo]}\"></script>" end img_path = '/images/OpenLayers/' if .has_key?(:img_path) img_path = [:img_path] end if defined?( RAILS_ROOT) rails_env = RAILS_ENV rails_root = RAILS_ROOT rails_relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] else rails_env = Rails.env rails_root = Rails.root rails_relative_url_root = controller.config.relative_url_root end if rails_env == "development" && File.exist?(File.join( rails_root, 'public/javascripts/lib/OpenLayers.js')) html << '<script src="/javascripts/lib/Firebug/firebug.js"></script>' html << '<script src="/javascripts/lib/OpenLayers.js"></script>' else html << javascript_include_tag('OpenLayers') end html << stylesheet_link_tag("map") img_path=(Pathname(rails_relative_url_root||"") +img_path).cleanpath.to_s html << javascript_tag("OpenLayers.ImgPath='"+ img_path + "/';") proxy = .has_key?(:proxy) ? [:proxy] : controller.controller_name html << javascript_tag("OpenLayers.ProxyHost='/#{proxy}/proxy?url=';") html end |