fix wgs84 scheme
This commit is contained in:
@@ -76,7 +76,7 @@ RUN mkdir -p /data && chown node:node /data
|
|||||||
VOLUME /data
|
VOLUME /data
|
||||||
WORKDIR /data
|
WORKDIR /data
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 8000
|
||||||
|
|
||||||
USER node:node
|
USER node:node
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ trap refresh HUP
|
|||||||
|
|
||||||
if ! which -- "${1}"; then
|
if ! which -- "${1}"; then
|
||||||
# first arg is not an executable
|
# first arg is not an executable
|
||||||
xvfb-run -a --server-args="-screen 0 1024x768x24" -- node /usr/src/app/ -p 80 "$@" &
|
xvfb-run -a --server-args="-screen 0 1024x768x24" -- node /usr/src/app/ -p 8000 "$@" &
|
||||||
# Wait exits immediately on signals which have traps set. Store return value and wait
|
# Wait exits immediately on signals which have traps set. Store return value and wait
|
||||||
# again for all jobs to actually complete before continuing.
|
# again for all jobs to actually complete before continuing.
|
||||||
wait $! || RETVAL=$?
|
wait $! || RETVAL=$?
|
||||||
|
|||||||
@@ -10,108 +10,97 @@ import MBTiles from '@mapbox/mbtiles';
|
|||||||
import Pbf from 'pbf';
|
import Pbf from 'pbf';
|
||||||
import VectorTile from '@mapbox/vector-tile';
|
import VectorTile from '@mapbox/vector-tile';
|
||||||
|
|
||||||
import { getTileUrls, fixTileJSONCenter } from './utils.js';
|
import {getTileUrls, fixTileJSONCenter} from './utils.js';
|
||||||
|
|
||||||
export const serve_data = {
|
export const serve_data = {
|
||||||
init: (options, repo) => {
|
init: (options, repo) => {
|
||||||
const app = express().disable('x-powered-by');
|
const app = express().disable('x-powered-by');
|
||||||
|
|
||||||
app.get(
|
app.get('/:id/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w.]+)', (req, res, next) => {
|
||||||
'/:id/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w.]+)',
|
const item = repo[req.params.id];
|
||||||
(req, res, next) => {
|
if (!item) {
|
||||||
const item = repo[req.params.id];
|
return res.sendStatus(404);
|
||||||
if (!item) {
|
}
|
||||||
return res.sendStatus(404);
|
const tileJSONFormat = item.tileJSON.format;
|
||||||
}
|
const z = req.params.z | 0;
|
||||||
const tileJSONFormat = item.tileJSON.format;
|
const x = req.params.x | 0;
|
||||||
const z = req.params.z | 0;
|
const y = req.params.y | 0;
|
||||||
const x = req.params.x | 0;
|
let format = req.params.format;
|
||||||
const y = req.params.y | 0;
|
if (format === options.pbfAlias) {
|
||||||
let format = req.params.format;
|
format = 'pbf';
|
||||||
if (format === options.pbfAlias) {
|
}
|
||||||
format = 'pbf';
|
if (format !== tileJSONFormat &&
|
||||||
}
|
!(format === 'geojson' && tileJSONFormat === 'pbf')) {
|
||||||
if (
|
return res.status(404).send('Invalid format');
|
||||||
format !== tileJSONFormat &&
|
}
|
||||||
!(format === 'geojson' && tileJSONFormat === 'pbf')
|
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
||||||
) {
|
|
||||||
return res.status(404).send('Invalid format');
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
z < item.tileJSON.minzoom ||
|
|
||||||
0 ||
|
|
||||||
x < 0 ||
|
|
||||||
y < 0 ||
|
|
||||||
z > item.tileJSON.maxzoom ||
|
z > item.tileJSON.maxzoom ||
|
||||||
x >= Math.pow(2, z) ||
|
x >= Math.pow(2, options.wgs84 ? z + 1 : z) || y >= Math.pow(2, z)) {
|
||||||
y >= Math.pow(2, z)
|
return res.status(404).send('Out of bounds');
|
||||||
) {
|
}
|
||||||
return res.status(404).send('Out of bounds');
|
item.source.getTile(z, x, y, (err, data, headers) => {
|
||||||
}
|
let isGzipped;
|
||||||
item.source.getTile(z, x, y, (err, data, headers) => {
|
if (err) {
|
||||||
let isGzipped;
|
if (/does not exist/.test(err.message)) {
|
||||||
if (err) {
|
return res.status(204).send();
|
||||||
if (/does not exist/.test(err.message)) {
|
|
||||||
return res.status(204).send();
|
|
||||||
} else {
|
|
||||||
return res.status(500).send(err.message);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (data == null) {
|
return res.status(500).send(err.message);
|
||||||
return res.status(404).send('Not found');
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tileJSONFormat === 'pbf') {
|
if (data == null) {
|
||||||
isGzipped =
|
return res.status(404).send('Not found');
|
||||||
data.slice(0, 2).indexOf(Buffer.from([0x1f, 0x8b])) === 0;
|
} else {
|
||||||
if (options.dataDecoratorFunc) {
|
if (tileJSONFormat === 'pbf') {
|
||||||
if (isGzipped) {
|
isGzipped = data.slice(0, 2).indexOf(
|
||||||
data = zlib.unzipSync(data);
|
Buffer.from([0x1f, 0x8b])) === 0;
|
||||||
isGzipped = false;
|
if (options.dataDecoratorFunc) {
|
||||||
}
|
|
||||||
data = options.dataDecoratorFunc(id, 'data', data, z, x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (format === 'pbf') {
|
|
||||||
headers['Content-Type'] = 'application/x-protobuf';
|
|
||||||
} else if (format === 'geojson') {
|
|
||||||
headers['Content-Type'] = 'application/json';
|
|
||||||
|
|
||||||
if (isGzipped) {
|
if (isGzipped) {
|
||||||
data = zlib.unzipSync(data);
|
data = zlib.unzipSync(data);
|
||||||
isGzipped = false;
|
isGzipped = false;
|
||||||
}
|
}
|
||||||
|
data = options.dataDecoratorFunc(id, 'data', data, z, x, y);
|
||||||
const tile = new VectorTile(new Pbf(data));
|
|
||||||
const geojson = {
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [],
|
|
||||||
};
|
|
||||||
for (const layerName in tile.layers) {
|
|
||||||
const layer = tile.layers[layerName];
|
|
||||||
for (let i = 0; i < layer.length; i++) {
|
|
||||||
const feature = layer.feature(i);
|
|
||||||
const featureGeoJSON = feature.toGeoJSON(x, y, z);
|
|
||||||
featureGeoJSON.properties.layer = layerName;
|
|
||||||
geojson.features.push(featureGeoJSON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data = JSON.stringify(geojson);
|
|
||||||
}
|
}
|
||||||
delete headers['ETag']; // do not trust the tile ETag -- regenerate
|
|
||||||
headers['Content-Encoding'] = 'gzip';
|
|
||||||
res.set(headers);
|
|
||||||
|
|
||||||
if (!isGzipped) {
|
|
||||||
data = zlib.gzipSync(data);
|
|
||||||
isGzipped = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.status(200).send(data);
|
|
||||||
}
|
}
|
||||||
|
if (format === 'pbf') {
|
||||||
|
headers['Content-Type'] = 'application/x-protobuf';
|
||||||
|
} else if (format === 'geojson') {
|
||||||
|
headers['Content-Type'] = 'application/json';
|
||||||
|
|
||||||
|
if (isGzipped) {
|
||||||
|
data = zlib.unzipSync(data);
|
||||||
|
isGzipped = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tile = new VectorTile(new Pbf(data));
|
||||||
|
const geojson = {
|
||||||
|
'type': 'FeatureCollection',
|
||||||
|
'features': []
|
||||||
|
};
|
||||||
|
for (const layerName in tile.layers) {
|
||||||
|
const layer = tile.layers[layerName];
|
||||||
|
for (let i = 0; i < layer.length; i++) {
|
||||||
|
const feature = layer.feature(i);
|
||||||
|
const featureGeoJSON = feature.toGeoJSON(x, y, z);
|
||||||
|
featureGeoJSON.properties.layer = layerName;
|
||||||
|
geojson.features.push(featureGeoJSON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data = JSON.stringify(geojson);
|
||||||
|
}
|
||||||
|
delete headers['ETag']; // do not trust the tile ETag -- regenerate
|
||||||
|
headers['Content-Encoding'] = 'gzip';
|
||||||
|
res.set(headers);
|
||||||
|
|
||||||
|
if (!isGzipped) {
|
||||||
|
data = zlib.gzipSync(data);
|
||||||
|
isGzipped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send(data);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
},
|
});
|
||||||
);
|
});
|
||||||
|
|
||||||
app.get('/:id.json', (req, res, next) => {
|
app.get('/:id.json', (req, res, next) => {
|
||||||
const item = repo[req.params.id];
|
const item = repo[req.params.id];
|
||||||
@@ -119,16 +108,10 @@ export const serve_data = {
|
|||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
}
|
}
|
||||||
const info = clone(item.tileJSON);
|
const info = clone(item.tileJSON);
|
||||||
info.tiles = getTileUrls(
|
info.tiles = getTileUrls(req, info.tiles,
|
||||||
req,
|
`data/${req.params.id}`, info.format, item.publicUrl, {
|
||||||
info.tiles,
|
'pbf': options.pbfAlias
|
||||||
`data/${req.params.id}`,
|
});
|
||||||
info.format,
|
|
||||||
item.publicUrl,
|
|
||||||
{
|
|
||||||
pbf: options.pbfAlias,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return res.send(info);
|
return res.send(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -137,7 +120,7 @@ export const serve_data = {
|
|||||||
add: (options, repo, params, id, publicUrl) => {
|
add: (options, repo, params, id, publicUrl) => {
|
||||||
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
|
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
|
||||||
let tileJSON = {
|
let tileJSON = {
|
||||||
tiles: params.domains || options.domains,
|
'tiles': params.domains || options.domains
|
||||||
};
|
};
|
||||||
|
|
||||||
const mbtilesFileStats = fs.statSync(mbtilesFile);
|
const mbtilesFileStats = fs.statSync(mbtilesFile);
|
||||||
@@ -146,7 +129,7 @@ export const serve_data = {
|
|||||||
}
|
}
|
||||||
let source;
|
let source;
|
||||||
const sourceInfoPromise = new Promise((resolve, reject) => {
|
const sourceInfoPromise = new Promise((resolve, reject) => {
|
||||||
source = new MBTiles(mbtilesFile + '?mode=ro', (err) => {
|
source = new MBTiles(mbtilesFile + '?mode=ro', err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
return;
|
return;
|
||||||
@@ -181,8 +164,8 @@ export const serve_data = {
|
|||||||
repo[id] = {
|
repo[id] = {
|
||||||
tileJSON,
|
tileJSON,
|
||||||
publicUrl,
|
publicUrl,
|
||||||
source,
|
source
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user