Skip to content

Commit

Permalink
TMS tiles path
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Sep 28, 2024
1 parent b34da10 commit dfe4cd4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
}

Expand Down
38 changes: 16 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ const MAX_ZOOM = 24
let basePath: string
const chartTilesPath = 'chart-tiles'
const chartStylesPath = 'chart-styles'
let chartPaths: Array<string>
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
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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[]) =>
Expand Down

0 comments on commit dfe4cd4

Please sign in to comment.