0.1.0 • Published 1 year ago

@durstdog87/dropin-tileservice v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Drop In Tileservice

A drop in vector tile service using pg for turning any postres backend into a tileserver.

Pre Requisites:

Installation

  • Clone this repo then build using npm run build at the root
  • Install in your application with npm install path/to/repo
  • Link with npm link path/to/repo

Usage: (Express example)

import { Tileserver } from "dropin-tileservice"
import { Pool } from "pg"
import Express from "express"

const app = Express()
const port = 5000

app.use(cors())

const connection_params = {
    user: "postgres",
    host: "localhost",
    database: "features",
    password: "secret-password", //optional
    port: 5432
}

const pool = new Pool(connection_params)

const tileService = new Tileserver()
//SQL to be run against the pool db
tileservice.setQuery("SELECT id, geom FROM schema.table WHERE prop = 44") 
tileservice.setSrid(2252) //Michigan Central

app.get("/tiles/:z/:x/:y", async (req, res) => {
    try {
        const conn = await pool.connect()
        const tiles = await ts.query(req.params.z, req.params.x, req.params.y, conn, {
            layername: "default"
        })
        res.status(200).send(tiles) //protobuf sent as result 
    } catch (e) {
        console.log(e)
    } finally {
        await conn.release()
    }

})

With Params

tileservice.setQuery("SELECT id, geom FROM schema.table WHERE prop = $1") 
tileservice.setSrid(2252) //Michigan Central

app.get("/tiles/:z/:x/:y", async (req, res) => {
    try {
        const conn = await pool.connect()
        const tiles = await ts.query(req.params.z, req.params.x, req.params.y, conn, {
            params: [44],
            layername: "default"
        })
        res.status(200).send(tiles) //protobuf sent as result 
    } catch (e) {
        console.log(e)
    } finally {
        await conn.release()
    }
})

Passing queryString and srid

app.get("/tiles/:z/:x/:y", async (req, res) => {
    try {
        const conn = await pool.connect()
        const tiles = await ts.query(req.params.z, req.params.x, req.params.y, conn, {
            queryString: "SELECT id, geom FROM schema.table WHERE prop = $1",
            srid: 2252,
            params: [44],
            layername: "default"
        })
        res.status(200).send(tiles) //protobuf sent as result 
    } catch (e) {
        console.log(e)
    } finally {
        await conn.release()
    }
})
ansi-stylesansi-escapesacorn-jsxacornansi-regexbabel-plugin-jest-hoistbabel-jestanymatchargparsebabel-plugin-istanbulbabel-plugin-polyfill-corejs3babel-plugin-polyfill-corejs2babel-preset-jestbabel-preset-current-node-syntaxbrace-expansionbracesbrowserslistajvbserbalanced-matchbabel-plugin-polyfill-regeneratorbs-loggerbuiltin-modulesbuffer-writercamelcasecaniuse-litecallsiteschalkchar-regexcliuicolor-namebuffer-fromcolor-convertcjs-module-lexerconvert-source-mapci-infocommandercollect-v8-coveragecreate-jestcross-spawncocore-js-compatdeep-isdedentdeepmergedebugdiffdiff-sequencesemitterydetect-newlineconcat-mapescaladedoctrineelectron-to-chromiumemoji-regexerror-exeslint-visitor-keyseslint-scopeespreeesprimaescape-string-regexpesrecurseesutilsexitestraverseexpectesqueryfast-json-stable-stringifyfast-deep-equalfastqfb-watchmanfill-rangeexecafs.realpathfind-upfile-entry-cacheflat-cacheflattedfseventsfunction-bindget-package-typeget-caller-fileget-streamglob-parentglobalshas-flagglobhasfast-levenshteingensyncgraphemerhuman-signalsgraceful-fsimport-localimurmurhashinheritsimport-freshis-arrayishis-extglobis-core-moduleis-fullwidth-code-pointis-generator-fnhtml-escaperinflightis-path-insideignoreis-numberistanbul-lib-coverageistanbul-lib-instrumentis-globis-streamistanbul-lib-source-mapsistanbul-lib-reportisexejest-changed-filesjest-circusistanbul-reportsjest-clijest-docblockjest-eachjest-environment-nodejest-configjest-leak-detectorjest-get-typejest-diffjest-mockjest-matcher-utilsjest-haste-mapjest-regex-utiljest-pnp-resolverjest-runnerjest-runtimejest-utiljest-snapshotjest-resolvejest-watcherjest-validatejest-workerjest-resolve-dependenciesjs-tokensjsescjson-schema-traversejson-stable-stringify-without-jsonifyjson-parse-even-better-errorslevenkleurjs-yamljson5lodash.debouncelocate-pathlines-and-columnslodash.memoizelodash.mergelevnlru-cachejest-message-utilmakeerrormicromatchmimic-fnmake-dirmerge-streammake-errormsnode-int64natural-compareminimatchminimistnpm-run-pathonetimemkdirpnode-releasesp-tryobufnormalize-pathonceoptionatorparse-jsonp-locatep-limitpacket-readerparent-modulepath-keypath-parsepath-existspg-int8pg-cloudflarepath-is-absolutepg-connection-stringpg-protocolpicocolorspg-typespicomatchpgpasspg-poolpiratespkg-dirpostgres-intervalpostgres-byteapostgres-dateprelude-lspg-numericpostgres-rangepretty-formatpromptspostgres-arraypunycodereact-isqueue-microtaskpure-randregenerateregenerate-unicode-propertiesregenerator-transformrequire-directoryregexpu-coreregenerator-runtimeregjsparserresolve.exportsresolve-cwdrun-parallelresolve-fromresolverimrafshebang-commandshebang-regexsignal-exitsisteransireusifysplit2source-mapsprintf-jsslashstack-utilsstring-lengthstring-widthstrip-ansistrip-bomsource-map-supportstrip-json-commentsstrip-final-newlinesupports-colortext-tablesupports-preserve-symlinks-flagsemverto-fast-propertiestest-excludeto-regex-rangetype-detecttsutilstype-checktype-festunicode-match-property-ecmascriptunicode-property-aliases-ecmascriptunicode-canonical-property-names-ecmascripttmplupdate-browserslist-dbunicode-match-property-value-ecmascriptv8-to-istanbuluri-jswhichxtendwalkerwrappyy18nyallistwrite-file-atomictslibwrap-ansiyargsyargs-parseryocto-queue
0.1.0

1 year ago