mapcachetools 1.0.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +95 -19
- package/bin/mapcache_download.js +325 -0
- package/package.json +41 -13
- package/REALKEY.txt +0 -1
- package/images/Screenshot from 2022-09-03 02-19-12.png +0 -0
- package/mapcache_download.js +0 -379
- package/site/css/leaflet.css +0 -640
- package/site/css/styles.css +0 -8
- package/site/index.html +0 -43
- package/site/js/jquery/jquery-3.4.1.min.js +0 -2
- package/site/js/jquery/jquery-ui.min.css +0 -7
- package/site/js/jquery/jquery-ui.min.js +0 -13
- package/site/js/leaflet-src.esm.js +0 -13986
- package/site/js/leaflet-src.esm.js.map +0 -1
- package/site/js/leaflet-src.js +0 -14080
- package/site/js/leaflet-src.js.map +0 -1
- package/site/js/leaflet.js +0 -5
- package/site/js/leaflet.js.map +0 -1
- package/site/js/leaflet.rotatedMarker.js +0 -57
package/mapcache_download.js
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
Download images sequentially
|
|
6
|
-
*/
|
|
7
|
-
"use strict";
|
|
8
|
-
const v_pjson = require("./package.json");
|
|
9
|
-
const c_args = require("./helpers/hlp_args.js");
|
|
10
|
-
const c_colors = require("./helpers/js_colors.js").Colors;
|
|
11
|
-
|
|
12
|
-
const fs = require("fs");
|
|
13
|
-
const axios = require("axios");
|
|
14
|
-
|
|
15
|
-
const EARTH_RADIUS = 6378137;
|
|
16
|
-
const MAX_LATITUDE = 85.0511287798;
|
|
17
|
-
const R_MINOR = 6356752.314245179;
|
|
18
|
-
const TOKEN = "GET YOUR TOKEN";
|
|
19
|
-
var map_provider = 0;
|
|
20
|
-
var myArgs = c_args.getArgs();
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* @namespace Projection
|
|
24
|
-
* @projection L.Projection.SphericalMercator
|
|
25
|
-
*
|
|
26
|
-
* Spherical Mercator projection — the most common projection for online maps,
|
|
27
|
-
* used by almost all free and commercial tile providers. Assumes that Earth is
|
|
28
|
-
* a sphere. Used by the `EPSG:3857` CRS.
|
|
29
|
-
*/
|
|
30
|
-
function project(lat, lng) {
|
|
31
|
-
var d = Math.PI / 180,
|
|
32
|
-
max = MAX_LATITUDE,
|
|
33
|
-
lat = Math.max(Math.min(max, lat), -max),
|
|
34
|
-
sin = Math.sin(lat * d);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
x: EARTH_RADIUS * lng * d,
|
|
38
|
-
y: (EARTH_RADIUS * Math.log((1 + sin) / (1 - sin))) / 2,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function unproject(point) {
|
|
43
|
-
var d = 180 / Math.PI;
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
lat: (2 * Math.atan(Math.exp(point.y / EARTH_RADIUS)) - Math.PI / 2) * d,
|
|
47
|
-
lng: (point.x * d) / EARTH_RADIUS,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function zoomScale(zoom) {
|
|
52
|
-
return 256 * Math.pow(2, zoom);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function transform(point, scale) {
|
|
56
|
-
scale = scale || 1;
|
|
57
|
-
point.x = scale * (2.495320233665337e-8 * point.x + 0.5);
|
|
58
|
-
point.y = scale * (-2.495320233665337e-8 * point.y + 0.5);
|
|
59
|
-
return point;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function fn_convertFromLngLatToPoints(lat1, lng1, lat2, lng2, zoom) {
|
|
63
|
-
// order location
|
|
64
|
-
if (lng1 > lng2) {
|
|
65
|
-
var t = lng2;
|
|
66
|
-
lng2 = lng1;
|
|
67
|
-
lng1 = t;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (lat1 > lat2) {
|
|
71
|
-
var t = lat2;
|
|
72
|
-
lat2 = lat1;
|
|
73
|
-
lat1 = t;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// convert to points
|
|
77
|
-
var point1 = project(lat1, lng1);
|
|
78
|
-
var point2 = project(lat2, lng2);
|
|
79
|
-
|
|
80
|
-
var scaledZoom = zoomScale(zoom);
|
|
81
|
-
point1 = transform(point1, scaledZoom);
|
|
82
|
-
point2 = transform(point2, scaledZoom);
|
|
83
|
-
|
|
84
|
-
// convert to integer
|
|
85
|
-
point1.x = Math.floor(point1.x / 256);
|
|
86
|
-
point1.y = Math.floor(point1.y / 256);
|
|
87
|
-
point2.x = Math.floor(point2.x / 256);
|
|
88
|
-
point2.y = Math.floor(point2.y / 256);
|
|
89
|
-
|
|
90
|
-
// sort
|
|
91
|
-
if (point1.y > point2.y) {
|
|
92
|
-
var t = point2.y;
|
|
93
|
-
point2.y = point1.y;
|
|
94
|
-
point1.y = t;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
var point = [];
|
|
98
|
-
|
|
99
|
-
point.push(point1);
|
|
100
|
-
point.push(point2);
|
|
101
|
-
|
|
102
|
-
return point;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/* ============================================================
|
|
106
|
-
Function: Download Image
|
|
107
|
-
============================================================ */
|
|
108
|
-
|
|
109
|
-
const download_image = (url, image_path) =>
|
|
110
|
-
axios({
|
|
111
|
-
url,
|
|
112
|
-
responseType: "stream",
|
|
113
|
-
}).then(
|
|
114
|
-
(response) =>
|
|
115
|
-
new Promise((resolve, reject) => {
|
|
116
|
-
response.data
|
|
117
|
-
.pipe(fs.createWriteStream(image_path))
|
|
118
|
-
.on("finish", () => resolve())
|
|
119
|
-
.on("error", (e) => reject(e));
|
|
120
|
-
})
|
|
121
|
-
).catch((error) => {
|
|
122
|
-
console.log(error.message);
|
|
123
|
-
});;
|
|
124
|
-
|
|
125
|
-
function fn_download_images(point1, point2, zoom) {
|
|
126
|
-
(async () => {
|
|
127
|
-
var url, filename;
|
|
128
|
-
var totalImages =
|
|
129
|
-
(1 + (point2.x + 1) - point1.x) * (1 + (point2.y + 1) - point1.y);
|
|
130
|
-
var START_FROM = 0;
|
|
131
|
-
|
|
132
|
-
for (var j, c = 0, i = point1.x; i <= point2.x + 1; ++i)
|
|
133
|
-
for (j = point1.y; j <= point2.y + 1; ++j, ++c) {
|
|
134
|
-
if (c >= START_FROM) {
|
|
135
|
-
/*
|
|
136
|
-
You can edit URL here to download from any provider.
|
|
137
|
-
*/
|
|
138
|
-
if (map_provider==1)
|
|
139
|
-
{
|
|
140
|
-
// MAPBOX API
|
|
141
|
-
url =
|
|
142
|
-
"https://api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/" +
|
|
143
|
-
zoom +
|
|
144
|
-
"/" +
|
|
145
|
-
i +
|
|
146
|
-
"/" +
|
|
147
|
-
j +
|
|
148
|
-
"?access_token=" +
|
|
149
|
-
TOKEN;
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
{
|
|
153
|
-
// Open Street Map
|
|
154
|
-
// URL https://tile.openstreetmap.org/{z}/{x}/{y}.png
|
|
155
|
-
url =
|
|
156
|
-
"https://tile.openstreetmap.org/" +
|
|
157
|
-
zoom +
|
|
158
|
-
"/" +
|
|
159
|
-
i +
|
|
160
|
-
"/" +
|
|
161
|
-
j +
|
|
162
|
-
".png";
|
|
163
|
-
}
|
|
164
|
-
filename = folder + "/" + i + "_" + j + "_" + zoom + ".jpeg";
|
|
165
|
-
if (!fs.existsSync(filename)) {
|
|
166
|
-
await download_image(url, filename);
|
|
167
|
-
}
|
|
168
|
-
else
|
|
169
|
-
{
|
|
170
|
-
console.log ("image no. " + c + " already exists.");
|
|
171
|
-
}
|
|
172
|
-
console.log(c + " of " + totalImages + ":" + url);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
})();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function fn_handle_arguments() {
|
|
179
|
-
myArgs = c_args.getArgs();
|
|
180
|
-
var error = false;
|
|
181
|
-
if (
|
|
182
|
-
myArgs.hasOwnProperty("version") === true ||
|
|
183
|
-
myArgs.hasOwnProperty("v") === true
|
|
184
|
-
) {
|
|
185
|
-
console.log(
|
|
186
|
-
c_colors.BSuccess +
|
|
187
|
-
"MAP Cache version" +
|
|
188
|
-
c_colors.FgYellow +
|
|
189
|
-
JSON.stringify(v_pjson.version) +
|
|
190
|
-
c_colors.Reset
|
|
191
|
-
);
|
|
192
|
-
console.log(
|
|
193
|
-
c_colors.BSuccess +
|
|
194
|
-
"--lat1" +
|
|
195
|
-
c_colors.FgWhite +
|
|
196
|
-
" for Start latitude. " +
|
|
197
|
-
c_colors.FgYellow +
|
|
198
|
-
" Example --lat1=-54.652332555" +
|
|
199
|
-
c_colors.Reset
|
|
200
|
-
);
|
|
201
|
-
console.log(
|
|
202
|
-
c_colors.BSuccess +
|
|
203
|
-
"--lng1" +
|
|
204
|
-
c_colors.FgWhite +
|
|
205
|
-
" for start longitude. " +
|
|
206
|
-
c_colors.FgYellow +
|
|
207
|
-
" Example --lng1=-54.652332555" +
|
|
208
|
-
c_colors.Reset
|
|
209
|
-
);
|
|
210
|
-
console.log(
|
|
211
|
-
c_colors.BSuccess +
|
|
212
|
-
"--lat2" +
|
|
213
|
-
c_colors.FgWhite +
|
|
214
|
-
" for end latitude. " +
|
|
215
|
-
c_colors.FgYellow +
|
|
216
|
-
" Example --lat2=-54.652332555" +
|
|
217
|
-
c_colors.Reset
|
|
218
|
-
);
|
|
219
|
-
console.log(
|
|
220
|
-
c_colors.BSuccess +
|
|
221
|
-
"--lng2" +
|
|
222
|
-
c_colors.FgWhite +
|
|
223
|
-
" for end longitude. " +
|
|
224
|
-
c_colors.FgYellow +
|
|
225
|
-
" Example --lng2=-54.652332555" +
|
|
226
|
-
c_colors.Reset
|
|
227
|
-
);
|
|
228
|
-
console.log(
|
|
229
|
-
c_colors.BSuccess +
|
|
230
|
-
"--zout" +
|
|
231
|
-
c_colors.FgWhite +
|
|
232
|
-
" for maximum zoom in. You need to check provider normally up to 20" +
|
|
233
|
-
c_colors.FgYellow +
|
|
234
|
-
" Example --zout=2 " +
|
|
235
|
-
c_colors.Reset
|
|
236
|
-
);
|
|
237
|
-
console.log(
|
|
238
|
-
c_colors.BSuccess +
|
|
239
|
-
"--zin" +
|
|
240
|
-
c_colors.FgWhite +
|
|
241
|
-
" for maximum zoom out. can be as low as 0. " +
|
|
242
|
-
c_colors.FgYellow +
|
|
243
|
-
" Example --zin=10 " +
|
|
244
|
-
c_colors.Reset
|
|
245
|
-
);
|
|
246
|
-
console.log(
|
|
247
|
-
c_colors.BSuccess +
|
|
248
|
-
"--folder" +
|
|
249
|
-
c_colors.FgWhite +
|
|
250
|
-
" folder to store images in. " +
|
|
251
|
-
c_colors.FgYellow +
|
|
252
|
-
" Example --folder=./out " +
|
|
253
|
-
c_colors.Reset
|
|
254
|
-
);
|
|
255
|
-
console.log(
|
|
256
|
-
c_colors.BSuccess +
|
|
257
|
-
"--provider" +
|
|
258
|
-
c_colors.FgWhite +
|
|
259
|
-
" if equal to 1 then use https://api.mapbox.com else use tile.openstreetmap.org. " +
|
|
260
|
-
c_colors.FgYellow +
|
|
261
|
-
" Example --folder=./out " +
|
|
262
|
-
c_colors.Reset
|
|
263
|
-
);
|
|
264
|
-
console.log(
|
|
265
|
-
c_colors.BSuccess +
|
|
266
|
-
"--token" +
|
|
267
|
-
c_colors.FgWhite +
|
|
268
|
-
" Required only with https://api.mapbox.com " +
|
|
269
|
-
c_colors.FgYellow +
|
|
270
|
-
" Example --folder=pk.eyJ1IjoibZglZm55IiwiYSI698mNrZW84Nm9rYTA2ZWgycm9mdmNscmFxYzcifQ.c-zxDZXCthXmRsErPzKhbQ " +
|
|
271
|
-
c_colors.Reset
|
|
272
|
-
);
|
|
273
|
-
process.exit();
|
|
274
|
-
}
|
|
275
|
-
if (myArgs.hasOwnProperty("lat1") !== true) {
|
|
276
|
-
error = true;
|
|
277
|
-
console.log(
|
|
278
|
-
c_colors.BError +
|
|
279
|
-
"Missing start latitude. " +
|
|
280
|
-
c_colors.FgYellow +
|
|
281
|
-
" Example --lat1=-54.652332555" +
|
|
282
|
-
c_colors.Reset
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
if (myArgs.hasOwnProperty("lng1") !== true) {
|
|
286
|
-
error = true;
|
|
287
|
-
console.log(
|
|
288
|
-
c_colors.BError +
|
|
289
|
-
"Missing start longitude. " +
|
|
290
|
-
c_colors.FgYellow +
|
|
291
|
-
" Example --lng1=-54.652332555" +
|
|
292
|
-
c_colors.Reset
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
if (myArgs.hasOwnProperty("lat2") !== true) {
|
|
296
|
-
error = true;
|
|
297
|
-
console.log(
|
|
298
|
-
c_colors.BError +
|
|
299
|
-
"Missing end latitude. " +
|
|
300
|
-
c_colors.FgYellow +
|
|
301
|
-
" Example --lat2=-54.652332555" +
|
|
302
|
-
c_colors.Reset
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
if (myArgs.hasOwnProperty("lng2") !== true) {
|
|
306
|
-
error = true;
|
|
307
|
-
console.log(
|
|
308
|
-
c_colors.BError +
|
|
309
|
-
"Missing end longitude. " +
|
|
310
|
-
c_colors.FgYellow +
|
|
311
|
-
" Example --lng2=-54.652332555" +
|
|
312
|
-
c_colors.Reset
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
if (myArgs.hasOwnProperty("zout") !== true) {
|
|
316
|
-
myArgs.zout = 0;
|
|
317
|
-
console.log(
|
|
318
|
-
c_colors.FgCyan +
|
|
319
|
-
"Missing zoom out max. Use zero as a default. " +
|
|
320
|
-
c_colors.FgYellow +
|
|
321
|
-
" Example --zout=0 " +
|
|
322
|
-
c_colors.Reset
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
if (myArgs.hasOwnProperty("zin") !== true) {
|
|
326
|
-
error = true;
|
|
327
|
-
console.log(
|
|
328
|
-
c_colors.BError +
|
|
329
|
-
"Missing zoom in max between 18 & 2. " +
|
|
330
|
-
c_colors.FgYellow +
|
|
331
|
-
" Example --zin=10 " +
|
|
332
|
-
c_colors.Reset
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
if (myArgs.hasOwnProperty("folder") !== true) {
|
|
336
|
-
error = true;
|
|
337
|
-
console.log(
|
|
338
|
-
c_colors.BError +
|
|
339
|
-
"Missing output folder. " +
|
|
340
|
-
c_colors.FgYellow +
|
|
341
|
-
" Example --folder=./out " +
|
|
342
|
-
c_colors.Reset
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
if (myArgs.hasOwnProperty("provider") === true) {
|
|
346
|
-
if (myArgs.provider == 1)
|
|
347
|
-
{
|
|
348
|
-
map_provider = 1;
|
|
349
|
-
if (myArgs.hasOwnProperty("token") !== true) {
|
|
350
|
-
error = true;
|
|
351
|
-
console.log(
|
|
352
|
-
c_colors.BError +
|
|
353
|
-
"Missing TOKEN file for https://api.mapbox.com. " +
|
|
354
|
-
c_colors.FgYellow +
|
|
355
|
-
" Example --token=pk.eyJ1IjoibZglZm55IiwiYSI698mNrZW84Nm9rYTA2ZWgycm9mdmNscmFxYzcifQ.c-zxDZXCthXmRsErPzKhbQ " +
|
|
356
|
-
c_colors.Reset
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
if (map_provider)
|
|
363
|
-
if (error === true) process.exit(0);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/* ============================================================
|
|
367
|
-
Download Images in Order
|
|
368
|
-
============================================================ */
|
|
369
|
-
|
|
370
|
-
fn_handle_arguments();
|
|
371
|
-
var folder = myArgs.folder;
|
|
372
|
-
for (var zoom = myArgs.zout; zoom <= myArgs.zin; ++zoom) {
|
|
373
|
-
var points = fn_convertFromLngLatToPoints(myArgs.lat1, myArgs.lng1, myArgs.lat2, myArgs.lng2, zoom);
|
|
374
|
-
|
|
375
|
-
var point1 = points[0];
|
|
376
|
-
var point2 = points[1];
|
|
377
|
-
|
|
378
|
-
fn_download_images(point1, point2, zoom);
|
|
379
|
-
}
|