Skip to content

Commit

Permalink
Add sprite@2x to json and png tile routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dianna Faulk committed Oct 27, 2019
1 parent 371287a commit b407da0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ const app = express();

app.use(cors());

app.get("/tiles/:version/tiles/:z/:x/:y.pbf", function(req, res) {
app.get("/tiles/:version/tiles/:z/:x/:y.pbf", function (req, res) {
const { z, x, y } = req.params;
new MBTiles(path.join(__dirname, "tiles", "tiles.mbtiles"), function(
new MBTiles(path.join(__dirname, "tiles", "tiles.mbtiles"), function (
err,
mbtiles
) {
if (err) {
res.header("Content-Type", "text/plain");
res.status(500).send(`Tile error: ${err}`);
} else {
mbtiles.getTile(z, x, y, function(err, tile, headers) {
mbtiles.getTile(z, x, y, function (err, tile, headers) {
if (err) {
res.header("Content-Type", "text/plain");
res.status(404).send(`Tile error ${err}`);
Expand All @@ -31,13 +31,13 @@ app.get("/tiles/:version/tiles/:z/:x/:y.pbf", function(req, res) {
});
});

const themeHandler = function(req, res) {
const themeHandler = function (req, res) {
let theme = req.params.theme;
if (!theme.endsWith(".json")) {
theme = theme + ".json";
}
const filePath = path.join(__dirname, "themes", theme);
fs.readFile(filePath, "utf8", function(err, file) {
fs.readFile(filePath, "utf8", function (err, file) {
if (err) {
res.status(500);
res.json({ status: 500, message: `Could not load theme: ${err}` });
Expand All @@ -55,11 +55,11 @@ const themeHandler = function(req, res) {
app.get("/tiles/styles/:version/:theme", themeHandler);
app.get("/tiles/:version/:theme", themeHandler);

app.get("/tiles/styles/:version/:theme/sprite.json", function(req, res) {
app.get(["/tiles/styles/:version/:theme/sprite.json", "/tiles/styles/:version/:theme/[email protected]"], function (req, res) {
res.json({});
});

app.get("/tiles/styles/:version/:theme/sprite.png", function(req, res) {
app.get(["/tiles/styles/:version/:theme/sprite.png", "/tiles/styles/:version/:theme/[email protected]"], function (req, res) {
const reader = fs.createReadStream(
path.join(__dirname, "themes", "sprite.png")
);
Expand Down

0 comments on commit b407da0

Please sign in to comment.