Permalink
Browse files

fixes

  • Loading branch information...
normanrz committed Aug 5, 2018
1 parent a586ff4 commit 2ec375da4233ac9177f078be9378ce57b51e75b0
Showing with 26 additions and 21 deletions.
  1. +4 −2 index.js
  2. +5 −1 package.json
  3. +8 −5 test/test.js
  4. +5 −13 tileset.js
  5. +4 −0 yarn.lock
@@ -1,11 +1,13 @@
const { json, send } = require("micro");
const { S3TileSet } = require("./tileset");
const { FileTileSet, S3TileSet } = require("./tileset");

const cacheSize = process.env.TILE_SET_CACHE || 128;
const tileFolder = process.env.TILE_SET_PATH || __dirname;
const maxPostSize = process.env.MAX_POST_SIZE || "500kb";

const tiles = new S3TileSet({ cacheSize });
const tiles = tileFolder.startsWith("s3://")
? new S3TileSet({ cacheSize })
: new FileTileSet(tileFolder, { cacheSize });

module.exports = async (req, res) => {
if (req.method !== "POST") {
@@ -4,12 +4,16 @@
"main": "index.js",
"scripts": {
"start": "micro index.js",
"test": "node test/test.js"
"test": "node test/test.js",
"pretty": "prettier --write *.js test/*.js"
},
"author": "Norman Rzepka <code@normanrz.com>",
"license": "MIT",
"dependencies": {
"lru-memoize": "^1.0.2",
"micro": "^9.3.2"
},
"devDependencies": {
"prettier": "^1.14.0"
}
}
@@ -1,9 +1,12 @@
const TileSet = require("../tileset");
const assert = require("assert");

const { FileTileSet } = require("../tileset");

(async function() {
const tileset = new TileSet(__dirname);
const tileset = new FileTileSet(__dirname);

const testLatLng = [51.3, 13.4];

// Return elevation in meters above sea level.
// By default, elevation is interpolated bilinearly.
console.log(await tileset.getElevation([51.3, 13.4]));
console.log(await tileset.getElevation(testLatLng));
assert(101, await tileset.getElevation(testLatLng));
})();
@@ -12,7 +12,8 @@ class TileSet {
this.options = Object.assign(
{},
{
cacheSize: 128
cacheSize: 128,
gzip: true
},
options
);
@@ -43,21 +44,12 @@ class TileSet {

class FileTileSet extends TileSet {
constructor(folder, options) {
super(
Object.assign(
{},
{
cacheSize: 128,
gzip: true
},
options
)
);
super(options);
this._folder = folder;
}

async _getTile(lat, lng) {
let stream = fs.createReadStream(
let stream = createReadStream(
path.join(this._folder, this.getFilePath(lat, lng))
);
if (this.options.gzip) {
@@ -70,7 +62,7 @@ class FileTileSet extends TileSet {

class S3TileSet extends TileSet {
async _getTile(lat, lng) {
console.log(`${S3TileSet.baseUrl}/${this.getFilePath(lat, lng)}`);
// console.log(`${S3TileSet.baseUrl}/${this.getFilePath(lat, lng)}`);
let stream = await new Promise(resolve =>
get(`${S3TileSet.baseUrl}/${this.getFilePath(lat, lng)}`, resolve)
);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 2ec375d

Please sign in to comment.