tileserver-gl-light 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ # Read the Docs configuration file for Sphinx projects
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ # Required
5
+ version: 2
6
+
7
+ # Set the version of Python and other tools you might need
8
+ build:
9
+ os: ubuntu-22.04
10
+ tools:
11
+ python: "3.11"
12
+
13
+ # Build documentation in the doc/help/ directory with Sphinx
14
+ sphinx:
15
+ configuration: docs/conf.py
16
+
17
+ formats:
18
+ - pdf
package/LICENSE.md CHANGED
@@ -1416,6 +1416,38 @@ modification, are permitted provided that the following conditions are met:
1416
1416
  this list of conditions and the following disclaimer in the documentation
1417
1417
  and/or other materials provided with the distribution.
1418
1418
 
1419
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1420
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1421
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1422
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1423
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1424
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1425
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1426
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1427
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1428
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1429
+ ```
1430
+ ---
1431
+
1432
+ ### [PMTiles](https://github.com/protomaps/pmtiles)
1433
+ ```
1434
+ BSD 3-Clause License
1435
+ Copyright 2021 Protomaps LLC
1436
+
1437
+ Redistribution and use in source and binary forms, with or without
1438
+ modification, are permitted provided that the following conditions are met:
1439
+
1440
+ 1. Redistributions of source code must retain the above copyright notice, this
1441
+ list of conditions and the following disclaimer.
1442
+
1443
+ 2. Redistributions in binary form must reproduce the above copyright notice,
1444
+ this list of conditions and the following disclaimer in the documentation
1445
+ and/or other materials provided with the distribution.
1446
+
1447
+ 3. Neither the name of the copyright holder nor the names of its contributors
1448
+ may be used to endorse or promote products derived from this software
1449
+ without specific prior written permission.
1450
+
1419
1451
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1420
1452
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1421
1453
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
package/docs/config.rst CHANGED
@@ -16,7 +16,8 @@ Example:
16
16
  "sprites": "sprites",
17
17
  "icons": "icons",
18
18
  "styles": "styles",
19
- "mbtiles": ""
19
+ "mbtiles": "data",
20
+ "pmtiles": "data"
20
21
  },
21
22
  "domains": [
22
23
  "localhost:8080",
@@ -33,6 +34,8 @@ Example:
33
34
  "serveAllStyles": false,
34
35
  "serveStaticMaps": true,
35
36
  "allowRemoteMarkerIcons": true,
37
+ "allowInlineMarkerImages": true,
38
+ "staticAttributionText": "© OpenMapTiles © OpenStreetMaps",
36
39
  "tileMargin": 0
37
40
  },
38
41
  "styles": {
@@ -140,7 +143,13 @@ It is recommended to also use the ``serveAllFonts`` option when using this optio
140
143
  -----------
141
144
 
142
145
  Optional string to be rendered into the raster tiles (and static maps) as watermark (bottom-left corner).
143
- Can be used for hard-coding attributions etc. (can also be specified per-style).
146
+ Not used by default.
147
+
148
+ ``staticAttributionText``
149
+ -----------
150
+
151
+ Optional string to be rendered in the static images endpoint. Text will be rendered in the bottom-right corner,
152
+ and styled similar to attribution on web-based maps (text only, links not supported).
144
153
  Not used by default.
145
154
 
146
155
  ``allowRemoteMarkerIcons``
@@ -150,6 +159,13 @@ Allows the rendering of marker icons fetched via http(s) hyperlinks.
150
159
  For security reasons only allow this if you can control the origins from where the markers are fetched!
151
160
  Default is to disallow fetching of icons from remote sources.
152
161
 
162
+ ``allowInlineMarkerImages``
163
+ --------------
164
+ Allows the rendering of inline marker icons or base64 urls.
165
+ For security reasons only allow this if you can control the origins from where the markers are fetched!
166
+ Not used by default.
167
+
168
+
153
169
  ``styles``
154
170
  ==========
155
171
 
@@ -165,11 +181,27 @@ Each item in this object defines one style (map). It can have the following opti
165
181
  ``data``
166
182
  ========
167
183
 
168
- Each item specifies one data source which should be made accessible by the server. It has the following options:
184
+ Each item specifies one data source which should be made accessible by the server. It has to have one of the following options:
185
+
186
+ * ``mbtiles`` -- name of the mbtiles file
187
+ * ``pmtiles`` -- name of the pmtiles file or url.
188
+
189
+ For example::
190
+
191
+ "data": {
192
+ "source1": {
193
+ "mbtiles": "source1.mbtiles"
194
+ },
195
+ "source2": {
196
+ "pmtiles": "source2.pmtiles"
197
+ },
198
+ "source3": {
199
+ "pmtiles": "https://foo.lan/source3.pmtiles"
200
+ }
201
+ }
169
202
 
170
- * ``mbtiles`` -- name of the mbtiles file [required]
171
203
 
172
- The mbtiles file does not need to be specified here unless you explicitly want to serve the raw data.
204
+ The data source does not need to be specified here unless you explicitly want to serve the raw data.
173
205
 
174
206
  Referencing local files from style JSON
175
207
  =======================================
@@ -179,21 +211,46 @@ You can link various data sources from the style JSON (for example even remote T
179
211
  MBTiles
180
212
  -------
181
213
 
182
- To specify that you want to use local mbtiles, use to following syntax: ``mbtiles://switzerland.mbtiles``.
183
- The TileServer-GL will try to find the file ``switzerland.mbtiles`` in ``root`` + ``mbtiles`` path.
214
+ To specify that you want to use local mbtiles, use to following syntax: ``mbtiles://source1.mbtiles``.
215
+ TileServer-GL will try to find the file ``source1.mbtiles`` in ``root`` + ``mbtiles`` path.
184
216
 
185
217
  For example::
186
218
 
187
219
  "sources": {
188
220
  "source1": {
189
- "url": "mbtiles://switzerland.mbtiles",
221
+ "url": "mbtiles://source1.mbtiles",
190
222
  "type": "vector"
191
223
  }
192
224
  }
193
225
 
194
- Alternatively, you can use ``mbtiles://{zurich-vector}`` to reference existing data object from the config.
195
- In this case, the server will look into the ``config.json`` to determine what mbtiles file to use.
196
- For the config above, this is equivalent to ``mbtiles://zurich.mbtiles``.
226
+ Alternatively, you can use ``mbtiles://{source1}`` to reference existing data object from the config.
227
+ In this case, the server will look into the ``config.json`` to determine what file to use by data id.
228
+ For the config above, this is equivalent to ``mbtiles://source1.mbtiles``.
229
+
230
+ PMTiles
231
+ -------
232
+
233
+ To specify that you want to use local pmtiles, use to following syntax: ``pmtiles://source2.pmtiles``.
234
+ TileServer-GL will try to find the file ``source2.pmtiles`` in ``root`` + ``pmtiles`` path.
235
+
236
+ To specify that you want to use a url based pmtiles, use to following syntax: ``pmtiles://https://foo.lan/source3.pmtiles``.
237
+
238
+ For example::
239
+
240
+ "sources": {
241
+ "source2": {
242
+ "url": "pmtiles://source2.pmtiles",
243
+ "type": "vector"
244
+ },
245
+ "source3": {
246
+ "url": "pmtiles://https://foo.lan/source3.pmtiles",
247
+ "type": "vector"
248
+ },
249
+ }
250
+
251
+ Alternatively, you can use ``pmtiles://{source2}`` to reference existing data object from the config.
252
+ In this case, the server will look into the ``config.json`` to determine what file to use by data id.
253
+ For the config above, this is equivalent to ``pmtiles://source2.mbtiles``.
197
254
 
198
255
  Sprites
199
256
  -------
@@ -35,14 +35,23 @@ Static images
35
35
 
36
36
  * All the static image endpoints additionally support following query parameters:
37
37
 
38
- * ``path``
39
- * can be provided multiple times
40
- * syntax
41
- * comma-separated ``lng,lat``, pipe-separated pairs
42
- * e.g. ``path=5.9,45.8|5.9,47.8|10.5,47.8|10.5,45.8|5.9,45.8``
43
- * Match pattern with options ``((fill|stroke|width)\:[^\|]+\|)*((enc:.+)|((-?\d+\.?\d*,-?\d+\.?\d*\|)+(-?\d+\.?\d*,-?\d+\.?\d*)))``
44
- * e.g. ``path=stroke:yellow|width:2|fill:green|5.9,45.8|5.9,47.8|10.5,47.8|10.5,45.8|5.9,45.8`` or ``stroke:blue|enc:_p~iF~ps|U_ulLnnqC_mqNvxq`@``
45
- * 'enc:' is specified in `Google Encoded Polyline Format <https://developers.google.com/maps/documentation/utilities/polylinealgorithm>`. If used, the rest of the path parameter is considered to be part of the encoded polyline string -- do not specify the coordinate pairs.
38
+ * ``path`` - ``((fill|stroke|width)\:[^\|]+\|)*(enc:.+|-?\d+(\.\d*)?,-?\d+(\.\d*)?(\|-?\d+(\.\d*)?,-?\d+(\.\d*)?)+)``
39
+
40
+ * comma-separated ``lng,lat``, pipe-separated pairs
41
+
42
+ * e.g. ``path=5.9,45.8|5.9,47.8|10.5,47.8|10.5,45.8|5.9,45.8``
43
+
44
+ * `Google Encoded Polyline Format <https://developers.google.com/maps/documentation/utilities/polylinealgorithm>`_
45
+
46
+ * e.g. ``path=enc:_p~iF~ps|U_ulLnnqC_mqNvxq`@``
47
+ * If 'enc:' is used, the rest of the path parameter is considered to be part of the encoded polyline string -- do not specify the coordinate pairs.
48
+
49
+ * With options (fill|stroke|width)
50
+
51
+ * e.g. ``path=stroke:yellow|width:2|fill:green|5.9,45.8|5.9,47.8|10.5,47.8|10.5,45.8|5.9,45.8`` or ``path=stroke:blue|width:1|fill:yellow|enc:_p~iF~ps|U_ulLnnqC_mqNvxq`@``
52
+
53
+ * can be provided multiple times
54
+
46
55
  * ``latlng`` - indicates coordinates are in ``lat,lng`` order rather than the usual ``lng,lat``
47
56
  * ``fill`` - color to use as the fill (e.g. ``red``, ``rgba(255,255,255,0.5)``, ``#0000ff``)
48
57
  * ``stroke`` - color of the path stroke
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tileserver-gl-light",
3
- "version": "4.5.1",
3
+ "version": "4.6.0",
4
4
  "description": "Map tile server for JSON GL styles - serving vector tiles",
5
5
  "main": "src/main.js",
6
6
  "bin": "src/main.js",
@@ -23,18 +23,20 @@
23
23
  "@mapbox/sphericalmercator": "1.2.0",
24
24
  "@mapbox/vector-tile": "1.3.1",
25
25
  "@maplibre/maplibre-gl-style-spec": "18.0.0",
26
+ "@sindresorhus/fnv1a": "3.0.0",
26
27
  "advanced-pool": "0.3.3",
27
28
  "chokidar": "3.5.3",
28
29
  "clone": "2.1.2",
29
30
  "color": "4.2.3",
30
- "commander": "11.0.0",
31
+ "commander": "11.1.0",
31
32
  "cors": "2.8.5",
32
33
  "express": "4.18.2",
33
34
  "handlebars": "4.7.8",
34
35
  "http-shutdown": "1.2.2",
35
36
  "morgan": "1.10.0",
36
37
  "pbf": "3.2.1",
37
- "proj4": "2.9.0",
38
+ "pmtiles": "2.11.0",
39
+ "proj4": "2.9.1",
38
40
  "request": "2.88.2",
39
41
  "sanitize-filename": "1.6.3",
40
42
  "tileserver-gl-styles": "2.0.0"
@@ -77,8 +77,9 @@
77
77
  <img src="{{public_url}}images/placeholder.png{{&key_query}}" alt="{{name}} preview" />
78
78
  {{/if}}
79
79
  <div class="details">
80
- <h3>{{name}}</h3>
81
- <p class="identifier">identifier: {{@key}}{{#if formatted_filesize}} | size: {{formatted_filesize}}{{/if}} | type: {{#is_vector}}vector{{/is_vector}}{{^is_vector}}raster{{/is_vector}} data</p>
80
+ <h3>{{tileJSON.name}}</h3>
81
+ <div class="identifier">identifier: {{@key}}{{#if formatted_filesize}} | size: {{formatted_filesize}}{{/if}}</div>
82
+ <div class="identifier">type: {{#is_vector}}vector{{/is_vector}}{{^is_vector}}raster{{/is_vector}} data {{#if source_type}} | ext: {{source_type}}{{/if}}</div>
82
83
  <p class="services">
83
84
  services: <a href="{{public_url}}data/{{@key}}.json{{&../key_query}}">TileJSON</a>
84
85
  {{#if wmts_link}}
package/src/main.js CHANGED
@@ -7,8 +7,9 @@ import path from 'path';
7
7
  import { fileURLToPath } from 'url';
8
8
  import request from 'request';
9
9
  import { server } from './server.js';
10
-
11
10
  import MBTiles from '@mapbox/mbtiles';
11
+ import { isValidHttpUrl } from './utils.js';
12
+ import { PMtilesOpen, GetPMtilesInfo } from './pmtiles_adapter.js';
12
13
 
13
14
  const __filename = fileURLToPath(import.meta.url);
14
15
  const __dirname = path.dirname(__filename);
@@ -25,9 +26,15 @@ import { program } from 'commander';
25
26
  program
26
27
  .description('tileserver-gl startup options')
27
28
  .usage('tileserver-gl [mbtiles] [options]')
29
+ .option(
30
+ '--file <file>',
31
+ 'MBTiles or PMTiles file\n' +
32
+ '\t ignored if the configuration file is also specified',
33
+ )
28
34
  .option(
29
35
  '--mbtiles <file>',
30
- 'MBTiles file (uses demo configuration);\n' +
36
+ '(DEPRECIATED) MBTiles file\n' +
37
+ '\t ignored if file is also specified' +
31
38
  '\t ignored if the configuration file is also specified',
32
39
  )
33
40
  .option(
@@ -55,7 +62,7 @@ const opts = program.opts();
55
62
 
56
63
  console.log(`Starting ${packageJson.name} v${packageJson.version}`);
57
64
 
58
- const startServer = (configPath, config) => {
65
+ const StartServer = (configPath, config) => {
59
66
  let publicUrl = opts.public_url;
60
67
  if (publicUrl && publicUrl.lastIndexOf('/') !== publicUrl.length - 1) {
61
68
  publicUrl += '/';
@@ -74,135 +81,205 @@ const startServer = (configPath, config) => {
74
81
  });
75
82
  };
76
83
 
77
- const startWithMBTiles = (mbtilesFile) => {
78
- console.log(`[INFO] Automatically creating config file for ${mbtilesFile}`);
84
+ const StartWithInputFile = async (inputFile) => {
85
+ console.log(`[INFO] Automatically creating config file for ${inputFile}`);
79
86
  console.log(`[INFO] Only a basic preview style will be used.`);
80
87
  console.log(
81
88
  `[INFO] See documentation to learn how to create config.json file.`,
82
89
  );
83
90
 
84
- mbtilesFile = path.resolve(process.cwd(), mbtilesFile);
91
+ let inputFilePath;
92
+ if (isValidHttpUrl(inputFile)) {
93
+ inputFilePath = process.cwd();
94
+ } else {
95
+ inputFile = path.resolve(process.cwd(), inputFile);
96
+ inputFilePath = path.dirname(inputFile);
85
97
 
86
- const mbtilesStats = fs.statSync(mbtilesFile);
87
- if (!mbtilesStats.isFile() || mbtilesStats.size === 0) {
88
- console.log(`ERROR: Not valid MBTiles file: ${mbtilesFile}`);
89
- process.exit(1);
90
- }
91
- const instance = new MBTiles(mbtilesFile + '?mode=ro', (err) => {
92
- if (err) {
93
- console.log('ERROR: Unable to open MBTiles.');
94
- console.log(`Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
98
+ const inputFileStats = fs.statSync(inputFile);
99
+ if (!inputFileStats.isFile() || inputFileStats.size === 0) {
100
+ console.log(`ERROR: Not a valid input file: `);
95
101
  process.exit(1);
96
102
  }
103
+ }
97
104
 
98
- instance.getInfo((err, info) => {
99
- if (err || !info) {
100
- console.log('ERROR: Metadata missing in the MBTiles.');
101
- console.log(
102
- `Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`,
103
- );
104
- process.exit(1);
105
- }
106
- const bounds = info.bounds;
105
+ const styleDir = path.resolve(
106
+ __dirname,
107
+ '../node_modules/tileserver-gl-styles/',
108
+ );
107
109
 
108
- const styleDir = path.resolve(
109
- __dirname,
110
- '../node_modules/tileserver-gl-styles/',
111
- );
110
+ const config = {
111
+ options: {
112
+ paths: {
113
+ root: styleDir,
114
+ fonts: 'fonts',
115
+ styles: 'styles',
116
+ mbtiles: inputFilePath,
117
+ pmtiles: inputFilePath,
118
+ },
119
+ },
120
+ styles: {},
121
+ data: {},
122
+ };
112
123
 
113
- const config = {
114
- options: {
115
- paths: {
116
- root: styleDir,
117
- fonts: 'fonts',
118
- styles: 'styles',
119
- mbtiles: path.dirname(mbtilesFile),
120
- },
121
- },
122
- styles: {},
123
- data: {},
124
- };
125
-
126
- if (
127
- info.format === 'pbf' &&
128
- info.name.toLowerCase().indexOf('openmaptiles') > -1
129
- ) {
124
+ const extension = inputFile.split('.').pop().toLowerCase();
125
+ if (extension === 'pmtiles') {
126
+ let FileOpenInfo = PMtilesOpen(inputFile);
127
+ const metadata = await GetPMtilesInfo(FileOpenInfo);
128
+
129
+ if (
130
+ metadata.format === 'pbf' &&
131
+ metadata.name.toLowerCase().indexOf('openmaptiles') > -1
132
+ ) {
133
+ if (isValidHttpUrl(inputFile)) {
130
134
  config['data'][`v3`] = {
131
- mbtiles: path.basename(mbtilesFile),
135
+ pmtiles: inputFile,
132
136
  };
137
+ } else {
138
+ config['data'][`v3`] = {
139
+ pmtiles: path.basename(inputFile),
140
+ };
141
+ }
133
142
 
134
- const styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
135
- for (const styleName of styles) {
136
- const styleFileRel = styleName + '/style.json';
137
- const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
138
- if (fs.existsSync(styleFile)) {
139
- config['styles'][styleName] = {
140
- style: styleFileRel,
141
- tilejson: {
142
- bounds: bounds,
143
- },
144
- };
145
- }
143
+ const styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
144
+ for (const styleName of styles) {
145
+ const styleFileRel = styleName + '/style.json';
146
+ const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
147
+ if (fs.existsSync(styleFile)) {
148
+ config['styles'][styleName] = {
149
+ style: styleFileRel,
150
+ tilejson: {
151
+ bounds: metadata.bounds,
152
+ },
153
+ };
146
154
  }
155
+ }
156
+ } else {
157
+ console.log(
158
+ `WARN: PMTiles not in "openmaptiles" format. Serving raw data only...`,
159
+ );
160
+ if (isValidHttpUrl(inputFile)) {
161
+ config['data'][(metadata.id || 'pmtiles').replace(/[?/:]/g, '_')] = {
162
+ pmtiles: inputFile,
163
+ };
147
164
  } else {
148
- console.log(
149
- `WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`,
150
- );
151
- config['data'][
152
- (info.id || 'mbtiles')
153
- .replace(/\//g, '_')
154
- .replace(/:/g, '_')
155
- .replace(/\?/g, '_')
156
- ] = {
157
- mbtiles: path.basename(mbtilesFile),
165
+ config['data'][(metadata.id || 'pmtiles').replace(/[?/:]/g, '_')] = {
166
+ pmtiles: path.basename(inputFile),
158
167
  };
159
168
  }
169
+ }
160
170
 
161
- if (opts.verbose) {
162
- console.log(JSON.stringify(config, undefined, 2));
163
- } else {
164
- console.log('Run with --verbose to see the config file here.');
171
+ if (opts.verbose) {
172
+ console.log(JSON.stringify(config, undefined, 2));
173
+ } else {
174
+ console.log('Run with --verbose to see the config file here.');
175
+ }
176
+
177
+ return StartServer(null, config);
178
+ } else {
179
+ if (isValidHttpUrl(inputFile)) {
180
+ console.log(
181
+ `ERROR: MBTiles does not support web based files. "${inputFile}" is not a valid data file.`,
182
+ );
183
+ process.exit(1);
184
+ }
185
+ const instance = new MBTiles(inputFile + '?mode=ro', (err) => {
186
+ if (err) {
187
+ console.log('ERROR: Unable to open MBTiles.');
188
+ console.log(`Make sure ${path.basename(inputFile)} is valid MBTiles.`);
189
+ process.exit(1);
165
190
  }
166
191
 
167
- return startServer(null, config);
192
+ instance.getInfo((err, info) => {
193
+ if (err || !info) {
194
+ console.log('ERROR: Metadata missing in the MBTiles.');
195
+ console.log(
196
+ `Make sure ${path.basename(inputFile)} is valid MBTiles.`,
197
+ );
198
+ process.exit(1);
199
+ }
200
+ const bounds = info.bounds;
201
+
202
+ if (
203
+ info.format === 'pbf' &&
204
+ info.name.toLowerCase().indexOf('openmaptiles') > -1
205
+ ) {
206
+ config['data'][`v3`] = {
207
+ mbtiles: path.basename(inputFile),
208
+ };
209
+
210
+ const styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
211
+ for (const styleName of styles) {
212
+ const styleFileRel = styleName + '/style.json';
213
+ const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
214
+ if (fs.existsSync(styleFile)) {
215
+ config['styles'][styleName] = {
216
+ style: styleFileRel,
217
+ tilejson: {
218
+ bounds: bounds,
219
+ },
220
+ };
221
+ }
222
+ }
223
+ } else {
224
+ console.log(
225
+ `WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`,
226
+ );
227
+ config['data'][(info.id || 'mbtiles').replace(/[?/:]/g, '_')] = {
228
+ mbtiles: path.basename(inputFile),
229
+ };
230
+ }
231
+
232
+ if (opts.verbose) {
233
+ console.log(JSON.stringify(config, undefined, 2));
234
+ } else {
235
+ console.log('Run with --verbose to see the config file here.');
236
+ }
237
+
238
+ return StartServer(null, config);
239
+ });
168
240
  });
169
- });
241
+ }
170
242
  };
171
243
 
172
244
  fs.stat(path.resolve(opts.config), (err, stats) => {
173
245
  if (err || !stats.isFile() || stats.size === 0) {
174
- let mbtiles = opts.mbtiles;
175
- if (!mbtiles) {
246
+ let inputFile;
247
+ if (opts.file) {
248
+ inputFile = opts.file;
249
+ } else if (opts.mbtiles) {
250
+ inputFile = opts.mbtiles;
251
+ }
252
+
253
+ if (inputFile) {
254
+ return StartWithInputFile(inputFile);
255
+ } else {
176
256
  // try to find in the cwd
177
257
  const files = fs.readdirSync(process.cwd());
178
258
  for (const filename of files) {
179
- if (filename.endsWith('.mbtiles')) {
180
- const mbTilesStats = fs.statSync(filename);
181
- if (mbTilesStats.isFile() && mbTilesStats.size > 0) {
182
- mbtiles = filename;
259
+ if (filename.endsWith('.mbtiles') || filename.endsWith('.pmtiles')) {
260
+ const inputFilesStats = fs.statSync(filename);
261
+ if (inputFilesStats.isFile() && inputFilesStats.size > 0) {
262
+ inputFile = filename;
183
263
  break;
184
264
  }
185
265
  }
186
266
  }
187
- if (mbtiles) {
188
- console.log(`No MBTiles specified, using ${mbtiles}`);
189
- return startWithMBTiles(mbtiles);
267
+ if (inputFile) {
268
+ console.log(`No input file specified, using ${inputFile}`);
269
+ return StartWithInputFile(inputFile);
190
270
  } else {
191
271
  const url =
192
272
  'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
193
273
  const filename = 'zurich_switzerland.mbtiles';
194
274
  const stream = fs.createWriteStream(filename);
195
- console.log(`No MBTiles found`);
275
+ console.log(`No input file found`);
196
276
  console.log(`[DEMO] Downloading sample data (${filename}) from ${url}`);
197
- stream.on('finish', () => startWithMBTiles(filename));
277
+ stream.on('finish', () => StartWithInputFile(filename));
198
278
  return request.get(url).pipe(stream);
199
279
  }
200
280
  }
201
- if (mbtiles) {
202
- return startWithMBTiles(mbtiles);
203
- }
204
281
  } else {
205
282
  console.log(`Using specified config file from ${opts.config}`);
206
- return startServer(opts.config, null);
283
+ return StartServer(opts.config, null);
207
284
  }
208
285
  });