forked from MapComplete/MapComplete
Make tilecountserver accept arguments
This commit is contained in:
parent
da1eca797c
commit
caaaff45da
1 changed files with 66 additions and 52 deletions
|
@ -1,6 +1,7 @@
|
|||
import { Client } from "pg"
|
||||
import { Tiles } from "../../src/Models/TileRange"
|
||||
import { Server } from "../server"
|
||||
import Script from "../Script"
|
||||
|
||||
/**
|
||||
* Just the OSM2PGSL default database
|
||||
|
@ -114,7 +115,7 @@ class OsmPoiDatabase {
|
|||
meta[property] = value
|
||||
}
|
||||
this.metaCacheDate = now
|
||||
this.metaCache = <any>meta
|
||||
this.metaCache = <PoiDatabaseMeta> meta
|
||||
return this.metaCache
|
||||
}
|
||||
}
|
||||
|
@ -160,14 +161,22 @@ class CachedSqlCount {
|
|||
}
|
||||
}
|
||||
|
||||
const connectionString = "postgresql://user:password@localhost:5444/osm-poi"
|
||||
|
||||
class TileCountServer extends Script {
|
||||
constructor() {
|
||||
super("Starts the tilecount server which calculates summary for a given tile, based on the database. Usage: [db-connection-string] [port=2345]")
|
||||
}
|
||||
|
||||
async main(args: string[]): Promise<void> {
|
||||
const connectionString = args[0] ?? "postgresql://user:password@localhost:5444/osm-poi"
|
||||
const port = Number(args[1] ?? 2345)
|
||||
const tcs = new OsmPoiDatabase(connectionString)
|
||||
const withCache = new CachedSqlCount(tcs, 14 * 60 * 60 * 24)
|
||||
new Server(2345, { ignorePathPrefix: ["summary"] }, [
|
||||
new Server(port, { ignorePathPrefix: ["summary"] }, [
|
||||
{
|
||||
mustMatch: "status.json",
|
||||
mimetype: "application/json",
|
||||
handle: async (path: string) => {
|
||||
handle: async () => {
|
||||
const layers = await tcs.getLayers()
|
||||
const meta = await tcs.getMeta()
|
||||
return JSON.stringify({ meta, layers: Array.from(layers) })
|
||||
|
@ -180,7 +189,7 @@ new Server(2345, { ignorePathPrefix: ["summary"] }, [
|
|||
const [layers, z, x, y] = path.split(".")[0].split("/")
|
||||
|
||||
let sum = 0
|
||||
let properties: Record<string, number> = {}
|
||||
const properties: Record<string, number> = {}
|
||||
const availableLayers = await tcs.getLayers()
|
||||
let latSum = 0
|
||||
let lonSum = 0
|
||||
|
@ -215,3 +224,8 @@ console.log(
|
|||
[3.2839964396059145, 51.172701162680994],
|
||||
])
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
new TileCountServer().run()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue