-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhistorical-maps.js
More file actions
103 lines (85 loc) · 3.28 KB
/
historical-maps.js
File metadata and controls
103 lines (85 loc) · 3.28 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
const axios = require('axios');
const cheerio = require('cheerio');
module.exports = {
getHistoricalMaps,
};
async function getHistoricalMaps(leftLon, bottomLat, rightLon, topLat) {
const requestConfig = {
baseURL: "http://warper.wmflabs.org/",
url: "/api/v1/maps.json",
method: "get",
params: {
show_warped: 1,
bbox: leftLon + "," + bottomLat + "," + rightLon + "," + topLat,
per_page: 50
}
};
const response = await axios.request(requestConfig);
const warpedMaps = response.data.data;
let commonsTitles = [];
for (var i = 0; i < warpedMaps.length; i++) {
commonsTitles.push(warpedMaps[i].attributes.title);
}
const titles = commonsTitles.join('|');
const requestConfigGetImageInfo = {
baseURL: "https://commons.wikimedia.org/",
url: "/w/api.php",
method: "get",
timeout: 10000,
params: {
action: "query",
titles: titles,
iiurlwidth: 400,
iiurlheight: 400,
prop: "imageinfo",
iiprop: "user|url|extmetadata",
redirects: "resolve",
format: "json"
}
};
const imageInfoResponse = await axios.request(requestConfigGetImageInfo);
const pages = Object.keys(imageInfoResponse.data.query.pages).map(function(e) {
return imageInfoResponse.data.query.pages[e];
});
let basemaps = [];
for (var i = 0; i < warpedMaps.length; i++) {
for (var j = 0; j < pages.length; j++) {
if (warpedMaps[i].attributes.title == pages[j].title &&
pages[j].imageinfo != undefined) {
var page = pages[j];
var basemap = {
id: page.title,
title: "",
imageURL: page.imageinfo[0].url,
thumbURL: page.imageinfo[0].thumburl,
commonsInfoURL: page.imageinfo[0].descriptionurl,
year: null,
license: null,
server: "http://warper.wmflabs.org/",
warperID: parseInt(warpedMaps[i].id, 10),
bbox: warpedMaps[i].attributes.bbox
};
if (page.imageinfo[0].extmetadata.ImageDescription != undefined) {
var origHTML = page.imageinfo[0].extmetadata.ImageDescription.value;
const $ = cheerio.load(origHTML);
var title = $.text();
basemap.title = title;
}
if (page.imageinfo[0].extmetadata.DateTimeOriginal != undefined) {
var dateString = page.imageinfo[0].extmetadata.DateTimeOriginal.value;
var year = parseInt(dateString.substr(0, 4), 10);
if (year != NaN) {
basemap.year = year;
}
}
if (page.imageinfo[0].extmetadata.LicenseShortName != undefined) {
basemap.license = page.imageinfo[0].extmetadata.LicenseShortName.value;
}
if (basemap.year != null && basemap.year < 2000) {
basemaps.push(basemap);
}
}
}
}
return basemaps;
}