Skip to content

Instantly share code, notes, and snippets.

@veltman
Created December 11, 2015 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veltman/1b33785d8568e7b06d7a to your computer and use it in GitHub Desktop.
Save veltman/1b33785d8568e7b06d7a to your computer and use it in GitHub Desktop.
var express = require("express"),
cors = require("cors"),
request = require("request"),
path = require("path"),
app = express();
app.use(cors());
app.all("*",function(req,res){
// Get the vector tile from Mapzen
request.get("https://" + path.join("vector.mapzen.com",req.url),function(err,r,body){
res.status(r.statusCode);
// Quit if error
if (r.statusCode !== 200) {
return res.send(body || "");
}
// This assumes TopoJSON, could modify for GeoJSON, etc.
var topo = JSON.parse(body);
// Modify the content
if ("buildings" in topo.objects) {
topo.objects.buildings.geometries.forEach(function(geom){
// Add/edit properties
});
}
// Send the modified JSON
res.json(topo);
});
});
app.listen(8888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment