Skip to content

Commit

Permalink
header
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Oct 30, 2016
0 parents commit 559e3c5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var Canvas = require('canvas');
var express = require('express');
var Image = Canvas.Image;
var fs = require('fs');

var PORT = 19999;
var app = express();


app.get('/tiles/:z/:x/:y', function (req, res) {
var x = req.params.x,
y = req.params.y,
z = req.params.z;
console.log('make tile: ', x, y, z);
res.type('image/png').send(generateTile(x,y,z));
});

app.listen(PORT, function () {
console.log('Tile server is listening on port ' + PORT);
});

function generateTile(x,y,z) {

var canvas = new Canvas(256, 256);
var ctx = canvas.getContext('2d');

var coords = '(' + [x, y].join(', ') + ')';
ctx.rect(0, 0, 256, 256);
ctx.fillStyle = '#F0F0F0';
ctx.fill();
ctx.fillStyle = '#777';
ctx.font = '16px Arial';
ctx.fillText(coords, 24, 64);
ctx.strokeStyle = 'white';
ctx.strokeRect(0, 0, 256, 256);
ctx.fillStyle = '#DDD';
ctx.font = '64px Arial';
ctx.fillText(z + 'x', 64, 192);
var bytes = canvas.toBuffer(undefined, 3, canvas.PNG_FILTER_NONE);
return bytes;
}
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Dummy-map-tiles",
"version": "0.0.1",
"private": true,
"Dependencies": {
"canvas": "^1.6.1",
"express": "^4.14.0"
}
}

0 comments on commit 559e3c5

Please sign in to comment.