coastlines 0.0.3-alpha.0 → 0.0.4-alpha.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.
package/LICENSE CHANGED
@@ -19,3 +19,11 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
23
+ ---
24
+
25
+ The code and documentation are MIT, above. The data ships under its own
26
+ terms, unchanged: Natural Earth is public domain; the GSHHG shoreline is
27
+ LGPL-3.0-or-later, with its copyright and permission notice at
28
+ data/gshhg-licence.txt and the licence text at data/gshhg-copying-lesser.txt.
29
+ The package's SPDX expression, `MIT AND LGPL-3.0-or-later`, names both.
package/README.md CHANGED
@@ -20,7 +20,16 @@ const world = JSON.parse(await readFile(localUrl(entry), 'utf8'))
20
20
  ```
21
21
 
22
22
  The subpath `coastlines/data/<id>` resolves to the `.geojson` file for any
23
- tool that can load one; `manifest.json` and `charts.json` are plain JSON.
23
+ tool that can load one; `manifest.json` and `charts.json` are plain JSON. A
24
+ file in another format carries its extension, `coastlines/data/gshhg-land-h.shp`,
25
+ and `shapefilePolygons` from the package reads it:
26
+
27
+ ```js
28
+ import { find, localUrl, shapefilePolygons } from 'coastlines'
29
+
30
+ const land = find('gshhg-land-h') // { source: 'gshhg', format: 'shp', … }
31
+ const polygons = shapefilePolygons(await readFile(localUrl(land))) // 144,749 of [outerRing]
32
+ ```
24
33
 
25
34
  **See it:** [the basemap on GitHub Pages](https://mark-brannan.github.io/coastlines/),
26
35
  the three default charts, drawn with the styles the plugin will serve.
@@ -45,9 +54,12 @@ draws.
45
54
 
46
55
  ## The catalogue
47
56
 
48
- 33 files. Every 50m and 110m file in the marine catalogue, and at 10m the
49
- coastline, the land and every other file that fits a 5 MB response body.
50
- The rest of 10m and the bathymetry set belong to companion packages.
57
+ 36 files from two sources. From Natural Earth, every 50m and 110m file in
58
+ the marine catalogue, and at 10m the coastline, the land and every other file
59
+ that fits a 5 MB response body; the rest of 10m and the bathymetry set belong
60
+ to companion packages. From GSHHG 2.3.7, the "h" land polygons, the next rung
61
+ of coastline above Natural Earth's 10m (vertex spacing median 707 m), as the
62
+ published shapefile, with the two licence notices that travel with it.
51
63
 
52
64
  <!-- catalogue:start -->
53
65
  | Import `coastlines/data/…` | Layer | Scale | Geometry | Raw | Why a boat wants it |
@@ -85,17 +97,33 @@ The rest of 10m and the bathymetry set belong to companion packages.
85
97
  | `ne-admin-0-disputed-areas-10m` | admin_0_disputed_areas | 10m | polygons | 685 KB | Honesty on the borders layer |
86
98
  | `ne-ports-10m` | ports | 10m | points | 273 KB | Harbours |
87
99
  | `ne-antarctic-ice-shelves-polys-10m` | antarctic_ice_shelves_polys | 10m | polygons | 548 KB | Polar context |
100
+ | `gshhg-land-h.shp` | land | h | polygons | 32.5 MB | Land, the GSHHS shoreline at high resolution; 144,749 polygons |
101
+ | `gshhg-licence.txt` | — | — | — | 1 KB | The GSHHG copyright and permission notice; travels with every copy |
102
+ | `gshhg-copying-lesser.txt` | — | — | — | 8 KB | The GNU Lesser General Public License, version 3 |
88
103
  <!-- catalogue:end -->
89
104
 
90
105
  ![Every file, rendered equirectangular](docs/layers.png)
91
106
 
92
107
  Ids follow the file: `ne-<layer>-<scale>` is `ne_<scale>_<layer>.geojson` in
93
- the Natural Earth tree. `coastlines/manifest.json` is the machine-readable
94
- form of this table, with the bytes and sha256 of each file.
108
+ the Natural Earth tree; `gshhg-land-h` is `GSHHS_shp/h/GSHHS_h_L1.shp` inside
109
+ the GSHHG zip. `coastlines/manifest.json` is the machine-readable form of this
110
+ table, with the bytes and sha256 of each file and, under `sources`, of the
111
+ zip itself.
112
+
113
+ ### Sources and licences
114
+
115
+ Natural Earth is public domain. GSHHG (Wessel & Smith, the Global
116
+ Self-consistent, Hierarchical, High-resolution Geography database) is
117
+ LGPL-3.0-or-later with a permission notice that asks for the copyright and
118
+ permission notice to appear in all copies; both ship unchanged as
119
+ `data/gshhg-licence.txt` and `data/gshhg-copying-lesser.txt`, pinned like the
120
+ data. Cite: Wessel, P., and W. H. F. Smith, A global, self-consistent,
121
+ hierarchical, high-resolution shoreline database, _J. Geophys. Res._, 101(B4),
122
+ 8741–8743, 1996.
95
123
 
96
124
  ## The charts
97
125
 
98
- A plotter does not want 33 files; it wants a basemap to tick. `charts.json`
126
+ A plotter does not want 36 files; it wants a basemap to tick. `charts.json`
99
127
  groups the files into three charts, each at one scale, and gives every layer
100
128
  its zoom range. `styles/<chart>.json` is a Mapbox style, hand-written, one
101
129
  per chart; the demo draws it over GeoJSON sources, and the plugin will serve
@@ -112,14 +140,14 @@ consumer written against one chart reads any.
112
140
 
113
141
  ## Provenance, and checking rather than trusting
114
142
 
115
- `data/` is not in git. `npm run sync` fetches each file from the pinned
143
+ `data/` is not in git. `npm run sync` fetches each file from its pinned
116
144
  release and refuses any byte that disagrees with `manifest.json`; `npm pack`
117
145
  runs it first, so a tarball never ships a file the manifest did not promise.
118
146
 
119
147
  ```shell
120
- npm run sync # fetch what is missing, verify everything (45 MB, ~15 s)
148
+ npm run sync # fetch what is missing, verify everything (45 MB + 149 MB zip)
121
149
  npm run sync:check # verify only, no network
122
- npm run sync:refresh # move the pin: refetch all and rewrite bytes and sha256
150
+ npm run sync:refresh # move the pins: refetch all and rewrite bytes and sha256
123
151
  ```
124
152
 
125
153
  To check a published tarball against Natural Earth yourself:
@@ -136,4 +164,8 @@ permission needed, no attribution required. Credited anyway:
136
164
 
137
165
  > Made with Natural Earth. Free vector and raster map data @ naturalearthdata.com
138
166
 
167
+ The GSHHG shoreline is [LGPL-3.0-or-later][gshhg]; its notices ship beside it
168
+ ([Sources and licences](#sources-and-licences)).
169
+
139
170
  [ne]: https://www.naturalearthdata.com/
171
+ [gshhg]: https://www.soest.hawaii.edu/pwessel/gshhg/
package/charts.json CHANGED
@@ -10,9 +10,24 @@
10
10
  { "id": "ne-land-110m", "name": "land", "minzoom": 0, "maxzoom": 4 },
11
11
  { "id": "ne-glaciated-areas-110m", "name": "glaciated_areas", "minzoom": 2, "maxzoom": 4 },
12
12
  { "id": "ne-lakes-110m", "name": "lakes", "minzoom": 2, "maxzoom": 4 },
13
- { "id": "ne-rivers-lake-centerlines-110m", "name": "rivers_lake_centerlines", "minzoom": 3, "maxzoom": 4 },
14
- { "id": "ne-admin-0-countries-110m", "name": "admin_0_countries", "minzoom": 2, "maxzoom": 4 },
15
- { "id": "ne-admin-0-boundary-lines-land-110m", "name": "admin_0_boundary_lines_land", "minzoom": 1, "maxzoom": 4 },
13
+ {
14
+ "id": "ne-rivers-lake-centerlines-110m",
15
+ "name": "rivers_lake_centerlines",
16
+ "minzoom": 3,
17
+ "maxzoom": 4
18
+ },
19
+ {
20
+ "id": "ne-admin-0-countries-110m",
21
+ "name": "admin_0_countries",
22
+ "minzoom": 2,
23
+ "maxzoom": 4
24
+ },
25
+ {
26
+ "id": "ne-admin-0-boundary-lines-land-110m",
27
+ "name": "admin_0_boundary_lines_land",
28
+ "minzoom": 1,
29
+ "maxzoom": 4
30
+ },
16
31
  { "id": "ne-coastline-110m", "name": "coastline", "minzoom": 0, "maxzoom": 4 },
17
32
  { "id": "ne-geographic-lines-110m", "name": "geographic_lines", "minzoom": 0, "maxzoom": 4 },
18
33
  { "id": "ne-populated-places-110m", "name": "populated_places", "minzoom": 2, "maxzoom": 4 }
@@ -27,13 +42,33 @@
27
42
  "layers": [
28
43
  { "id": "ne-ocean-50m", "name": "ocean", "minzoom": 0, "maxzoom": 7 },
29
44
  { "id": "ne-land-50m", "name": "land", "minzoom": 0, "maxzoom": 7 },
30
- { "id": "ne-antarctic-ice-shelves-polys-50m", "name": "antarctic_ice_shelves_polys", "minzoom": 2, "maxzoom": 7 },
45
+ {
46
+ "id": "ne-antarctic-ice-shelves-polys-50m",
47
+ "name": "antarctic_ice_shelves_polys",
48
+ "minzoom": 2,
49
+ "maxzoom": 7
50
+ },
31
51
  { "id": "ne-glaciated-areas-50m", "name": "glaciated_areas", "minzoom": 3, "maxzoom": 7 },
32
52
  { "id": "ne-lakes-50m", "name": "lakes", "minzoom": 3, "maxzoom": 7 },
33
- { "id": "ne-rivers-lake-centerlines-50m", "name": "rivers_lake_centerlines", "minzoom": 4, "maxzoom": 7 },
53
+ {
54
+ "id": "ne-rivers-lake-centerlines-50m",
55
+ "name": "rivers_lake_centerlines",
56
+ "minzoom": 4,
57
+ "maxzoom": 7
58
+ },
34
59
  { "id": "ne-admin-0-countries-50m", "name": "admin_0_countries", "minzoom": 3, "maxzoom": 7 },
35
- { "id": "ne-admin-0-boundary-lines-land-50m", "name": "admin_0_boundary_lines_land", "minzoom": 2, "maxzoom": 7 },
36
- { "id": "ne-admin-0-boundary-lines-maritime-indicator-50m", "name": "admin_0_boundary_lines_maritime_indicator", "minzoom": 3, "maxzoom": 7 },
60
+ {
61
+ "id": "ne-admin-0-boundary-lines-land-50m",
62
+ "name": "admin_0_boundary_lines_land",
63
+ "minzoom": 2,
64
+ "maxzoom": 7
65
+ },
66
+ {
67
+ "id": "ne-admin-0-boundary-lines-maritime-indicator-50m",
68
+ "name": "admin_0_boundary_lines_maritime_indicator",
69
+ "minzoom": 3,
70
+ "maxzoom": 7
71
+ },
37
72
  { "id": "ne-coastline-50m", "name": "coastline", "minzoom": 0, "maxzoom": 7 },
38
73
  { "id": "ne-geographic-lines-50m", "name": "geographic_lines", "minzoom": 0, "maxzoom": 7 },
39
74
  { "id": "ne-populated-places-50m", "name": "populated_places", "minzoom": 3, "maxzoom": 7 }
@@ -45,8 +80,6 @@
45
80
  "description": "The finest coastline alone, to zoom 12, the layer a distance-to-shore reads",
46
81
  "minzoom": 0,
47
82
  "maxzoom": 12,
48
- "layers": [
49
- { "id": "ne-coastline-10m", "name": "coastline", "minzoom": 0, "maxzoom": 12 }
50
- ]
83
+ "layers": [{ "id": "ne-coastline-10m", "name": "coastline", "minzoom": 0, "maxzoom": 12 }]
51
84
  }
52
85
  ]
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: package/data/gshhg-land-h.shp
3
+ size: 34129516 bytes
4
+ sha256: d870bdbc90a074f87a8c09a9630abb5f18916314b9a196dba2e6866fd51ef325
@@ -0,0 +1,23 @@
1
+ $LastChangedDate: 2013-11-24 09:26:07 -1000 (Sun, 24 Nov 2013) $
2
+ $Revision: 594 $
3
+
4
+ As of GSHHG 2.2.2, GSHHG is distributed under the GNU Lesser General Public
5
+ License (LGPL) version 3 or later. Copies of the The GNU General Public
6
+ License (GPL) and the GNU Lesser General Public License (LGPL) are
7
+ distributed along with the sources. Refer to the files COPYINGv3 and
8
+ COPYING.LESSERv3.
9
+
10
+ Permission to use, copy, modify, and distribute (with no more than a
11
+ reasonable redistribution fee) this data and its documentation for
12
+ any purpose is hereby granted, provided that the above copyright notice
13
+ appear in all copies, that both that copyright notice and this
14
+ permission notice appear in supporting documentation, and that the name
15
+ of GSHHG not be used in advertising or publicity pertaining to
16
+ distribution of the software without specific, written prior permission.
17
+ The GSHHG package may be included in a bundled distribution of software
18
+ for which a fee may be charged. The University of Hawaii (UH) and the
19
+ National Oceanic and Atmospheric Administration (NOAA) make no
20
+ representations about the suitability of this software for any purpose.
21
+ It is provided "as is" without expressed or implied warranty. It is
22
+ provided with no support and without obligation on the part of UH or
23
+ NOAA, to assist in its use, correction, modification, or enhancement.
package/lib/catalogue.js CHANGED
@@ -3,30 +3,48 @@
3
3
  // Every consumer -- the sync script, the renderers, the tests and later the
4
4
  // Signal K plugin -- goes through here rather than reading the manifest or
5
5
  // guessing a path, so the layout of data/ is decided in exactly one place.
6
- import { createRequire } from 'node:module'
6
+ import { createRequire } from 'node:module';
7
7
 
8
- const require = createRequire(import.meta.url)
8
+ const require = createRequire(import.meta.url);
9
9
 
10
- /** The parsed manifest. `source` is the pinned upstream; `files` one entry per shipped id. */
11
- export const manifest = require('../manifest.json')
10
+ /**
11
+ * The parsed manifest. `sources` is the pinned upstreams keyed by short name
12
+ * (`ne`, `gshhg`); `files` one entry per shipped id, each naming its source.
13
+ */
14
+ export const manifest = require('../manifest.json');
12
15
 
13
- /** The Natural Earth file name an entry came from, e.g. `ne_50m_coastline.geojson`. */
14
- export const upstreamName = ({ layer, scale }) => `ne_${scale}_${layer}.geojson`
16
+ /** The source an entry comes from: the `sources` object it names. */
17
+ export const source = (entry) => manifest.sources[entry.source];
15
18
 
16
- /** The URL an entry is fetched from, pinned to the manifest's ref. */
17
- export const upstreamUrl = (entry) => new URL(upstreamName(entry), manifest.source.base).href
19
+ /** An entry's on-disk format: `'geojson'` unless the manifest says `'shp'` or `'txt'`. */
20
+ export const format = (entry) => entry.format ?? 'geojson';
18
21
 
19
- /** Where an entry lives on disk once synced: `data/<id>.geojson`, relative to the package root. */
20
- export const localPath = ({ id }) => `data/${id}.geojson`
22
+ /**
23
+ * The upstream file name: for Natural Earth `ne_50m_coastline.geojson`; for a
24
+ * member of a zip, its path inside the archive.
25
+ */
26
+ export const upstreamName = (entry) => entry.member ?? `ne_${entry.scale}_${entry.layer}.geojson`;
27
+
28
+ /**
29
+ * The URL an entry is fetched from, pinned. A Natural Earth file has one of its
30
+ * own; a zip member comes from the zip, and `upstreamName` says which member.
31
+ */
32
+ export const upstreamUrl = (entry) => {
33
+ const from = source(entry);
34
+ return from.url ?? new URL(upstreamName(entry), from.base).href;
35
+ };
36
+
37
+ /** Where an entry lives on disk once synced: `data/<id>.<format>`, relative to the package root. */
38
+ export const localPath = (entry) => `data/${entry.id}.${format(entry)}`;
21
39
 
22
40
  /** The file URL of an entry on disk, for `readFile`. */
23
- export const localUrl = (entry) => new URL(`../${localPath(entry)}`, import.meta.url)
41
+ export const localUrl = (entry) => new URL(`../${localPath(entry)}`, import.meta.url);
24
42
 
25
43
  /** The entry for an id, or `undefined`: a provider rejects ids it does not own. */
26
- export const find = (id) => manifest.files.find((entry) => entry.id === id)
44
+ export const find = (id) => manifest.files.find((entry) => entry.id === id);
27
45
 
28
46
  /** Every id, in manifest order. */
29
- export const ids = () => manifest.files.map((entry) => entry.id)
47
+ export const ids = () => manifest.files.map((entry) => entry.id);
30
48
 
31
- /** The entries of one scale: `'10m'`, `'50m'` or `'110m'`. */
32
- export const atScale = (scale) => manifest.files.filter((entry) => entry.scale === scale)
49
+ /** The entries of one scale: Natural Earth's `'10m'`, `'50m'`, `'110m'`, or GSHHG's `'h'`. */
50
+ export const atScale = (scale) => manifest.files.filter((entry) => entry.scale === scale);
package/lib/charts.js CHANGED
@@ -2,16 +2,16 @@
2
2
  // the zoom range each layer is drawn at. The styles in styles/ and, later, the
3
3
  // plugin's tile cutter both read this table, so a layer outside its range is
4
4
  // neither styled nor cut.
5
- import { createRequire } from 'node:module'
6
- import { find } from './catalogue.js'
5
+ import { createRequire } from 'node:module';
6
+ import { find } from './catalogue.js';
7
7
 
8
- const require = createRequire(import.meta.url)
8
+ const require = createRequire(import.meta.url);
9
9
 
10
10
  /** The parsed charts.json: one entry per chart, in the order a plotter lists them. */
11
- export const charts = require('../charts.json')
11
+ export const charts = require('../charts.json');
12
12
 
13
13
  /** The chart with this id, or `undefined`. */
14
- export const chart = (id) => charts.find((entry) => entry.id === id)
14
+ export const chart = (id) => charts.find((entry) => entry.id === id);
15
15
 
16
16
  /**
17
17
  * The catalogue entries of a chart drawn at a zoom, with their layer name.
@@ -19,9 +19,9 @@ export const chart = (id) => charts.find((entry) => entry.id === id)
19
19
  * consumer written against one chart reads any.
20
20
  */
21
21
  export function layersAt(chartId, zoom) {
22
- const entry = chart(chartId)
23
- if (!entry) return []
22
+ const entry = chart(chartId);
23
+ if (!entry) return [];
24
24
  return entry.layers
25
25
  .filter(({ minzoom, maxzoom }) => zoom >= minzoom && zoom <= maxzoom)
26
- .map((layer) => ({ ...layer, entry: find(layer.id) }))
26
+ .map((layer) => ({ ...layer, entry: find(layer.id) }));
27
27
  }
package/lib/draw.js CHANGED
@@ -4,30 +4,29 @@
4
4
  // is -- and it clips nothing, which equirectangular never needs.
5
5
 
6
6
  /** Equirectangular: lon,lat to x,y in a `width` by `height` box. */
7
- export const equirectangular = (width, height) => ([lon, lat]) => [
8
- ((lon + 180) / 360) * width,
9
- ((90 - lat) / 180) * height,
10
- ]
7
+ export const equirectangular =
8
+ (width, height) =>
9
+ ([lon, lat]) => [((lon + 180) / 360) * width, ((90 - lat) / 180) * height];
11
10
 
12
11
  function tracePath(ctx, rings, project) {
13
12
  for (const ring of rings) {
14
13
  ring.forEach((position, index) => {
15
- const [x, y] = project(position)
16
- if (index === 0) ctx.moveTo(x, y)
17
- else ctx.lineTo(x, y)
18
- })
14
+ const [x, y] = project(position);
15
+ if (index === 0) ctx.moveTo(x, y);
16
+ else ctx.lineTo(x, y);
17
+ });
19
18
  }
20
19
  }
21
20
 
22
21
  /** Every ring (polygons), line (lines) or position (points) of a geometry, flattened one level. */
23
22
  function parts(geometry) {
24
- const { type, coordinates } = geometry
25
- if (type === 'Point') return [[coordinates]]
26
- if (type === 'MultiPoint') return [coordinates]
27
- if (type === 'LineString') return [coordinates]
28
- if (type === 'MultiLineString' || type === 'Polygon') return coordinates
29
- if (type === 'MultiPolygon') return coordinates.flat()
30
- return []
23
+ const { type, coordinates } = geometry;
24
+ if (type === 'Point') return [[coordinates]];
25
+ if (type === 'MultiPoint') return [coordinates];
26
+ if (type === 'LineString') return [coordinates];
27
+ if (type === 'MultiLineString' || type === 'Polygon') return coordinates;
28
+ if (type === 'MultiPolygon') return coordinates.flat();
29
+ return [];
31
30
  }
32
31
 
33
32
  /**
@@ -36,26 +35,26 @@ function parts(geometry) {
36
35
  * points become dots of `radius`.
37
36
  */
38
37
  export function drawCollection(ctx, collection, project, style) {
39
- const { fill, stroke, lineWidth = 1, radius = 1.5 } = style
40
- ctx.lineWidth = lineWidth
41
- if (stroke) ctx.strokeStyle = stroke
42
- if (fill) ctx.fillStyle = fill
38
+ const { fill, stroke, lineWidth = 1, radius = 1.5 } = style;
39
+ ctx.lineWidth = lineWidth;
40
+ if (stroke) ctx.strokeStyle = stroke;
41
+ if (fill) ctx.fillStyle = fill;
43
42
  for (const feature of collection.features) {
44
- if (!feature.geometry) continue
45
- const { type } = feature.geometry
46
- const polygon = type === 'Polygon' || type === 'MultiPolygon'
47
- const point = type === 'Point' || type === 'MultiPoint'
43
+ if (!feature.geometry) continue;
44
+ const { type } = feature.geometry;
45
+ const polygon = type === 'Polygon' || type === 'MultiPolygon';
46
+ const point = type === 'Point' || type === 'MultiPoint';
48
47
  if (point) {
49
48
  for (const [x, y] of parts(feature.geometry)[0].map(project)) {
50
- ctx.beginPath()
51
- ctx.arc(x, y, radius, 0, Math.PI * 2)
52
- ctx.fill()
49
+ ctx.beginPath();
50
+ ctx.arc(x, y, radius, 0, Math.PI * 2);
51
+ ctx.fill();
53
52
  }
54
- continue
53
+ continue;
55
54
  }
56
- ctx.beginPath()
57
- tracePath(ctx, parts(feature.geometry), project)
58
- if (polygon && fill) ctx.fill('evenodd')
59
- if (stroke) ctx.stroke()
55
+ ctx.beginPath();
56
+ tracePath(ctx, parts(feature.geometry), project);
57
+ if (polygon && fill) ctx.fill('evenodd');
58
+ if (stroke) ctx.stroke();
60
59
  }
61
60
  }
package/lib/index.js CHANGED
@@ -3,9 +3,12 @@ export {
3
3
  find,
4
4
  ids,
5
5
  atScale,
6
+ source,
7
+ format,
6
8
  localPath,
7
9
  localUrl,
8
10
  upstreamName,
9
11
  upstreamUrl,
10
- } from './catalogue.js'
11
- export { charts, chart, layersAt } from './charts.js'
12
+ } from './catalogue.js';
13
+ export { charts, chart, layersAt } from './charts.js';
14
+ export { shapefilePolygons } from './shapefile.js';