mirror of
https://github.com/publiclab/mapknitter.git
synced 2026-01-06 07:25:25 +01:00
Adjust TMS redirects for google cloud, new route redirect style (#1548)
* Adjust TMS redirects for google cloud, new route redirect style * Update utility_controller.rb * Apply suggestions from code review * Update _cloud_exports.html.erb * Update tms_info.html.erb * Delete utility_controller_test.rb * Update routes.rb * Update utility_controller.rb * Update app/controllers/utility_controller.rb * Update utility_controller.rb * Update .codecov.yml * Update _cloud_exports.html.erb
This commit is contained in:
@@ -8,4 +8,7 @@ comment:
|
||||
coverage:
|
||||
status:
|
||||
project: on
|
||||
patch: on
|
||||
patch:
|
||||
default:
|
||||
target: 50%
|
||||
threshold: 5%
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
class UtilityController < ApplicationController
|
||||
# translates TMS formats from one ordering to another
|
||||
def tms_alt
|
||||
# /z/x/y.png
|
||||
# /z/x/y.png
|
||||
# /z/x/(2*z-y-1).png
|
||||
y = 2**params[:z].to_i - params[:y].to_i - 1
|
||||
redirect_to("/tms/#{params[:id]}/#{params[:z]}/#{params[:x]}/#{y}.png")
|
||||
# TMS redirects now handled mostly in config/routes.rb
|
||||
|
||||
# most export TMS routes are handled in app/views/maps/_cloud_exports.html.erb, but this may catch some too
|
||||
# if no static local file exists in format /tms/:id/:z/:x/:y.png, this action handles the request
|
||||
def tms
|
||||
unless Map.find_by(slug: params[:id]) # if no map with the given slug is found, record_not_found is thrown
|
||||
redirect_to("https://mapknitter-exports-warps.storage.googleapis.com/#{params[:id]}/tms/#{params[:z]}/#{params[:x]}/#{params[:y]}.png")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<% exports.order(created_at: :desc).each_with_index do |export, i| %>
|
||||
<p class="export mapknitter-cloud-export" style="font-size:12px;">
|
||||
<b>Export <%= exports.count - i %>:</b>
|
||||
<a data-slug="<%= export.map.slug %>" href="<%= export.export_url || "/export/status/#{export.map_id}" %>">Status</a>: <span class="status-container"></span>
|
||||
<a class="slug-el" data-slug="<%= export.map.slug %>" href="<%= export.export_url || "/export/status/#{export.map_id}" %>">Status</a>: <span class="status-container"></span>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -36,6 +36,8 @@ var addExport, collectExportUrls;
|
||||
console.log(response, response.status);
|
||||
var status_el = export_el.find('.status-container');
|
||||
var slug = status_el.attr('data-slug');
|
||||
var slug_el = export_el.find('.slug-el');
|
||||
var slug = slug_el.attr('data-slug');
|
||||
status_el.html('');
|
||||
|
||||
if (response.status != "complete") status_el.append(' <i class="fa fa-spinner fa-spin"></i>');
|
||||
@@ -47,6 +49,9 @@ var addExport, collectExportUrls;
|
||||
if (response.geotiff && typeof response.geotiff === "boolean") status_el.append(' <span class="file geotiff badge badge-success"><a style="color:white;" href="/warps/' + slug + '/' + slug + '.tif">GeoTiff</span>');
|
||||
else if (response.geotiff) status_el.append(' <span class="file geotiff badge badge-success"><a style="color:white;" href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.geotiff.split('public/warps/')[1] + '">GeoTiff</span>');
|
||||
|
||||
if (response.tms && typeof response.tms === "boolean") status_el.append(' <span class="file tms badge badge-info"><a style="color:white;" href="/tms/' + slug + '/">TMS</span>');
|
||||
else if (response.zip) status_el.append(' <span class="file tms badge badge-info"><a style="color:white;" href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.tms.split('public/tms/')[1] + '/tms/">TMS</span>');
|
||||
|
||||
if (response.zip && typeof response.zip === "boolean") status_el.append(' <span class="file zip badge badge-primary"><a style="color:white;" href="/tms/' + slug + '.zip">TMS (zip)</span>');
|
||||
else if (response.zip) status_el.append(' <span class="file zip badge badge-primary"><a style="color:white;" href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.zip.split('public/tms/')[1].split('.zip')[0] + "/" + response.zip.split('public/tms/')[1] + '">TMS (zip)</span>');
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
<div class="well">
|
||||
<div class="container" style="padding:50px">
|
||||
|
||||
<p>The TMS (Tiled Map Service) URL forms the basis of a longer TMS-style URL, which is mainly useful in plugging your map into other services. To access a specific tile, you can use a URL with the format:</p>
|
||||
|
||||
<pre>https://mapknitter.org/tms/<%= params[:id] %>/:z/:x/:y.png</pre>
|
||||
<input type='text' value="https://mapknitter.org/tms/<%= params[:id] %>/:z/:x/:y.png" style="width:100%;" />
|
||||
|
||||
<p>Read more: <a href="https://en.wikipedia.org/wiki/Tile_Map_Service">https://en.wikipedia.org/wiki/Tile_Map_Service</a></p>
|
||||
<p>For the OpenStreetMap ID editor, the format would be:
|
||||
|
||||
<input type='text' value="https://mapknitter.org/tms/<%= params[:id] %>/{zoom}/{x}/{y}.png" style="width:100%;" />
|
||||
|
||||
<p>Read more about TMS: <a href="https://en.wikipedia.org/wiki/Tile_Map_Service">https://en.wikipedia.org/wiki/Tile_Map_Service</a></p>
|
||||
|
||||
<p>Read more about MapKnitter TMS: <a href="https://publiclab.org/mapknitter-cloud-exporter#TMS"></a></p>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -42,7 +42,8 @@ Mapknitter::Application.routes.draw do
|
||||
get 'images/revert', to: 'images#revert'
|
||||
get 'images/:url', to: 'images#fetch'
|
||||
|
||||
get 'tms/:id/alt/:z/:x/:y.png', to: 'utility#tms_alt'
|
||||
get 'tms/:id/alt/:z/:x/:y.png', to: redirect {|params, req| "/tms/#{params[:id]}/#{params[:z]}/#{params[:x]}/#{2**params[:z].to_i - params[:y].to_i - 1}.png"}
|
||||
get 'tms/:id/:z/:x/:y.png', to: 'utility#tms_redirect'
|
||||
get 'tms/:id/', to: 'utility#tms_info'
|
||||
get 'tms/:id/alt/', to: 'utility#tms_info'
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class UtilityControllerTest < ActionController::TestCase
|
||||
test 'should translate tms format' do
|
||||
get(:tms_alt,
|
||||
params: {
|
||||
id: 1,
|
||||
x: 10,
|
||||
y: 30,
|
||||
z: 40
|
||||
}
|
||||
)
|
||||
|
||||
y = 2**40.to_i - 30.to_i - 1
|
||||
assert_redirected_to "/tms/1/40/10/#{y}.png"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user