forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a "tile details" view accessed from the context menu
- Loading branch information
Showing
10 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
OSM.TileInfo = function(map) { | ||
var tile; | ||
|
||
function lon2x(lon, zoom) { | ||
return Math.floor((lon + 180) / 360 * Math.pow(2, zoom)); | ||
} | ||
|
||
function lat2y(lat, zoom) { | ||
return Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / | ||
Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, zoom)); | ||
} | ||
|
||
function x2lon(x, z) { | ||
return x / Math.pow(2, z) * 360 - 180; | ||
} | ||
|
||
function y2lat(y, z) { | ||
var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z); | ||
return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))); | ||
} | ||
|
||
var page = {}; | ||
|
||
page.pushstate = page.popstate = function(path) { | ||
OSM.loadSidebarContent(path, function () { | ||
page.load(path, true); | ||
}); | ||
}; | ||
|
||
page.load = function(path, noCentre) { | ||
var params = querystring.parse(path.substring(path.indexOf('?') + 1)), | ||
lat = parseFloat(params.lat), | ||
lon = parseFloat(params.lon), | ||
zoom = parseInt(params.zoom), | ||
y = lat2y(lat, zoom), | ||
x = lon2x(lon, zoom), | ||
sw = L.latLng(y2lat(y, zoom), x2lon(x, zoom)), | ||
ne = L.latLng(y2lat(y + 1, zoom), x2lon(x + 1, zoom)), | ||
bounds = L.latLngBounds(sw, ne), | ||
latlng = L.latLng(lat, lon), | ||
layer = map.getBaseLayer(), | ||
url = layer.getTileUrl({ x: x, y : y }); | ||
|
||
tile = L.rectangle(bounds, { | ||
color: "#FF6200", | ||
weight: 4, | ||
opacity: 1, | ||
interactive: false | ||
}).addTo(map); | ||
|
||
$("#tileinfo-url").attr("href", url).text(url); | ||
$("#tileinfo-z").text(zoom); | ||
$("#tileinfo-y").text(y); | ||
$("#tileinfo-x").text(x); | ||
|
||
if (layer.options.code === "M") | ||
{ | ||
$.ajax({ | ||
url: url + "/status", | ||
success: function (data) { | ||
var re = /^Tile is (.*?)\. Last rendered at (.*?)\. Last accessed at (.*?)\./, | ||
matches = data.match(re); | ||
|
||
if (matches) | ||
{ | ||
$("#tileinfo-state").text(matches[1]); | ||
$("#tileinfo-rendered").text(matches[2]); | ||
$("#tileinfo-accessed").text(matches[3]); | ||
} | ||
} | ||
}); | ||
} | ||
else | ||
{ | ||
$("#tileinfo-status").hide(); | ||
} | ||
|
||
if (!window.location.hash && !noCentre && !map.getBounds().contains(latlng)) { | ||
OSM.router.withoutMoveListener(function () { | ||
map.setView(latlng, zoom); | ||
}); | ||
} | ||
}; | ||
|
||
page.unload = function() { | ||
map.removeLayer(tile); | ||
}; | ||
|
||
return page; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% set_title(t("site.tileinfo.title")) %> | ||
|
||
<h2> | ||
<a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a> | ||
<%= t("site.tileinfo.title") %> | ||
</h2> | ||
|
||
<div class="tileinfo-section"> | ||
<h3><%= t("site.tileinfo.url") %></h3> | ||
<a href="#" id="tileinfo-url"></a> | ||
</div> | ||
|
||
<div class="tileinfo-section"> | ||
<h3><%= t("site.tileinfo.coordinates") %></h3> | ||
<table> | ||
<tr><th>Z</th><td id="tileinfo-z"></td></tr> | ||
<tr><th>X</th><td id="tileinfo-x"></td></tr> | ||
<tr><th>Y</th><td id="tileinfo-y"></td></tr> | ||
</table> | ||
</div> | ||
|
||
<div class="tileinfo-section" id="tileinfo-status"> | ||
<h3><%= t("site.tileinfo.status") %></h3> | ||
<table> | ||
<tr><th><%= t("site.tileinfo.state") %></th><td id="tileinfo-state"></td></tr> | ||
<tr><th><%= t("site.tileinfo.last_rendered") %></th><td id="tileinfo-rendered"></td></tr> | ||
<tr><th><%= t("site.tileinfo.last_accessed") %></th><td id="tileinfo-accessed"></td></tr> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters