-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
119 lines (104 loc) · 4.32 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @preserve TileServer.com Maps API: National Library of Scotland
* -----------------------------------------------------
* This file is providing access to the tileset of the National Library of Scotland.
* Public functions:
*
* - NLSTileUrlOS(x,y,z) - Tiles for Ordnance Survey map from 1920-1947
*
* The function returns URL for a tile image at the x,y,z position in the Spherical Mercator.
* Without parameters it returns Bing SDK compantible for accessing the tiles.
*
* Please always get the tile url via this JavaScript API!
* Direct access to the tile location is not recommended.
* The server address will change as we update the dataset.
*
* Copyright (C) 2010 - Klokan Technologies GmbH
* http://www.klokantech.com/
*/
// Global variable with the tileserver
var tileserver = "";
// var tileserver_default = "uk.tileserver.com/_os1/r0/";
var tileserver_default = "nls.tileserver.com/nls/";
var _gaq = _gaq || [];
var protocol = ('https:' == document.location.protocol ? 'https://' : 'http://');
// THE PUBLIC FUNCTIONS:
// =====================
/* Tiles for Ordnance Survey map from 1920-1947
*
* with x, y, z parameters it returns an URL for particular tile
* with bounds paramter it returns expected results for OpenLayers
* with tile, zoom parameters it behaves like Google getTileUrl function
* without parameter it gives you the "Bing SDK" compatible universal string to access the tiles
*
* The function returns tiles from the tileserver_default, and after the dynamic test is finished from the fastest tileserver available
*/
function NLSTileUrlOS(x, y, z) {
// the "MAXZOOM" constant
if (x == "MAXZOOM")
return 14;
// without given "x" we are returning Bing SDK string
if (x == undefined) {
return protocol+"t%2." + tileserver_default + '%4.jpg';
// if (tileserver == "") return "http://t%2."+tileserver_default+"%4.jpg";
// else return "http://t%2."+tileserver+'%4.jpg';
}
// with "${x}" we return OpenLayers Array - this will mostly return only the tileserver_default location
if (x == "${x}") {
var urls = new Array();
if (tileserver == "")
for (no = 0; no < 5; no++)
urls.push(protocol+"t" + no + "." + tileserver_default + z + '/' + x + '/' + y + '.jpg');
else
for (no = 0; no < 5; no++)
urls.push(protocol+"t" + no + "." + tileserver + z + '/' + x + '/' + y + '.jpg');
return urls;
}
// behave like OpenLayers .getURL(bounds):
if (x['left'] != undefined) {
var bounds = x;
var res = this['map']['getResolution']();
x = Math.round((bounds['left'] - this['maxExtent']['left']) / (res * this['tileSize']['w']));
y = Math.round((this['maxExtent']['top'] - bounds['top']) / (res * this['tileSize']['h']));
z = this['map']['getZoom']();
}
// behave like Google .getTileUrl(tile, zoom):
if (x['x'] != undefined && Number(y) != NaN && z == undefined) {
z = y;
y = x['y'];
x = x['x'];
}
// HACK - ALWAYS USE THE NEW CDN ADDRESS
var no = (x + y) % 4;
return protocol+"nls-" + no + ".tileserver.com/nls/" + z + '/' + x + '/' + y + '.jpg';
// with numbers let's return directly the url to the tile on the server
var no = (x + y) % 5;
if (tileserver == "")
return protocol+"t" + no + "." + tileserver_default + z + '/' + x + '/' + y + '.jpg';
else
return protocol+"t" + no + "." + tileserver + z + '/' + x + '/' + y + '.jpg';
}
/* CHOOSE A TILESERVER ON THE CLIENT SIDE
* ======================================
* NOT IMPLEMENTED IN THIS VERSION OF API
*/
// STATISTICS - TRACKING VISITORS WITH GOOGLE ANALYTICS ASYNC
// TODO: record the tile server location as well
_gaq.push(['_setAccount', 'UA-8073932-5']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);
if (window.location.href.search("nls.tileserver.com") != -1)
_gaq.push(['_setVar', (window != window.top ? "iframe" : "nls.tileserver.com")]);
else
_gaq.push(['_setVar', 'api']);
_gaq.push(['_setCustomVar', 1, 'tileserver', tileserver, 2]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();