From: Tom Hughes Date: Fri, 23 Nov 2012 09:04:38 +0000 (+0000) Subject: Serve embedded maps through the assets pipeline X-Git-Tag: live~5786^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c0b47c0c2a3c31b42ef946aa6e07b85305091a0c?ds=sidebyside Serve embedded maps through the assets pipeline --- diff --git a/app/assets/javascripts/embed.js b/app/assets/javascripts/embed.js new file mode 100644 index 000000000..914eabb5b --- /dev/null +++ b/app/assets/javascripts/embed.js @@ -0,0 +1,38 @@ +//= require leaflet +//= require leaflet.osm + +window.onload = function () { + var query = (window.location.search || '?').substr(1), + args = {}; + + query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, function(match, key, value) { + value = value.split(","); + if (value.length == 1) + value = value[0]; + args[key] = value; + }); + + var map = L.map("map"); + map.attributionControl.setPrefix(''); + + if (!args.layer || args.layer == "mapnik" || args.layer == "osmarender") { + new L.OSM.Mapnik().addTo(map); + } else if (args.layer == "cyclemap" || args.layer == "cycle map") { + new L.OSM.CycleMap().addTo(map); + } else if (args.layer == "transportmap") { + new L.OSM.TransportMap().addTo(map); + } else if (args.layer == "mapquest") { + new L.OSM.MapQuestOpen().addTo(map); + } + + if (args.marker) { + L.marker(args.marker).addTo(map); + } + + if (args.bbox) { + map.fitBounds([L.latLng(args.bbox[1], args.bbox[0]), + L.latLng(args.bbox[3], args.bbox[2])]) + } else { + map.fitWorld(); + } +}; diff --git a/app/assets/stylesheets/embed.css.scss b/app/assets/stylesheets/embed.css.scss new file mode 100644 index 000000000..024f73d36 --- /dev/null +++ b/app/assets/stylesheets/embed.css.scss @@ -0,0 +1,27 @@ +/* + *= require leaflet + */ + +html { + width: 100%; + height: 100%; +} + +body { + width: 100%; + height: 100%; + margin: 0px; +} + +#map { + width: 100%; + height: 100%; +} + +.leaflet-control-zoom-in { + background-image: image-url("images/zoom-in.png"); +} + +.leaflet-control-zoom-out { + background-image: image-url("images/zoom-out.png"); +} diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 2102a5704..074a92ce8 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -3,6 +3,8 @@ class ExportController < ApplicationController before_filter :authorize_web before_filter :set_locale + caches_page :embed + def start end @@ -23,4 +25,7 @@ class ExportController < ApplicationController redirect_to "http://parent.tile.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}" end end + + def embed + end end diff --git a/app/views/export/embed.html.erb b/app/views/export/embed.html.erb new file mode 100644 index 000000000..b683c2665 --- /dev/null +++ b/app/views/export/embed.html.erb @@ -0,0 +1,15 @@ + + + + + OpenStreetMap Embedded + <%= stylesheet_link_tag "embed", :media=> "screen" %> + + <%= javascript_include_tag "embed" %> + + +
+ + diff --git a/config/environments/production.rb b/config/environments/production.rb index 937f1771a..c0854d3a4 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -62,6 +62,7 @@ OpenStreetMap::Application.configure do config.assets.precompile += %w( large-rtl.css small-rtl.css print-rtl.css ) config.assets.precompile += %w( browse.css theme/openstreetmap/style.css ) config.assets.precompile += %w( leaflet-all.css leaflet.ie.css ) + config.assets.precompile += %w( embed.js embed.css ) # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false diff --git a/config/routes.rb b/config/routes.rb index 9725c0d12..1cdaaea40 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -203,6 +203,7 @@ OpenStreetMap::Application.routes.draw do # export match '/export/start' => 'export#start', :via => :get match '/export/finish' => 'export#finish', :via => :post + match '/export/embed' => 'export#embed', :via => :get # messages match '/user/:display_name/inbox' => 'message#inbox', :via => :get, :as => "inbox" diff --git a/public/export/embed.html b/public/export/embed.html deleted file mode 100644 index 3559f8f35..000000000 --- a/public/export/embed.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - - OpenStreetMap Embedded - - - - - - - - -
- - - diff --git a/test/functional/export_controller_test.rb b/test/functional/export_controller_test.rb index af9d28183..61a307643 100644 --- a/test/functional/export_controller_test.rb +++ b/test/functional/export_controller_test.rb @@ -13,6 +13,10 @@ class ExportControllerTest < ActionController::TestCase { :path => "/export/finish", :method => :post }, { :controller => "export", :action => "finish" } ) + assert_routing( + { :path => "/export/embed", :method => :get }, + { :controller => "export", :action => "embed" } + ) end def test_start