-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from geolonia/create-tiles-json
Tiles.json を生成
- Loading branch information
Showing
5 changed files
with
1,143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.github | ||
.env.test | ||
README.md | ||
action.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const sqlite3 = require('sqlite3'); | ||
const { open } = require("sqlite"); | ||
|
||
async function main() { | ||
const mbtilesPath = process.argv[2]; | ||
|
||
const basename = path.basename(mbtilesPath, ".mbtiles"); | ||
const db = await open({ | ||
filename: mbtilesPath, | ||
driver: sqlite3.Database, | ||
}); | ||
|
||
const {value} = await db.get("SELECT value FROM metadata WHERE name = 'json'"); | ||
const theJSON = JSON.parse(value); | ||
delete theJSON['tilestats']; | ||
|
||
await db.run( | ||
"UPDATE metadata SET value = ? WHERE name = 'json'", | ||
[ | ||
JSON.stringify(theJSON), | ||
], | ||
); | ||
|
||
await db.run( | ||
"DELETE FROM metadata WHERE name IN ('generator_options', 'generator', 'strategies')", | ||
); | ||
|
||
const metadataRows = await db.all("SELECT * FROM metadata"); | ||
const metadataOut = { | ||
"tilejson": "3.0.0", | ||
}; | ||
for (const row of metadataRows) { | ||
if (row.name === "json") { | ||
const json = JSON.parse(row.value); | ||
for (const key of Object.keys(json)) { | ||
metadataOut[key] = json[key]; | ||
} | ||
} else { | ||
let val = row.value; | ||
if (row.name === 'bounds' || row.name === 'center') { | ||
val = row.value.split(",").map((v) => parseFloat(v)); | ||
} else if (row.name === 'minzoom' || row.name === 'maxzoom') { | ||
val = parseInt(row.value, 10); | ||
} | ||
metadataOut[row.name] = val; | ||
} | ||
} | ||
await fs.promises.writeFile(path.join(path.dirname(mbtilesPath), `${basename}.json`), JSON.stringify(metadataOut, null, 2)); | ||
|
||
await db.close(); | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.