From dfe4cd4f78276f8f70f9bc5a57e0c7c5b9196aa9 Mon Sep 17 00:00:00 2001 From: panaaj <38519157+panaaj@users.noreply.github.com> Date: Sat, 28 Sep 2024 15:51:53 +0930 Subject: [PATCH] TMS tiles path --- src/charts.ts | 4 ++-- src/index.ts | 38 ++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/charts.ts b/src/charts.ts index c5c4c3e..2c5e8d8 100644 --- a/src/charts.ts +++ b/src/charts.ts @@ -166,11 +166,11 @@ function directoryToMapInfo(file: string, identifier: string) { ;(info._fileFormat = 'directory'), (info._filePath = file), (info.v1 = { - tilemapUrl: `~basePath~/${identifier}/{z}/{x}/{y}`, + tilemapUrl: `~basePath~/~tilePath~/${identifier}/{z}/{x}/{y}`, chartLayers: [] }) info.v2 = { - url: `~basePath~/${identifier}/{z}/{x}/{y}`, + url: `~basePath~/~tilePath~/${identifier}/{z}/{x}/{y}`, layers: [] } diff --git a/src/index.ts b/src/index.ts index 87e8d28..f523959 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,14 +39,11 @@ const MAX_ZOOM = 24 let basePath: string const chartTilesPath = 'chart-tiles' const chartStylesPath = 'chart-styles' +let chartPaths: Array +let onlineProviders = {} module.exports = (app: ChartProviderApp): Plugin => { let chartProviders: { [key: string]: ChartProvider } = {} - let pluginStarted = false - let props: Config = { - chartPaths: [], - onlineChartProviders: [] - } const configBasePath = app.config.configPath const defaultChartsPath = path.join(configBasePath, '/charts') const serverMajorVersion = app.config.version @@ -158,8 +155,8 @@ module.exports = (app: ChartProviderApp): Plugin => { name: 'Signal K Charts', schema: () => CONFIG_SCHEMA, uiSchema: () => CONFIG_UISCHEMA, - start: (settings: object) => { - return doStartup(settings as Config) // return required for tests + start: (config: object) => { + return doStartup(config as Config) // return required for tests }, stop: () => { app.setPluginStatus('stopped') @@ -169,29 +166,19 @@ module.exports = (app: ChartProviderApp): Plugin => { const doStartup = (config: Config) => { app.debug('** loaded config: ', config) - // Do not register routes if plugin has been started once already - pluginStarted === false && registerRoutes() - pluginStarted = true + registerRoutes() basePath = `${app.config.ssl ? 'https' : 'http'}://localhost:${ 'getExternalPort' in app.config ? app.config.getExternalPort() : 3000 }` app.debug('**basePath**', basePath) app.setPluginStatus('Started') - return loadCharts(config) - } - - // Load chart files - const loadCharts = (config: Config) => { - props = { ...config } - - const chartPaths = _.isEmpty(props.chartPaths) + chartPaths = _.isEmpty(config.chartPaths) ? [defaultChartsPath] - : resolveUniqueChartPaths(props.chartPaths, configBasePath) + : resolveUniqueChartPaths(config.chartPaths, configBasePath) - // load from config - const onlineProviders = _.reduce( - props.onlineChartProviders, + onlineProviders = _.reduce( + config.onlineChartProviders, (result: { [key: string]: object }, data) => { const provider = convertOnlineProviderConfig(data) result[provider.identifier] = provider @@ -206,6 +193,13 @@ module.exports = (app: ChartProviderApp): Plugin => { )}, online charts: ${Object.keys(onlineProviders).length}` ) + return loadCharts() + } + + // Load chart files + const loadCharts = () => { + app.debug(`Loading Charts....`) + const loadProviders = bluebird .mapSeries(chartPaths, (chartPath: string) => findCharts(chartPath)) .then((list: ChartProvider[]) =>