Convert to esm module syntax (#606)
* switch to esm module * Update package.json * change to maplibre package * fix tests * eslint * remove extra package updates * Delete package-lock.json * change 'fs' to 'node:fs' * put back node 10. without the package updates this still works * remove trailing commas * remove unassociated fix / formatting * remove unassociated fix * remove eslint from this PR * remove unassociated fix * lint * Merge remote-tracking branch 'upstream/master' into esm_update * fix mlgl * update maplibre-native to new version with arm64 * update minor version
This commit is contained in:
28
src/utils.js
28
src/utils.js
@@ -1,16 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
import path from 'path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const clone = require('clone');
|
||||
const glyphCompose = require('@mapbox/glyph-pbf-composite');
|
||||
import clone from 'clone';
|
||||
import glyphCompose from '@mapbox/glyph-pbf-composite';
|
||||
|
||||
|
||||
module.exports.getPublicUrl = (publicUrl, req) => publicUrl || `${req.protocol}://${req.headers.host}/`;
|
||||
|
||||
module.exports.getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
|
||||
export const getPublicUrl = (publicUrl, req) => publicUrl || `${req.protocol}://${req.headers.host}/`;
|
||||
|
||||
export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
|
||||
if (domains) {
|
||||
if (domains.constructor === String && domains.length > 0) {
|
||||
domains = domains.split(',');
|
||||
@@ -37,7 +36,6 @@ module.exports.getTileUrls = (req, domains, path, format, publicUrl, aliases) =>
|
||||
domains = [req.headers.host];
|
||||
}
|
||||
|
||||
const key = req.query.key;
|
||||
const queryParams = [];
|
||||
if (req.query.key) {
|
||||
queryParams.push(`key=${encodeURIComponent(req.query.key)}`);
|
||||
@@ -57,13 +55,13 @@ module.exports.getTileUrls = (req, domains, path, format, publicUrl, aliases) =>
|
||||
uris.push(`${req.protocol}://${domain}/${path}/{z}/{x}/{y}.${format}${query}`);
|
||||
}
|
||||
} else {
|
||||
uris.push(`${publicUrl}${path}/{z}/{x}/{y}.${format}${query}`)
|
||||
uris.push(`${publicUrl}${path}/{z}/{x}/{y}.${format}${query}`);
|
||||
}
|
||||
|
||||
return uris;
|
||||
};
|
||||
|
||||
module.exports.fixTileJSONCenter = tileJSON => {
|
||||
export const fixTileJSONCenter = (tileJSON) => {
|
||||
if (tileJSON.bounds && !tileJSON.center) {
|
||||
const fitWidth = 1024;
|
||||
const tiles = fitWidth / 256;
|
||||
@@ -71,8 +69,8 @@ module.exports.fixTileJSONCenter = tileJSON => {
|
||||
(tileJSON.bounds[0] + tileJSON.bounds[2]) / 2,
|
||||
(tileJSON.bounds[1] + tileJSON.bounds[3]) / 2,
|
||||
Math.round(
|
||||
-Math.log((tileJSON.bounds[2] - tileJSON.bounds[0]) / 360 / tiles) /
|
||||
Math.LN2
|
||||
-Math.log((tileJSON.bounds[2] - tileJSON.bounds[0]) / 360 / tiles) /
|
||||
Math.LN2
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -118,14 +116,14 @@ const getFontPbf = (allowedFonts, fontPath, name, range, fallbacks) => new Promi
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.getFontsPbf = (allowedFonts, fontPath, names, range, fallbacks) => {
|
||||
export const getFontsPbf = (allowedFonts, fontPath, names, range, fallbacks) => {
|
||||
const fonts = names.split(',');
|
||||
const queue = [];
|
||||
for (const font of fonts) {
|
||||
queue.push(
|
||||
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks))
|
||||
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks))
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.all(queue).then(values => glyphCompose.combine(values));
|
||||
return Promise.all(queue).then((values) => glyphCompose.combine(values));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user