style: fix lint issues in code 🕺
Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
parent
50201f0a99
commit
f61e333b29
9 changed files with 9977 additions and 184 deletions
31
package.json
31
package.json
|
|
@ -5,16 +5,17 @@
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"bin": "src/main.js",
|
"bin": "src/main.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/maptiler/tileserver-gl.git"
|
|
||||||
},
|
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.15.0 <17"
|
"node": ">=14.15.0 <17"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha test/**.js --timeout 10000",
|
"test": "mocha test/**.js --timeout 10000",
|
||||||
|
"lint:yml": "yamllint --schema=CORE_SCHEMA *.{yml,yaml}",
|
||||||
|
"lint:prettier": "prettier --check \"{,!(node_modules|dist|static)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore",
|
||||||
|
"lint:prettier:fix": "prettier --write \"{,!(node_modules|dist|static)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore",
|
||||||
|
"lint": "npm run lint:prettier",
|
||||||
|
"lintfix": "npm run lint:prettier:fix",
|
||||||
"docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)"
|
"docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
@ -45,6 +46,24 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "4.3.6",
|
"chai": "4.3.6",
|
||||||
"mocha": "^10.0.0",
|
"mocha": "^10.0.0",
|
||||||
"supertest": "^6.2.4"
|
"prettier": "^2.7.1",
|
||||||
}
|
"should": "^13.2.3",
|
||||||
|
"supertest": "^6.2.4",
|
||||||
|
"yaml-lint": "^1.7.0"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"url": "git+https://github.com/maptiler/tileserver-gl.git",
|
||||||
|
"type": "git"
|
||||||
|
},
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Vinayak Kulkarni",
|
||||||
|
"email": "inbox.vinayak@gmail.com",
|
||||||
|
"url": "https://vinayakkulkarni.dev"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/maptiler/tileserver-gl/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/maptiler/tileserver-gl#readme"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
prettier.config.cjs
Normal file
13
prettier.config.cjs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
module.exports = {
|
||||||
|
$schema: 'http://json.schemastore.org/prettierrc',
|
||||||
|
semi: true,
|
||||||
|
arrowParens: 'always',
|
||||||
|
singleQuote: true,
|
||||||
|
trailingComma: 'all',
|
||||||
|
bracketSpacing: true,
|
||||||
|
htmlWhitespaceSensitivity: 'css',
|
||||||
|
insertPragma: false,
|
||||||
|
tabWidth: 2,
|
||||||
|
useTabs: false,
|
||||||
|
endOfLine: 'lf',
|
||||||
|
};
|
||||||
|
|
@ -1,162 +1,162 @@
|
||||||
(function(window) {
|
(function (window) {
|
||||||
var HAS_HASHCHANGE = (function() {
|
var HAS_HASHCHANGE = (function () {
|
||||||
var doc_mode = window.documentMode;
|
var doc_mode = window.documentMode;
|
||||||
return ('onhashchange' in window) &&
|
return 'onhashchange' in window && (doc_mode === undefined || doc_mode > 7);
|
||||||
(doc_mode === undefined || doc_mode > 7);
|
})();
|
||||||
})();
|
|
||||||
|
|
||||||
L.Hash = function(map) {
|
L.Hash = function (map) {
|
||||||
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
||||||
|
|
||||||
if (map) {
|
if (map) {
|
||||||
this.init(map);
|
this.init(map);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
L.Hash.parseHash = function(hash) {
|
L.Hash.parseHash = function (hash) {
|
||||||
if(hash.indexOf('#') === 0) {
|
if (hash.indexOf('#') === 0) {
|
||||||
hash = hash.substr(1);
|
hash = hash.substr(1);
|
||||||
}
|
}
|
||||||
var args = hash.split("/");
|
var args = hash.split('/');
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
var zoom = parseInt(args[0], 10),
|
var zoom = parseInt(args[0], 10),
|
||||||
lat = parseFloat(args[1]),
|
lat = parseFloat(args[1]),
|
||||||
lon = parseFloat(args[2]);
|
lon = parseFloat(args[2]);
|
||||||
if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
|
if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
center: new L.LatLng(lat, lon),
|
center: new L.LatLng(lat, lon),
|
||||||
zoom: zoom
|
zoom: zoom,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
L.Hash.formatHash = function(map) {
|
(L.Hash.formatHash = function (map) {
|
||||||
var center = map.getCenter(),
|
var center = map.getCenter(),
|
||||||
zoom = map.getZoom(),
|
zoom = map.getZoom(),
|
||||||
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
|
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
|
||||||
|
|
||||||
return "#" + [zoom,
|
return (
|
||||||
center.lat.toFixed(precision),
|
'#' +
|
||||||
center.lng.toFixed(precision)
|
[zoom, center.lat.toFixed(precision), center.lng.toFixed(precision)].join(
|
||||||
].join("/");
|
'/',
|
||||||
},
|
)
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
(L.Hash.prototype = {
|
||||||
|
map: null,
|
||||||
|
lastHash: null,
|
||||||
|
|
||||||
L.Hash.prototype = {
|
parseHash: L.Hash.parseHash,
|
||||||
map: null,
|
formatHash: L.Hash.formatHash,
|
||||||
lastHash: null,
|
|
||||||
|
|
||||||
parseHash: L.Hash.parseHash,
|
init: function (map) {
|
||||||
formatHash: L.Hash.formatHash,
|
this.map = map;
|
||||||
|
|
||||||
init: function(map) {
|
// reset the hash
|
||||||
this.map = map;
|
this.lastHash = null;
|
||||||
|
this.onHashChange();
|
||||||
|
|
||||||
// reset the hash
|
if (!this.isListening) {
|
||||||
this.lastHash = null;
|
this.startListening();
|
||||||
this.onHashChange();
|
}
|
||||||
|
},
|
||||||
|
|
||||||
if (!this.isListening) {
|
removeFrom: function (map) {
|
||||||
this.startListening();
|
if (this.changeTimeout) {
|
||||||
}
|
clearTimeout(this.changeTimeout);
|
||||||
},
|
}
|
||||||
|
|
||||||
removeFrom: function(map) {
|
if (this.isListening) {
|
||||||
if (this.changeTimeout) {
|
this.stopListening();
|
||||||
clearTimeout(this.changeTimeout);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isListening) {
|
this.map = null;
|
||||||
this.stopListening();
|
},
|
||||||
}
|
|
||||||
|
|
||||||
this.map = null;
|
onMapMove: function () {
|
||||||
},
|
// bail if we're moving the map (updating from a hash),
|
||||||
|
// or if the map is not yet loaded
|
||||||
|
|
||||||
onMapMove: function() {
|
if (this.movingMap || !this.map._loaded) {
|
||||||
// bail if we're moving the map (updating from a hash),
|
return false;
|
||||||
// or if the map is not yet loaded
|
}
|
||||||
|
|
||||||
if (this.movingMap || !this.map._loaded) {
|
var hash = this.formatHash(this.map);
|
||||||
return false;
|
if (this.lastHash != hash) {
|
||||||
}
|
location.replace(hash);
|
||||||
|
this.lastHash = hash;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
var hash = this.formatHash(this.map);
|
movingMap: false,
|
||||||
if (this.lastHash != hash) {
|
update: function () {
|
||||||
location.replace(hash);
|
var hash = location.hash;
|
||||||
this.lastHash = hash;
|
if (hash === this.lastHash) {
|
||||||
}
|
return;
|
||||||
},
|
}
|
||||||
|
var parsed = this.parseHash(hash);
|
||||||
|
if (parsed) {
|
||||||
|
this.movingMap = true;
|
||||||
|
|
||||||
movingMap: false,
|
this.map.setView(parsed.center, parsed.zoom);
|
||||||
update: function() {
|
|
||||||
var hash = location.hash;
|
|
||||||
if (hash === this.lastHash) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var parsed = this.parseHash(hash);
|
|
||||||
if (parsed) {
|
|
||||||
this.movingMap = true;
|
|
||||||
|
|
||||||
this.map.setView(parsed.center, parsed.zoom);
|
this.movingMap = false;
|
||||||
|
} else {
|
||||||
|
this.onMapMove(this.map);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
this.movingMap = false;
|
// defer hash change updates every 100ms
|
||||||
} else {
|
changeDefer: 100,
|
||||||
this.onMapMove(this.map);
|
changeTimeout: null,
|
||||||
}
|
onHashChange: function () {
|
||||||
},
|
// throttle calls to update() so that they only happen every
|
||||||
|
// `changeDefer` ms
|
||||||
|
if (!this.changeTimeout) {
|
||||||
|
var that = this;
|
||||||
|
this.changeTimeout = setTimeout(function () {
|
||||||
|
that.update();
|
||||||
|
that.changeTimeout = null;
|
||||||
|
}, this.changeDefer);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// defer hash change updates every 100ms
|
isListening: false,
|
||||||
changeDefer: 100,
|
hashChangeInterval: null,
|
||||||
changeTimeout: null,
|
startListening: function () {
|
||||||
onHashChange: function() {
|
this.map.on('moveend', this.onMapMove, this);
|
||||||
// throttle calls to update() so that they only happen every
|
|
||||||
// `changeDefer` ms
|
|
||||||
if (!this.changeTimeout) {
|
|
||||||
var that = this;
|
|
||||||
this.changeTimeout = setTimeout(function() {
|
|
||||||
that.update();
|
|
||||||
that.changeTimeout = null;
|
|
||||||
}, this.changeDefer);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
isListening: false,
|
if (HAS_HASHCHANGE) {
|
||||||
hashChangeInterval: null,
|
L.DomEvent.addListener(window, 'hashchange', this.onHashChange);
|
||||||
startListening: function() {
|
} else {
|
||||||
this.map.on("moveend", this.onMapMove, this);
|
clearInterval(this.hashChangeInterval);
|
||||||
|
this.hashChangeInterval = setInterval(this.onHashChange, 50);
|
||||||
|
}
|
||||||
|
this.isListening = true;
|
||||||
|
},
|
||||||
|
|
||||||
if (HAS_HASHCHANGE) {
|
stopListening: function () {
|
||||||
L.DomEvent.addListener(window, "hashchange", this.onHashChange);
|
this.map.off('moveend', this.onMapMove, this);
|
||||||
} else {
|
|
||||||
clearInterval(this.hashChangeInterval);
|
|
||||||
this.hashChangeInterval = setInterval(this.onHashChange, 50);
|
|
||||||
}
|
|
||||||
this.isListening = true;
|
|
||||||
},
|
|
||||||
|
|
||||||
stopListening: function() {
|
if (HAS_HASHCHANGE) {
|
||||||
this.map.off("moveend", this.onMapMove, this);
|
L.DomEvent.removeListener(window, 'hashchange', this.onHashChange);
|
||||||
|
} else {
|
||||||
if (HAS_HASHCHANGE) {
|
clearInterval(this.hashChangeInterval);
|
||||||
L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
|
}
|
||||||
} else {
|
this.isListening = false;
|
||||||
clearInterval(this.hashChangeInterval);
|
},
|
||||||
}
|
});
|
||||||
this.isListening = false;
|
L.hash = function (map) {
|
||||||
}
|
return new L.Hash(map);
|
||||||
};
|
};
|
||||||
L.hash = function(map) {
|
L.Map.prototype.addHash = function () {
|
||||||
return new L.Hash(map);
|
this._hash = L.hash(this);
|
||||||
};
|
};
|
||||||
L.Map.prototype.addHash = function() {
|
L.Map.prototype.removeHash = function () {
|
||||||
this._hash = L.hash(this);
|
this._hash.removeFrom();
|
||||||
};
|
};
|
||||||
L.Map.prototype.removeHash = function() {
|
|
||||||
this._hash.removeFrom();
|
|
||||||
};
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -26,7 +26,8 @@ const __dirname = path.dirname(__filename);
|
||||||
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8'))
|
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8'))
|
||||||
|
|
||||||
packageJson.name += '-light';
|
packageJson.name += '-light';
|
||||||
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
|
packageJson.description =
|
||||||
|
'Map tile server for JSON GL styles - serving vector tiles';
|
||||||
delete packageJson.dependencies['canvas'];
|
delete packageJson.dependencies['canvas'];
|
||||||
delete packageJson.dependencies['@maplibre/maplibre-gl-native'];
|
delete packageJson.dependencies['@maplibre/maplibre-gl-native'];
|
||||||
delete packageJson.dependencies['sharp'];
|
delete packageJson.dependencies['sharp'];
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,19 @@ export const serve_data = {
|
||||||
}
|
}
|
||||||
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
||||||
z > item.tileJSON.maxzoom ||
|
z > item.tileJSON.maxzoom ||
|
||||||
x >= Math.pow(2, z) || y >= Math.pow(2, z)) {
|
x >= Math.pow(2, z) ||
|
||||||
return res.status(404).send('Out of bounds');
|
y >= Math.pow(2, z)
|
||||||
}
|
) {
|
||||||
item.source.getTile(z, x, y, (err, data, headers) => {
|
return res.status(404).send('Out of bounds');
|
||||||
let isGzipped;
|
}
|
||||||
if (err) {
|
item.source.getTile(z, x, y, (err, data, headers) => {
|
||||||
if (/does not exist/.test(err.message)) {
|
let isGzipped;
|
||||||
return res.status(204).send();
|
if (err) {
|
||||||
|
if (/does not exist/.test(err.message)) {
|
||||||
|
return res.status(204).send();
|
||||||
|
} else {
|
||||||
|
return res.status(500).send(err.message);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return res.status(500).send(err.message);
|
return res.status(500).send(err.message);
|
||||||
}
|
}
|
||||||
|
|
@ -58,13 +63,6 @@ export const serve_data = {
|
||||||
data = zlib.unzipSync(data);
|
data = zlib.unzipSync(data);
|
||||||
isGzipped = false;
|
isGzipped = false;
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
@ -84,23 +82,23 @@ export const serve_data = {
|
||||||
featureGeoJSON.properties.layer = layerName;
|
featureGeoJSON.properties.layer = layerName;
|
||||||
geojson.features.push(featureGeoJSON);
|
geojson.features.push(featureGeoJSON);
|
||||||
}
|
}
|
||||||
|
data = JSON.stringify(geojson);
|
||||||
}
|
}
|
||||||
data = JSON.stringify(geojson);
|
delete headers['ETag']; // do not trust the tile ETag -- regenerate
|
||||||
}
|
headers['Content-Encoding'] = 'gzip';
|
||||||
delete headers['ETag']; // do not trust the tile ETag -- regenerate
|
res.set(headers);
|
||||||
headers['Content-Encoding'] = 'gzip';
|
|
||||||
res.set(headers);
|
|
||||||
|
|
||||||
if (!isGzipped) {
|
if (!isGzipped) {
|
||||||
data = zlib.gzipSync(data);
|
data = zlib.gzipSync(data);
|
||||||
isGzipped = true;
|
isGzipped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).send(data);
|
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];
|
||||||
|
|
@ -120,7 +118,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);
|
||||||
|
|
@ -167,5 +165,5 @@ export const serve_data = {
|
||||||
source
|
source
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue