Created
December 11, 2015 16:10
-
-
Save veltman/1b33785d8568e7b06d7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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