From 7d6cee08c8c339a8394df2787a7bfe0efa10856c Mon Sep 17 00:00:00 2001 From: Taro Matsuzawa Date: Mon, 17 Feb 2020 14:01:23 +0900 Subject: [PATCH] #288 merge zxy each tiles --- create_tiles.sh | 1 - createtiles.ts | 49 ++++++++++++++++++++++++++++--------------------- merge_tiles.sh | 8 ++++++++ 3 files changed, 36 insertions(+), 22 deletions(-) create mode 100755 merge_tiles.sh diff --git a/create_tiles.sh b/create_tiles.sh index 17973946..7e5562e1 100755 --- a/create_tiles.sh +++ b/create_tiles.sh @@ -9,4 +9,3 @@ target="${id}.mbtiles" zxy="${id}/zxy" mkdir -p "${dir}/$zxy" npx togeojson "${dir}/$file" | tippecanoe -f -o "${dir}/$target" --base-zoom=2 -tile-join --output-to-directory="${dir}/$zxy" --force --no-tile-compression --no-tile-size-limit "${dir}/$target" diff --git a/createtiles.ts b/createtiles.ts index 6c1fb890..dbffe8e8 100644 --- a/createtiles.ts +++ b/createtiles.ts @@ -16,28 +16,35 @@ list.map((name) => { // load map config console.log(`loading ${CONFIG_DIR}${name}`) const config = require(`${CONFIG_DIR}${name}`) - config.sources.forEach((source) => { - // download source file - if (!fs.existsSync(`${TARGET_DIR}${config.map_id}`)) { - fs.mkdirSync(`${TARGET_DIR}${config.map_id}`, {recursive: true}); - } - console.log(`downloading ${source.url}...`) - axios.get(source.url).then((response) => { - // currently, this is supporting only kml - const file_path = `${TARGET_DIR}${config.map_id}/${source.id}.${source.type}` - fs.writeFile(file_path, response.data, (err) => { - // failed - if(err){ - console.log("Downloading kml file failed" + err) - throw err - } - // success - else{ - console.log(`Downloaded ${source.id}.${source.type}`) - // convert kml files to xyz tile - shell.exec(`./create_tiles.sh ${file_path}`) - } + const funcs = config.sources.map(source => { + return new Promise((resolve, reject) => { + // download source file + if (!fs.existsSync(`${TARGET_DIR}${config.map_id}`)) { + fs.mkdirSync(`${TARGET_DIR}${config.map_id}`, {recursive: true}); + } + console.log(`downloading ${source.url}...`) + axios.get(source.url).then((response) => { + // currently, this is supporting only kml + const file_path = `${TARGET_DIR}${config.map_id}/${source.id}.${source.type}` + fs.writeFile(file_path, response.data, (err) => { + // failed + if(err){ + console.log("Downloading kml file failed" + err) + reject(err) + } + // success + else{ + console.log(`Downloaded ${source.id}.${source.type}`) + // convert kml files to xyz tile + shell.exec(`./create_tiles.sh ${file_path}`) + resolve() + } + }) }) }) }) + Promise.all(funcs).then(() => { + console.log(`${name} is finished!!!!!!!!`) + shell.exec(`./merge_tiles.sh ${name} ${TARGET_DIR}`) + }) }) \ No newline at end of file diff --git a/merge_tiles.sh b/merge_tiles.sh new file mode 100755 index 00000000..54a0dcd8 --- /dev/null +++ b/merge_tiles.sh @@ -0,0 +1,8 @@ +#!/bin/bash +file=$1 +base=`basename $file .json` +target_dir=$2 +dir=$target_dir$base +echo "----------------------" +echo "convert raw tile to ${dir}/${zxy}" +tile-join --output-to-directory="${dir}/$zxy" --force --no-tile-compression --no-tile-size-limit $dir/*.mbtiles