dotted-map 2.2.3 → 3.1.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/README.md CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  <img src="https://raw.githubusercontent.com/NTag/dotted-map/master/images/world-diagonal-circle-dark.svg" width="100%" />
9
9
 
10
+ <img src="https://raw.githubusercontent.com/NTag/dotted-map/master/images/world-orthographic-circle-dark.svg" width="100%" />
11
+
10
12
  <img src="https://raw.githubusercontent.com/NTag/dotted-map/master/images/france-diagonal-hexagon-light.svg" height="150px" />
11
13
  <img src="https://raw.githubusercontent.com/NTag/dotted-map/master/images/italy-diagonal-hexagon-light.svg" height="150px" />
12
14
  <img src="https://raw.githubusercontent.com/NTag/dotted-map/master/images/uk-diagonal-hexagon-light.svg" height="150px" />
@@ -16,7 +18,7 @@
16
18
 
17
19
  ## Installation
18
20
 
19
- Requires NodeJS ≥ 13.
21
+ Requires NodeJS ≥ 18.
20
22
 
21
23
  ```bash
22
24
  npm i dotted-map
@@ -25,9 +27,8 @@ npm i dotted-map
25
27
  ## Usage
26
28
 
27
29
  ```js
28
- const fs = require('fs');
29
- const DottedMap = require('dotted-map').default;
30
- // Or in the browser: import DottedMap from 'dotted-map';
30
+ import fs from 'fs';
31
+ import DottedMap from 'dotted-map';
31
32
 
32
33
  const map = new DottedMap({ height: 60, grid: 'diagonal' });
33
34
 
@@ -54,13 +55,15 @@ fs.writeFileSync('./map.svg', svgMap);
54
55
 
55
56
  If you use a large number of points (height or width ≥ 100), it may take a bit of time to compute the map (from 1 to 30 seconds depending on your device and number of points). This is why the result grid is cached. If you don’t change the parameters of `new DottedMap`, the next maps will be a lot faster to generate. You can however change the pins and the SVG options.
56
57
 
58
+ It’s also possible to use it in **Leaflet**, see [an example here](https://github.com/NTag/colivings/blob/main/src/App.js).
59
+
57
60
  ### Precomputing the map
58
61
 
59
62
  Because the previous operation can be expansive (especially if you want to use DottedMap in a browser or React Native app), it’s possible to precompute the grid. You will still be able to add pins on-the-fly, in real time. This also allows you to import a lighter version of the library. This is especially useful if you always use the same map parameters, but only change the pins.
60
63
 
61
64
  ```js
62
65
  // So you do this first step only once, when developing your app
63
- const getMapJSON = require('dotted-map').getMapJSON;
66
+ import { getMapJSON } from 'dotted-map';
64
67
 
65
68
  // This function accepts the same arguments as DottedMap in the example above.
66
69
  const mapJsonString = getMapJSON({ height: 60, grid: 'diagonal' });
@@ -123,9 +126,10 @@ import DottedMap from 'dotted-map';
123
126
  const map = new DottedMap({
124
127
  height,
125
128
  width, // just specify either height or width, so the ratio of the map is correct
126
- countries: ['FRA'] // look into `countries.geo.json` to see which keys to use. You can also omit this parameter and the whole world will be used
129
+ countries: [FRA] // look into `countries.geo.json` to see which keys to use. You can also omit this parameter and the whole world will be used
127
130
  region: { lat: { min, max }, lng: { min, max } }, // if not present, it will fit the countries (and if no country is specified, the whole world)
128
- grid: 'vertical' | 'diagonal', // how points should be aligned
131
+ grid: vertical | diagonal’, // how points should be aligned
132
+ projection: { name, center }, // optional, see below
129
133
  avoidOuterPins: false | true, // if it’s true, prevent adding pins when they are outside of region/countries
130
134
  });
131
135
 
@@ -151,6 +155,39 @@ map.getSVG({
151
155
  // <svg><circle … /><circle …></svg>
152
156
  ```
153
157
 
158
+ ### Projection
159
+
160
+ By default, the map uses the Mercator projection. You can optionally pass a `projection` parameter to use a different one:
161
+
162
+ ```js
163
+ const map = new DottedMap({
164
+ height: 60,
165
+ grid: 'diagonal',
166
+ projection: { name: 'robinson' },
167
+ });
168
+ ```
169
+
170
+ Available projections: `mercator` (default), `equirectangular`, `robinson`, `equalEarth`, `mollweide`, `miller`, `sinusoidal`, `orthographic`, `gallPeters`, `vanDerGrinten`.
171
+
172
+ You can also pass a `center` to shift the map's center point. This is especially useful for `orthographic` (which shows a single hemisphere) but works with any projection:
173
+
174
+ ```js
175
+ // Orthographic projection centered on North America
176
+ const map = new DottedMap({
177
+ height: 60,
178
+ grid: 'diagonal',
179
+ projection: { name: 'orthographic', center: { lat: 40, lng: -100 } },
180
+ });
181
+
182
+ // Robinson projection centered on the Pacific
183
+ const map = new DottedMap({
184
+ height: 60,
185
+ projection: { name: 'robinson', center: { lat: 0, lng: 150 } },
186
+ });
187
+ ```
188
+
189
+ Note: for `orthographic`, pins on the back side of the globe (not visible) will be ignored.
190
+
154
191
  ## Acknowledgments
155
192
 
156
193
  Countries are from https://github.com/johan/world.geo.json.
@@ -0,0 +1,34 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ Object.defineProperty(exports, '__toESM', {
30
+ enumerable: true,
31
+ get: function () {
32
+ return __toESM;
33
+ }
34
+ });