Skip to content

Commit

Permalink
codeforjapan#288 merge zxy each tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
smellman committed Feb 17, 2020
1 parent fbde7b8 commit 7d6cee0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
1 change: 0 additions & 1 deletion create_tiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
49 changes: 28 additions & 21 deletions createtiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
})
})
8 changes: 8 additions & 0 deletions merge_tiles.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7d6cee0

Please sign in to comment.