add elevatppy lint:js:fix
This commit is contained in:
parent
f55a4791c2
commit
a6123d1b6f
4 changed files with 44 additions and 27 deletions
|
@ -249,9 +249,20 @@ export const serve_data = {
|
|||
if (fetchTile == null) return res.status(204).send();
|
||||
|
||||
let data = fetchTile.data;
|
||||
var param = { long: bbox[0], lat: bbox[1], encoding, format, tile_size: TILE_SIZE, z: zoom, x: xy[0], y: xy[1] };
|
||||
var param = {
|
||||
long: bbox[0],
|
||||
lat: bbox[1],
|
||||
encoding,
|
||||
format,
|
||||
tile_size: TILE_SIZE,
|
||||
z: zoom,
|
||||
x: xy[0],
|
||||
y: xy[1],
|
||||
};
|
||||
|
||||
res.status(200).send(await serve_rendered.getTerrainElevation(data, param));
|
||||
res
|
||||
.status(200)
|
||||
.send(await serve_rendered.getTerrainElevation(data, param));
|
||||
} catch (err) {
|
||||
return res
|
||||
.status(500)
|
||||
|
|
|
@ -6,5 +6,8 @@ export const serve_rendered = {
|
|||
init: (options, repo, programOpts) => {},
|
||||
add: (options, repo, params, id, programOpts, dataResolver) => {},
|
||||
remove: (repo, id) => {},
|
||||
getTerrainElevation: (data, param) => { param["elevation"] = "not supported in light"; return param; },
|
||||
getTerrainElevation: (data, param) => {
|
||||
param['elevation'] = 'not supported in light';
|
||||
return param;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1459,43 +1459,43 @@ export const serve_rendered = {
|
|||
delete repo[id];
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the elevation of terrain tile data by rendering it to a canvas image
|
||||
* @param {object} data `The background color (or empty string for transparent).
|
||||
* @param {object} format A sharp format.
|
||||
* @returns {object}
|
||||
*/
|
||||
getTerrainElevation: async function(data, param) {
|
||||
* @param {object} data The background color (or empty string for transparent).
|
||||
* @param {object} param Required parameters (coordinates e.g.)
|
||||
* @returns {object}
|
||||
*/
|
||||
getTerrainElevation: async function (data, param) {
|
||||
return await new Promise(async (resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.onload = async () => {
|
||||
const canvas = createCanvas(param["tile_size"], param["tile_size"]);
|
||||
const canvas = createCanvas(param['tile_size'], param['tile_size']);
|
||||
const context = canvas.getContext('2d');
|
||||
context.drawImage(image, 0, 0);
|
||||
|
||||
// calculate pixel coordinate of tile,
|
||||
// see https://developers.google.com/maps/documentation/javascript/examples/map-coordinates
|
||||
let siny = Math.sin((param["lat"] * Math.PI) / 180);
|
||||
let siny = Math.sin((param['lat'] * Math.PI) / 180);
|
||||
// Truncating to 0.9999 effectively limits latitude to 89.189. This is
|
||||
// about a third of a tile past the edge of the world tile.
|
||||
siny = Math.min(Math.max(siny, -0.9999), 0.9999);
|
||||
const xWorld = param["tile_size"] * (0.5 + param["long"] / 360);
|
||||
const xWorld = param['tile_size'] * (0.5 + param['long'] / 360);
|
||||
const yWorld =
|
||||
param["tile_size"] *
|
||||
param['tile_size'] *
|
||||
(0.5 - Math.log((1 + siny) / (1 - siny)) / (4 * Math.PI));
|
||||
|
||||
const scale = 1 << param["z"];
|
||||
const scale = 1 << param['z'];
|
||||
|
||||
const xTile = Math.floor((xWorld * scale) / param["tile_size"]);
|
||||
const yTile = Math.floor((yWorld * scale) / param["tile_size"]);
|
||||
const xTile = Math.floor((xWorld * scale) / param['tile_size']);
|
||||
const yTile = Math.floor((yWorld * scale) / param['tile_size']);
|
||||
|
||||
const xPixel = Math.floor(xWorld * scale) - xTile * param["tile_size"];
|
||||
const yPixel = Math.floor(yWorld * scale) - yTile * param["tile_size"];
|
||||
const xPixel = Math.floor(xWorld * scale) - xTile * param['tile_size'];
|
||||
const yPixel = Math.floor(yWorld * scale) - yTile * param['tile_size'];
|
||||
if (
|
||||
xPixel < 0 ||
|
||||
yPixel < 0 ||
|
||||
xPixel >= param["tile_size"] ||
|
||||
yPixel >= param["tile_size"]
|
||||
xPixel >= param['tile_size'] ||
|
||||
yPixel >= param['tile_size']
|
||||
) {
|
||||
return reject('Out of bounds Pixel');
|
||||
}
|
||||
|
@ -1504,21 +1504,21 @@ export const serve_rendered = {
|
|||
const green = imgdata.data[1];
|
||||
const blue = imgdata.data[2];
|
||||
let elevation;
|
||||
if (param["encoding"] === 'mapbox') {
|
||||
if (param['encoding'] === 'mapbox') {
|
||||
elevation = -10000 + (red * 256 * 256 + green * 256 + blue) * 0.1;
|
||||
} else if (param["encoding"] === 'terrarium') {
|
||||
} else if (param['encoding'] === 'terrarium') {
|
||||
elevation = red * 256 + green + blue / 256 - 32768;
|
||||
} else {
|
||||
elevation = 'invalid encoding';
|
||||
}
|
||||
param["elevation"] = elevation;
|
||||
param["red"] = red;
|
||||
param["green"] = green;
|
||||
param["blue"] = blue;
|
||||
param['elevation'] = elevation;
|
||||
param['red'] = red;
|
||||
param['green'] = green;
|
||||
param['blue'] = blue;
|
||||
resolve(param);
|
||||
};
|
||||
image.onerror = (err) => reject(err);
|
||||
if (param["format"] === 'webp') {
|
||||
if (param['format'] === 'webp') {
|
||||
try {
|
||||
const img = await sharp(data).toFormat('png').toBuffer();
|
||||
image.src = img;
|
||||
|
|
|
@ -14,6 +14,9 @@ export const allowedTileSizes = allowedOptions(['256', '512']);
|
|||
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export function isLight() {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
|
Loading…
Reference in a new issue