dotted-map 1.3.0 → 2.2.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 +21 -0
- package/README.md +82 -6
- package/index.d.ts +21 -3
- package/index.js +1 -171
- package/package.json +13 -6
- package/{countries.geo.json → src/countries.geo.json} +0 -0
- package/src/with-countries.js +180 -0
- package/src/without-countries.js +105 -0
- package/webpack.config.js +37 -0
- package/without-countries.d.ts +70 -0
- package/without-countries.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Basile Bruneau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -26,23 +26,99 @@ npm i dotted-map
|
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
28
|
const fs = require('fs');
|
|
29
|
-
const DottedMap = require('dotted-map');
|
|
29
|
+
const DottedMap = require('dotted-map').default;
|
|
30
|
+
// Or in the browser: import DottedMap from 'dotted-map';
|
|
30
31
|
|
|
31
32
|
const map = new DottedMap({ height: 60, grid: 'diagonal' });
|
|
32
33
|
|
|
33
|
-
map.addPin({
|
|
34
|
-
|
|
34
|
+
map.addPin({
|
|
35
|
+
lat: 40.73061,
|
|
36
|
+
lng: -73.935242,
|
|
37
|
+
svgOptions: { color: '#d6ff79', radius: 0.4 },
|
|
38
|
+
});
|
|
39
|
+
map.addPin({
|
|
40
|
+
lat: 48.8534,
|
|
41
|
+
lng: 2.3488,
|
|
42
|
+
svgOptions: { color: '#fffcf2', radius: 0.4 },
|
|
43
|
+
});
|
|
35
44
|
|
|
36
|
-
const svgMap = map.getSVG({
|
|
45
|
+
const svgMap = map.getSVG({
|
|
46
|
+
radius: 0.22,
|
|
47
|
+
color: '#423B38',
|
|
48
|
+
shape: 'circle',
|
|
49
|
+
backgroundColor: '#020300',
|
|
50
|
+
});
|
|
37
51
|
|
|
38
52
|
fs.writeFileSync('./map.svg', svgMap);
|
|
39
53
|
```
|
|
40
54
|
|
|
41
|
-
|
|
55
|
+
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
|
+
### Precomputing the map
|
|
58
|
+
|
|
59
|
+
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
|
+
|
|
61
|
+
```js
|
|
62
|
+
// So you do this first step only once, when developing your app
|
|
63
|
+
const getMapJSON = require('dotted-map').getMapJSON;
|
|
64
|
+
|
|
65
|
+
// This function accepts the same arguments as DottedMap in the example above.
|
|
66
|
+
const mapJsonString = getMapJSON({ height: 60, grid: 'diagonal' });
|
|
67
|
+
console.log(mapJsonString);
|
|
68
|
+
|
|
69
|
+
// This string will contain everything about the grid. You will need to copy
|
|
70
|
+
// and include it in your front.
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
// Now we are in your app, let’s imagine it’s a React app
|
|
75
|
+
|
|
76
|
+
// This import doesn’t include coordinates of countries: it’s lighter
|
|
77
|
+
// that 'dotted-map', so especially useful in fronts.
|
|
78
|
+
// However, you must give it a map you have pre-computed before.
|
|
79
|
+
import DottedMap from 'dotted-map/without-countries';
|
|
80
|
+
|
|
81
|
+
// Basically myMap.js contains something like:
|
|
82
|
+
//
|
|
83
|
+
// const MyMapString = 'the string mapJsonString that you got on the first step';
|
|
84
|
+
// export default MyMapString;
|
|
85
|
+
import MyMapString from './myMap';
|
|
86
|
+
|
|
87
|
+
const MyComponent = () => {
|
|
88
|
+
// It’s safe to re-create the map at each render, because of the
|
|
89
|
+
// pre-computation it’s super fast ⚡️
|
|
90
|
+
const map = new DottedMap({ map: JSON.parse(MyMapString) });
|
|
91
|
+
|
|
92
|
+
map.addPin({
|
|
93
|
+
lat: 40.73061,
|
|
94
|
+
lng: -73.935242,
|
|
95
|
+
svgOptions: { color: '#d6ff79', radius: 0.4 },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const svgMap = map.getSVG({
|
|
99
|
+
radius: 0.22,
|
|
100
|
+
color: '#423B38',
|
|
101
|
+
shape: 'circle',
|
|
102
|
+
backgroundColor: '#020300',
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div>
|
|
107
|
+
<img src={`data:image/svg+xml;utf8,${encodeURIComponent(svgMap)}`} />
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default MyComponent;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
That’s how you can display a super stylish map in your React webapp, without impacting the size of your bundle nor the performance of your app (browsers are very fast at rendering SVGs).
|
|
42
116
|
|
|
43
117
|
## Specs
|
|
44
118
|
|
|
45
119
|
```js
|
|
120
|
+
import DottedMap from 'dotted-map';
|
|
121
|
+
|
|
46
122
|
// Create the map
|
|
47
123
|
const map = new DottedMap({
|
|
48
124
|
height,
|
|
@@ -50,7 +126,7 @@ const map = new DottedMap({
|
|
|
50
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
|
|
51
127
|
region: { lat: { min, max }, lng: { min, max } }, // if not present, it will fit the countries (and if no country is specified, the whole world)
|
|
52
128
|
grid: 'vertical' | 'diagonal', // how points should be aligned
|
|
53
|
-
avoidOuterPins: false | true, // if it
|
|
129
|
+
avoidOuterPins: false | true, // if it’s true, prevent adding pins when they are outside of region/countries
|
|
54
130
|
});
|
|
55
131
|
|
|
56
132
|
// Add some points/change the color of existing points
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
namespace DottedMapLib {
|
|
2
|
-
interface
|
|
2
|
+
interface Region {
|
|
3
|
+
lat: { min: number; max: number };
|
|
4
|
+
lng: { min: number; max: number };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface MapSettings {
|
|
3
8
|
height?: number;
|
|
4
9
|
width?: number;
|
|
5
10
|
countries?: string[];
|
|
6
|
-
region?:
|
|
11
|
+
region?: Region;
|
|
7
12
|
grid?: 'vertical' | 'diagonal';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Settings extends MapSettings {
|
|
8
16
|
avoidOuterPins?: false | true;
|
|
9
17
|
}
|
|
10
18
|
|
|
@@ -30,15 +38,25 @@ namespace DottedMapLib {
|
|
|
30
38
|
type Point = {
|
|
31
39
|
x: number;
|
|
32
40
|
y: number;
|
|
41
|
+
lat: number;
|
|
42
|
+
lng: number;
|
|
33
43
|
data?: any;
|
|
34
44
|
svgOptions?: SvgOptions;
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
47
|
|
|
48
|
+
export const getMapJSON: (settings: DottedMapLib.MapSettings) => string;
|
|
49
|
+
|
|
38
50
|
export default class DottedMap {
|
|
39
51
|
constructor(settings: DottedMapLib.Settings);
|
|
40
52
|
|
|
41
|
-
addPin(pin: DottedMapLib.Pin):
|
|
53
|
+
addPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
|
|
54
|
+
getPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
|
|
42
55
|
getPoints(): DottedMapLib.Point[];
|
|
43
56
|
getSVG(settings: DottedMapLib.SvgSettings): string;
|
|
57
|
+
image: {
|
|
58
|
+
region: DottedMap.Region;
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
44
62
|
}
|