fix wgs84 scheme

This commit is contained in:
Ivan Vazhenin
2022-11-14 10:49:22 +03:00
parent 0346d5c304
commit 7101585ee5
3 changed files with 87 additions and 104 deletions

View File

@@ -76,7 +76,7 @@ RUN mkdir -p /data && chown node:node /data
VOLUME /data
WORKDIR /data
EXPOSE 80
EXPOSE 8000
USER node:node

View File

@@ -20,7 +20,7 @@ trap refresh HUP
if ! which -- "${1}"; then
# 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
# again for all jobs to actually complete before continuing.
wait $! || RETVAL=$?

View File

@@ -10,15 +10,13 @@ import MBTiles from '@mapbox/mbtiles';
import Pbf from 'pbf';
import VectorTile from '@mapbox/vector-tile';
import { getTileUrls, fixTileJSONCenter } from './utils.js';
import {getTileUrls, fixTileJSONCenter} from './utils.js';
export const serve_data = {
init: (options, repo) => {
const app = express().disable('x-powered-by');
app.get(
'/:id/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w.]+)',
(req, res, next) => {
app.get('/:id/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w.]+)', (req, res, next) => {
const item = repo[req.params.id];
if (!item) {
return res.sendStatus(404);
@@ -31,21 +29,13 @@ export const serve_data = {
if (format === options.pbfAlias) {
format = 'pbf';
}
if (
format !== tileJSONFormat &&
!(format === 'geojson' && tileJSONFormat === 'pbf')
) {
if (format !== tileJSONFormat &&
!(format === 'geojson' && tileJSONFormat === 'pbf')) {
return res.status(404).send('Invalid format');
}
if (
z < item.tileJSON.minzoom ||
0 ||
x < 0 ||
y < 0 ||
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
z > item.tileJSON.maxzoom ||
x >= Math.pow(2, z) ||
y >= Math.pow(2, z)
) {
x >= Math.pow(2, options.wgs84 ? z + 1 : z) || y >= Math.pow(2, z)) {
return res.status(404).send('Out of bounds');
}
item.source.getTile(z, x, y, (err, data, headers) => {
@@ -61,8 +51,8 @@ export const serve_data = {
return res.status(404).send('Not found');
} else {
if (tileJSONFormat === 'pbf') {
isGzipped =
data.slice(0, 2).indexOf(Buffer.from([0x1f, 0x8b])) === 0;
isGzipped = data.slice(0, 2).indexOf(
Buffer.from([0x1f, 0x8b])) === 0;
if (options.dataDecoratorFunc) {
if (isGzipped) {
data = zlib.unzipSync(data);
@@ -83,8 +73,8 @@ export const serve_data = {
const tile = new VectorTile(new Pbf(data));
const geojson = {
type: 'FeatureCollection',
features: [],
'type': 'FeatureCollection',
'features': []
};
for (const layerName in tile.layers) {
const layer = tile.layers[layerName];
@@ -110,8 +100,7 @@ export const serve_data = {
}
}
});
},
);
});
app.get('/:id.json', (req, res, next) => {
const item = repo[req.params.id];
@@ -119,16 +108,10 @@ export const serve_data = {
return res.sendStatus(404);
}
const info = clone(item.tileJSON);
info.tiles = getTileUrls(
req,
info.tiles,
`data/${req.params.id}`,
info.format,
item.publicUrl,
{
pbf: options.pbfAlias,
},
);
info.tiles = getTileUrls(req, info.tiles,
`data/${req.params.id}`, info.format, item.publicUrl, {
'pbf': options.pbfAlias
});
return res.send(info);
});
@@ -137,7 +120,7 @@ export const serve_data = {
add: (options, repo, params, id, publicUrl) => {
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
let tileJSON = {
tiles: params.domains || options.domains,
'tiles': params.domains || options.domains
};
const mbtilesFileStats = fs.statSync(mbtilesFile);
@@ -146,7 +129,7 @@ export const serve_data = {
}
let source;
const sourceInfoPromise = new Promise((resolve, reject) => {
source = new MBTiles(mbtilesFile + '?mode=ro', (err) => {
source = new MBTiles(mbtilesFile + '?mode=ro', err => {
if (err) {
reject(err);
return;
@@ -181,8 +164,8 @@ export const serve_data = {
repo[id] = {
tileJSON,
publicUrl,
source,
source
};
});
},
}
};