Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create tileserver #2

Open
brandonfcohen1 opened this issue Nov 12, 2021 · 0 comments
Open

create tileserver #2

brandonfcohen1 opened this issue Nov 12, 2021 · 0 comments
Assignees

Comments

@brandonfcohen1
Copy link
Owner

sample:

app.get("/api/v1/demovector/:x/:y/:z/:t?", function(req, res) {
  let bbox = mercator.bbox(req.params.x, req.params.y, req.params.z)
  const sql = `
      SELECT ST_AsMVT(q, 'demographics', 4096, 'geom')
      FROM (
          SELECT
              key,
              ST_ASText(geom) w,
              ST_AsMVTGeom(
                  geom,
                  ST_MakeBox2D(ST_Point(${bbox[0]}, ${bbox[1]}), ST_Point(${bbox[2]}, ${bbox[3]})), 4096,
                  256,
                  true
              ) geom
          FROM (select * from `+req.params.t+` WHERE ST_Intersects(geom, 
                  ST_MakeEnvelope($1, $2, $3, $4, $5))) r        
      ) as q`

  const values = [bbox[0], bbox[1], bbox[2], bbox[3], 4326]
  app.pgpool.query(sql, values , function(err, mvt) {
      if (err) {
          console.log(err)
      } else {
          res.setHeader('Content-Type', 'application/x-protobuf')
          res.send(mvt.rows[0].st_asmvt)
      }
  })
})
@brandonfcohen1 brandonfcohen1 self-assigned this Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant