From c94bd22b8ec8b953e8fbe14f973c8e384cebb55d Mon Sep 17 00:00:00 2001 From: Miko Date: Sun, 13 Oct 2024 22:54:31 +0200 Subject: [PATCH] applied lint:js:fix --- src/serve_data.js | 38 +++++++++++++++++++++++++++----------- src/server.js | 18 ++++++++++++------ src/utils.js | 4 ++-- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/serve_data.js b/src/serve_data.js index 2c63676..38131db 100644 --- a/src/serve_data.js +++ b/src/serve_data.js @@ -174,8 +174,8 @@ export const serve_data = { } if ( - item.source._info.encoding != "terrarium" && - item.source._info.encoding != "mapbox" + item.source._info.encoding != 'terrarium' && + item.source._info.encoding != 'mapbox' ) { return res.status(404).send('Missing encoding'); } @@ -263,20 +263,36 @@ export const serve_data = { var green = imgdata.data[index + 1]; var blue = imgdata.data[index + 2]; let elevation; - if (item.source._info.encoding == "mapbox") { - elevation = -10000 + ((red * 256 * 256 + green * 256 + blue) * 0.1); - } else if (item.source._info.encoding == "terrarium") { - elevation = (red * 256 + green + blue / 256) - 32768; + if (item.source._info.encoding == 'mapbox') { + elevation = + -10000 + (red * 256 * 256 + green * 256 + blue) * 0.1; + } else if (item.source._info.encoding == 'terrarium') { + elevation = red * 256 + green + blue / 256 - 32768; } else { - elevation = "invalid encoding"; + elevation = 'invalid encoding'; } //"index": index, "length": imgdata.data.length, - return res.status(200).send({ "z": z, "x": xy[0], "y": xy[1], "red": red, "green": green, "blue": blue, "latitude": tileCenter[0], "longitude": tileCenter[1], "elevation": elevation }); + return res.status(200).send({ + z: z, + x: xy[0], + y: xy[1], + red: red, + green: green, + blue: blue, + latitude: tileCenter[0], + longitude: tileCenter[1], + elevation: elevation, + }); + }; + image.onerror = (err) => { + return res + .status(500) + .header('Content-Type', 'text/plain') + .send(err.message); }; - image.onerror = err => { return res.status(500).header('Content-Type', 'text/plain').send(err.message); } //image.onerror = err => { return res.status(200).header('Content-Type', 'image/webp').send(data); } - if (item.source._info.format == "webp") { + if (item.source._info.format == 'webp') { const img = await sharp(data).toFormat('png').toBuffer(); image.src = img; } else { @@ -372,7 +388,7 @@ export const serve_data = { const mbw = await openMbTilesWrapper(inputFile); const info = await mbw.getInfo(); source = mbw.getMbTiles(); - info["encoding"] = params["encoding"]; + info['encoding'] = params['encoding']; tileJSON['name'] = id; tileJSON['format'] = 'pbf'; diff --git a/src/server.js b/src/server.js index 2e48460..ce51e9a 100644 --- a/src/server.js +++ b/src/server.js @@ -513,13 +513,16 @@ function start(opts) { data.is_vector = tileJSON.format === 'pbf'; if (!data.is_vector) { - if ((tileJSON.encoding === 'terrarium' || tileJSON.encoding === 'mapbox')) { + if ( + tileJSON.encoding === 'terrarium' || + tileJSON.encoding === 'mapbox' + ) { data.elevation_link = getTileUrls( req, tileJSON.tiles, - `data/${id}/elevation` + `data/${id}/elevation`, )[0]; - }; + } if (center) { const centerPx = mercator.px([center[0], center[1]], center[2]); data.thumbnail = `${center[2]}/${Math.floor(centerPx[0] / 256)}/${Math.floor(centerPx[1] / 256)}.${tileJSON.format}`; @@ -610,13 +613,16 @@ function start(opts) { if (!data) { return null; } - const is_terrain = ((data.tileJSON.encoding === 'terrarium' || data.tileJSON.encoding === 'mapbox') && (preview === "preview")); + const is_terrain = + (data.tileJSON.encoding === 'terrarium' || + data.tileJSON.encoding === 'mapbox') && + preview === 'preview'; return { ...data, id, - use_maplibre: (data.tileJSON.format === 'pbf' || is_terrain), + use_maplibre: data.tileJSON.format === 'pbf' || is_terrain, is_terrain: is_terrain, - is_terrainrgb: (data.tileJSON.encoding === "mapbox"), + is_terrainrgb: data.tileJSON.encoding === 'mapbox', terrain_encoding: data.tileJSON.encoding, }; }); diff --git a/src/utils.js b/src/utils.js index fe39923..4f976f5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -119,10 +119,10 @@ export const getTileUrls = ( tileParams = `${tileSize}/{z}/{x}/{y}`; } - if (format && format != "") { + if (format && format != '') { format = `.${format}`; } else { - format = ""; + format = ''; } const uris = [];