Remove obsolete old code

This commit is contained in:
Petr Sloup 2019-12-30 17:00:23 +01:00
parent cdc7803ad8
commit 515c295898
3 changed files with 3 additions and 41 deletions

View file

@ -10,12 +10,6 @@ const MBTiles = require('@mapbox/mbtiles');
const Pbf = require('pbf'); const Pbf = require('pbf');
const VectorTile = require('@mapbox/vector-tile').VectorTile; const VectorTile = require('@mapbox/vector-tile').VectorTile;
let tileshrinkGl;
try {
tileshrinkGl = require('tileshrink-gl');
global.addStyleParam = true;
} catch (e) {}
const utils = require('./utils'); const utils = require('./utils');
module.exports = (options, repo, params, id, styles, publicUrl) => { module.exports = (options, repo, params, id, styles, publicUrl) => {
@ -26,8 +20,6 @@ module.exports = (options, repo, params, id, styles, publicUrl) => {
'tiles': params.domains || options.domains 'tiles': params.domains || options.domains
}; };
const shrinkers = {};
repo[id] = tileJSON; repo[id] = tileJSON;
const mbtilesFileStats = fs.statSync(mbtilesFile); const mbtilesFileStats = fs.statSync(mbtilesFile);
@ -101,32 +93,6 @@ module.exports = (options, repo, params, id, styles, publicUrl) => {
if (tileJSON['format'] === 'pbf') { if (tileJSON['format'] === 'pbf') {
isGzipped = data.slice(0, 2).indexOf( isGzipped = data.slice(0, 2).indexOf(
new Buffer([0x1f, 0x8b])) === 0; new Buffer([0x1f, 0x8b])) === 0;
const style = req.query.style;
if (style && tileshrinkGl) {
if (!shrinkers[style]) {
const styleJSON = styles[style];
if (styleJSON) {
let sourceName = null;
for (let sourceName_ in styleJSON.sources) {
const source = styleJSON.sources[sourceName_];
if (source &&
source.type === 'vector' &&
source.url.endsWith(`/${id}.json`)) {
sourceName = sourceName_;
}
}
shrinkers[style] = tileshrinkGl.createPBFShrinker(styleJSON, sourceName);
}
}
if (shrinkers[style]) {
if (isGzipped) {
data = zlib.unzipSync(data);
isGzipped = false;
}
data = shrinkers[style](data, z, tileJSON.maxzoom);
//console.log(shrinkers[style].getStats());
}
}
if (options.dataDecoratorFunc) { if (options.dataDecoratorFunc) {
if (isGzipped) { if (isGzipped) {
data = zlib.unzipSync(data); data = zlib.unzipSync(data);

View file

@ -1,6 +1,5 @@
'use strict'; 'use strict';
const clone = require('clone');
const express = require('express'); const express = require('express');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');

View file

@ -64,14 +64,11 @@ module.exports = (options, repo, params, id, publicUrl, reportTiles, reportFont)
repo[id] = styleJSON; repo[id] = styleJSON;
app.get(`/${id}/style.json`, (req, res, next) => { app.get(`/${id}/style.json`, (req, res, next) => {
const fixUrl = (url, opt_nokey, opt_nostyle) => { const fixUrl = (url, opt_nokey) => {
if (!url || (typeof url !== 'string') || url.indexOf('local://') !== 0) { if (!url || (typeof url !== 'string') || url.indexOf('local://') !== 0) {
return url; return url;
} }
const queryParams = []; const queryParams = [];
if (!opt_nostyle && global.addStyleParam) {
queryParams.push(`style=${id}`);
}
if (!opt_nokey && req.query.key) { if (!opt_nokey && req.query.key) {
queryParams.unshift(`key=${req.query.key}`); queryParams.unshift(`key=${req.query.key}`);
} }
@ -90,10 +87,10 @@ module.exports = (options, repo, params, id, publicUrl, reportTiles, reportFont)
} }
// mapbox-gl-js viewer cannot handle sprite urls with query // mapbox-gl-js viewer cannot handle sprite urls with query
if (styleJSON_.sprite) { if (styleJSON_.sprite) {
styleJSON_.sprite = fixUrl(styleJSON_.sprite, true, true); styleJSON_.sprite = fixUrl(styleJSON_.sprite, true);
} }
if (styleJSON_.glyphs) { if (styleJSON_.glyphs) {
styleJSON_.glyphs = fixUrl(styleJSON_.glyphs, false, true); styleJSON_.glyphs = fixUrl(styleJSON_.glyphs, false);
} }
return res.send(styleJSON_); return res.send(styleJSON_);
}); });