Skip to content

Instantly share code, notes, and snippets.

View jczaplew's full-sized avatar

John J Czaplewski jczaplew

View GitHub Profile
@chriswhong
chriswhong / gist:762ceac7fb8a1420e7e7adceb770b707
Last active March 3, 2022 09:01
Using ST_AsMVT() and ST_AsMVTGeom() in express to build a vector tile endpoint
/* GET /tiles/:z/:x/:y.mvt */
/* Retreive a vector tile by tileid */
router.get('/tiles/:z/:x/:y.mvt', async (req, res) => {
const { z, x, y } = req.params;
// calculate the bounding polygon for this tile
const bbox = mercator.bbox(x, y, z, false);
// Query the database, using ST_AsMVTGeom() to clip the geometries
// Wrap the whole query with ST_AsMVT(), which will create a protocol buffer
@missinglink
missinglink / leaflet-foursquare.js
Last active November 29, 2016 14:59
Leaflet configuration which allows you to set map co-ordinates with a pixel offset (as per foursquare homepage). In this example I am using jQuery to find the width of `$('main.content')` and use that to offset the map.
var map = L.map( 'map' );
L.Map.prototype.panToOffset = function (latlng, offset, options) {
var x = this.latLngToContainerPoint(latlng).x - offset[0]
var y = this.latLngToContainerPoint(latlng).y - offset[1]
var point = this.containerPointToLatLng([x, y])
return this.setView(point, this._zoom, { pan: options })
}
function centerMap(){