Merge branch 'master' into refactor4
This commit is contained in:
commit
ee602acc4c
2 changed files with 28 additions and 42 deletions
|
@ -1,12 +1,24 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// SECTION START
|
||||||
|
//
|
||||||
|
// The order of the two imports below is important.
|
||||||
|
// For an unknown reason, if the order is reversed, rendering can crash.
|
||||||
|
// This happens on ARM:
|
||||||
|
// > terminate called after throwing an instance of 'std::runtime_error'
|
||||||
|
// > what(): Cannot read GLX extensions.
|
||||||
|
import 'canvas';
|
||||||
|
import '@maplibre/maplibre-gl-native';
|
||||||
|
//
|
||||||
|
// SECTION END
|
||||||
|
|
||||||
import advancedPool from 'advanced-pool';
|
import advancedPool from 'advanced-pool';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
import zlib from 'zlib';
|
import zlib from 'zlib';
|
||||||
import sharp from 'sharp'; // sharp has to be required before node-canvas on linux but after it on windows. see https://github.com/lovell/sharp/issues/371
|
import sharp from 'sharp';
|
||||||
import clone from 'clone';
|
import clone from 'clone';
|
||||||
import Color from 'color';
|
import Color from 'color';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
@ -428,24 +440,9 @@ const respondImage = (
|
||||||
return res.status(500).header('Content-Type', 'text/plain').send(err);
|
return res.status(500).header('Content-Type', 'text/plain').send(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix semi-transparent outlines on raw, premultiplied input
|
|
||||||
// https://github.com/maptiler/tileserver-gl/issues/350#issuecomment-477857040
|
|
||||||
for (let i = 0; i < data.length; i += 4) {
|
|
||||||
const alpha = data[i + 3];
|
|
||||||
const norm = alpha / 255;
|
|
||||||
if (alpha === 0) {
|
|
||||||
data[i] = 0;
|
|
||||||
data[i + 1] = 0;
|
|
||||||
data[i + 2] = 0;
|
|
||||||
} else {
|
|
||||||
data[i] = data[i] / norm;
|
|
||||||
data[i + 1] = data[i + 1] / norm;
|
|
||||||
data[i + 2] = data[i + 2] / norm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const image = sharp(data, {
|
const image = sharp(data, {
|
||||||
raw: {
|
raw: {
|
||||||
|
premultiplied: true,
|
||||||
width: params.width * scale,
|
width: params.width * scale,
|
||||||
height: params.height * scale,
|
height: params.height * scale,
|
||||||
channels: 4,
|
channels: 4,
|
||||||
|
|
39
src/utils.js
39
src/utils.js
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'node:fs';
|
import fsPromises from 'fs/promises';
|
||||||
|
import fs, { existsSync } from 'node:fs';
|
||||||
import clone from 'clone';
|
import clone from 'clone';
|
||||||
import glyphCompose from '@mapbox/glyph-pbf-composite';
|
import glyphCompose from '@mapbox/glyph-pbf-composite';
|
||||||
|
|
||||||
|
@ -166,30 +167,18 @@ export const getFontsPbf = async (
|
||||||
|
|
||||||
export const listFonts = async (fontPath) => {
|
export const listFonts = async (fontPath) => {
|
||||||
const existingFonts = {};
|
const existingFonts = {};
|
||||||
const fontListingPromise = new Promise((resolve, reject) => {
|
|
||||||
fs.readdir(fontPath, (err, files) => {
|
const files = await fsPromises.readdir(fontPath);
|
||||||
if (err) {
|
for (const file of files) {
|
||||||
reject(err);
|
const stats = await fsPromises.stat(path.join(fontPath, file));
|
||||||
return;
|
if (
|
||||||
}
|
stats.isDirectory() &&
|
||||||
for (const file of files) {
|
existsSync(path.join(fontPath, file, '0-255.pbf'))
|
||||||
fs.stat(path.join(fontPath, file), (err, stats) => {
|
) {
|
||||||
if (err) {
|
existingFonts[path.basename(file)] = true;
|
||||||
reject(err);
|
}
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
if (
|
|
||||||
stats.isDirectory() &&
|
|
||||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))
|
|
||||||
) {
|
|
||||||
existingFonts[path.basename(file)] = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
await fontListingPromise;
|
|
||||||
return existingFonts;
|
return existingFonts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue