Switch scripts to module because of node-fetch v3
This commit is contained in:
parent
58c657e38a
commit
9c59fa10b6
4 changed files with 17 additions and 11 deletions
67
layers/josm/extract.mjs
Normal file
67
layers/josm/extract.mjs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import fetch from 'node-fetch';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const outDir = __dirname;
|
||||
|
||||
const includeList = [
|
||||
"cyclosm",
|
||||
"osmbe",
|
||||
"osmbe-fr",
|
||||
"osmbe-nl",
|
||||
"osmfr-basque",
|
||||
"osmfr-breton",
|
||||
"osmfr-occitan",
|
||||
"OpenStreetMap-turistautak",
|
||||
"hu-hillshade",
|
||||
"Israel_Hiking",
|
||||
"Israel_MTB",
|
||||
"mtbmap-no",
|
||||
"Freemap.sk-Outdoor",
|
||||
"Freemap.sk-Car",
|
||||
"Freemap.sk-Hiking",
|
||||
"Freemap.sk-Cyclo",
|
||||
"opencylemap",
|
||||
"standard",
|
||||
"HDM_HOT",
|
||||
"osmfr",
|
||||
"osm-mapnik-german_style",
|
||||
"OpenTopoMap",
|
||||
"osm-cambodia_laos_thailand_vietnam-bilingual",
|
||||
"Waymarked_Trails-Hiking",
|
||||
"Waymarked_Trails-Cycling",
|
||||
"Waymarked_Trails-MTB",
|
||||
"wikimedia-map",
|
||||
"openpt_map"
|
||||
];
|
||||
|
||||
function extract(layersJosm) {
|
||||
for (let i = 0; i < layersJosm.features.length; i++) {
|
||||
let layer = layersJosm.features[i];
|
||||
let props = layer.properties;
|
||||
let id = props.id;
|
||||
if (includeList.includes(id)) {
|
||||
//console.log(`${id}, ${props.name}, ${props.url}`);
|
||||
|
||||
props.dataSource = 'JOSM';
|
||||
|
||||
const outFileName = path.join(outDir, id + '.geojson');
|
||||
const data = JSON.stringify(layer, null, 2);
|
||||
fs.writeFileSync(outFileName, data);
|
||||
|
||||
includeList.splice(includeList.indexOf(id), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (includeList.length > 0) {
|
||||
console.warn('Layers not found: ', includeList);
|
||||
}
|
||||
}
|
||||
|
||||
fetch('https://josm.openstreetmap.de/maps?format=geojson')
|
||||
.then(res => res.json())
|
||||
.then(json => extract(json))
|
||||
.catch(err => console.error(err));
|
||||
Loading…
Add table
Add a link
Reference in a new issue