forked from mapbox/tilebelt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
214 lines (186 loc) · 6.34 KB
/
test.js
File metadata and controls
214 lines (186 loc) · 6.34 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
'use strict';
var test = require('tape').test,
tilebelt = require('./');
var tile1 = [5, 10, 10];
test('tile to geojson', function (t) {
var geojson = tilebelt.tileToGeoJSON(tile1);
t.ok(geojson, 'get geojson representation of tile');
t.equal(geojson.type, 'Polygon');
t.deepEqual(geojson.coordinates, [[
[-178.2421875, 84.73838712095339],
[-178.2421875, 84.7060489350415],
[-177.890625, 84.7060489350415],
[-177.890625, 84.73838712095339],
[-178.2421875, 84.73838712095339]
]], 'Coordinates');
t.end();
});
test('tile to bbox', function (t) {
var ext = tilebelt.tileToBBOX(tile1);
t.ok(ext, 'get geojson representation of tile');
t.deepEqual(ext,
[-178.2421875, 84.7060489350415, -177.890625, 84.73838712095339],
'extent');
t.end();
});
test('get parent', function (t) {
var parent = tilebelt.getParent(tile1);
t.ok(parent);
t.equal(parent.length, 3);
t.equal(parent[0], 2);
t.equal(parent[1], 5);
t.equal(parent[2], 9);
t.end();
});
test('get siblings', function (t) {
var siblings = tilebelt.getSiblings(t);
t.ok(siblings);
t.equal(siblings.length, 4);
t.equal(siblings[0].length, 3);
t.end();
});
test('has siblings', function (t) {
var tiles1 = [
[0, 0, 5],
[0, 1, 5],
[1, 1, 5],
[1, 0, 5]
];
var tiles2 = [
[0, 0, 5],
[0, 1, 5],
[1, 1, 5]
];
t.equals(tilebelt.hasSiblings([0, 0, 5], tiles1), true);
t.equals(tilebelt.hasSiblings([0, 1, 5], tiles1), true);
t.equals(tilebelt.hasSiblings([0, 0, 5], tiles2), false);
t.equals(tilebelt.hasSiblings([0, 0, 5], tiles2), false);
t.end();
});
test('has tile', function (t) {
var tiles1 = [
[0, 0, 5],
[0, 1, 5],
[1, 1, 5],
[1, 0, 5]
];
t.equals(tilebelt.hasSiblings([2, 0, 5], tiles1), false);
t.equals(tilebelt.hasSiblings([0, 1, 5], tiles1), true);
t.end();
});
test('get quadkey', function (t) {
var key = tilebelt.tileToQuadkey([11, 3, 8]);
t.equal(key, '00001033');
t.end();
});
test('quadkey to tile', function (t) {
var quadkey = '00001033';
var tile = tilebelt.quadkeyToTile(quadkey);
t.equal(tile.length, 3);
t.end();
});
test('point to tile', function (t) {
var tile = tilebelt.pointToTile(0, 0, 10);
t.equal(tile.length, 3);
t.equal(tile[2], 10);
t.end();
});
test('point to tile verified', function (t) {
var tile = tilebelt.pointToTile(-77.03239381313323, 38.91326516559442, 10);
t.equal(tile.length, 3);
t.equal(tile[0], 292);
t.equal(tile[1], 391);
t.equal(tile[2], 10);
t.equal(tilebelt.tileToQuadkey(tile), '0320100322');
t.end();
});
test('point and tile back and forth', function (t) {
var tile = tilebelt.pointToTile(10, 10, 10);
t.equal(tile.toString(), tilebelt.quadkeyToTile(tilebelt.tileToQuadkey(tile)).toString());
t.end();
});
test('check key 03', function (t) {
var quadkey = '03';
t.equal(tilebelt.quadkeyToTile(quadkey).toString(), [1, 1, 2].toString());
t.end();
});
test('bbox to tile -- big', function (t) {
var bbox = [-84.72656249999999, 11.178401873711785, -5.625, 61.60639637138628];
var tile = tilebelt.bboxToTile(bbox);
t.ok(tile, 'convert bbox to tile');
t.equal(tile[0], 1);
t.equal(tile[1], 1);
t.equal(tile[2], 2);
t.end();
});
test('bbox to tile -- no area', function (t) {
var bbox = [-84, 11, -84, 11];
var tile = tilebelt.bboxToTile(bbox);
t.ok(tile, 'convert bbox to tile');
t.deepEqual(tile, [71582788, 125964677, 28]);
t.end();
});
test('bbox to tile -- dc', function (t) {
var bbox = [-77.04615354537964, 38.899967510782346, -77.03664779663086, 38.90728142481329];
var tile = tilebelt.bboxToTile(bbox);
t.ok(tile, 'convert bbox to tile');
t.equal(tile[0], 9371);
t.equal(tile[1], 12534);
t.equal(tile[2], 15);
t.end();
});
test('bbox to tile -- crossing 0 lat/lng', function (t) {
var bbox = [-10, -10, 10, 10];
var tile = tilebelt.bboxToTile(bbox);
t.ok(tile, 'convert bbox to tile');
t.equal(tile[0], 0);
t.equal(tile[1], 0);
t.equal(tile[2], 0);
t.end();
});
test('tile to bbox -- verify bbox order', function (t) {
var tile = [13, 11, 5];
var bbox = tilebelt.tileToBBOX(tile);
t.equal(bbox[0] < bbox[2], true, 'east is less than west');
t.equal(bbox[1] < bbox[3], true, 'south is less than north');
tile = [20, 11, 5];
bbox = tilebelt.tileToBBOX(tile);
t.equal(bbox[0] < bbox[2], true, 'east is less than west');
t.equal(bbox[1] < bbox[3], true, 'south is less than north');
tile = [143, 121, 8];
bbox = tilebelt.tileToBBOX(tile);
t.equal(bbox[0] < bbox[2], true, 'east is less than west');
t.equal(bbox[1] < bbox[3], true, 'south is less than north');
tile = [999, 1000, 17];
bbox = tilebelt.tileToBBOX(tile);
t.equal(bbox[0] < bbox[2], true, 'east is less than west');
t.equal(bbox[1] < bbox[3], true, 'south is less than north');
t.end();
});
test('pointToTileFraction', function (t) {
var tile = tilebelt.pointToTileFraction(-95.93965530395508, 41.26000108568697, 9);
t.ok(tile, 'convert point to tile fraction');
t.equal(tile[0], 119.552490234375);
t.equal(tile[1], 191.47119140625);
t.equal(tile[2], 9);
t.end();
});
test('pointToTile -- cross meridian', function (t) {
// X axis
// https://github.com/mapbox/tile-cover/issues/75
// https://github.com/mapbox/tilebelt/pull/32
t.deepEqual(tilebelt.pointToTile(-180, 0, 0), [0, 0, 0], '[-180, 0] zoom 0');
t.deepEqual(tilebelt.pointToTile(-180, 85, 2), [0, 0, 2], '[-180, 85] zoom 2');
t.deepEqual(tilebelt.pointToTile(180, 85, 2), [0, 0, 2], '[+180, 85] zoom 2');
t.deepEqual(tilebelt.pointToTile(-185, 85, 2), [3, 0, 2], '[-185, 85] zoom 2');
t.deepEqual(tilebelt.pointToTile(185, 85, 2), [0, 0, 2], '[+185, 85] zoom 2');
// Y axis
// Does not wrap Tile Y
t.deepEqual(tilebelt.pointToTile(-175, -95, 2), [0, 3, 2], '[-175, -95] zoom 2');
t.deepEqual(tilebelt.pointToTile(-175, 95, 2), [0, 0, 2], '[-175, +95] zoom 2');
t.deepEqual(tilebelt.pointToTile(-175, 95, 2), [0, 0, 2], '[-175, +95] zoom 2');
// BBox
// https://github.com/mapbox/tilebelt/issues/12
t.deepEqual(tilebelt.bboxToTile([-0.000001, -85, 1000000, 85]), [0, 0, 0]);
t.end();
});