dotted-map 2.1.1 → 2.2.3
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/.github/workflows/publish.yml +22 -0
- package/README.md +82 -6
- package/index.d.ts +3 -0
- package/index.js +1 -1
- package/package.json +3 -2
- package/src/without-countries.js +18 -3
- package/without-countries.d.ts +5 -0
- package/without-countries.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotted-map",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Create a SVG map filled with dots for the world or countries",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"module": "./src/with-countries.js",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "webpack"
|
|
12
|
+
"build": "webpack",
|
|
13
|
+
"test": "node test.js"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"map",
|
package/src/without-countries.js
CHANGED
|
@@ -17,6 +17,14 @@ function DottedMapWithoutCountries({ map, avoidOuterPins = false }) {
|
|
|
17
17
|
|
|
18
18
|
return {
|
|
19
19
|
addPin({ lat, lng, data, svgOptions }) {
|
|
20
|
+
const pin = this.getPin({ lat, lng });
|
|
21
|
+
const point = { ...pin, data, svgOptions };
|
|
22
|
+
|
|
23
|
+
points[[point.x, point.y].join(';')] = point;
|
|
24
|
+
|
|
25
|
+
return point;
|
|
26
|
+
},
|
|
27
|
+
getPin({ lat, lng }) {
|
|
20
28
|
const [googleX, googleY] = proj4(proj4.defs('GOOGLE'), [lng, lat]);
|
|
21
29
|
if (avoidOuterPins) {
|
|
22
30
|
const wgs84Point = proj4(proj4.defs('GOOGLE'), proj4.defs('WGS84'), [
|
|
@@ -39,11 +47,18 @@ function DottedMapWithoutCountries({ map, avoidOuterPins = false }) {
|
|
|
39
47
|
localx += 0.5;
|
|
40
48
|
}
|
|
41
49
|
|
|
42
|
-
const
|
|
50
|
+
const [localLng, localLat] = proj4(
|
|
51
|
+
proj4.defs('GOOGLE'),
|
|
52
|
+
proj4.defs('WGS84'),
|
|
53
|
+
[
|
|
54
|
+
(localx * X_RANGE) / width + X_MIN,
|
|
55
|
+
Y_MAX - (localy * Y_RANGE) / height,
|
|
56
|
+
],
|
|
57
|
+
);
|
|
43
58
|
|
|
44
|
-
|
|
59
|
+
const pin = { x: localx, y: localy, lat: localLat, lng: localLng };
|
|
45
60
|
|
|
46
|
-
return
|
|
61
|
+
return pin;
|
|
47
62
|
},
|
|
48
63
|
getPoints() {
|
|
49
64
|
return Object.values(points);
|
package/without-countries.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ namespace DottedMapWithoutCountriesLib {
|
|
|
44
44
|
type Point = {
|
|
45
45
|
x: number;
|
|
46
46
|
y: number;
|
|
47
|
+
lat: number;
|
|
48
|
+
lng: number;
|
|
47
49
|
data?: any;
|
|
48
50
|
svgOptions?: SvgOptions;
|
|
49
51
|
};
|
|
@@ -55,6 +57,9 @@ export default class DottedMapWithoutCountries {
|
|
|
55
57
|
addPin(
|
|
56
58
|
pin: DottedMapWithoutCountriesLib.Pin,
|
|
57
59
|
): DottedMapWithoutCountriesLib.Point;
|
|
60
|
+
getPin(
|
|
61
|
+
pin: DottedMapWithoutCountriesLib.Pin,
|
|
62
|
+
): DottedMapWithoutCountriesLib.Point;
|
|
58
63
|
getPoints(): DottedMapWithoutCountriesLib.Point[];
|
|
59
64
|
getSVG(settings: DottedMapWithoutCountriesLib.SvgSettings): string;
|
|
60
65
|
image: {
|
package/without-countries.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(o,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("proj4"),require("@turf/boolean-point-in-polygon")):"function"==typeof define&&define.amd?define(["proj4","@turf/boolean-point-in-polygon"],e):"object"==typeof exports?exports["dotted-map"]=e(require("proj4"),require("@turf/boolean-point-in-polygon")):o["dotted-map"]=e(o.proj4,o["@turf/boolean-point-in-polygon"])}(this,(function(o,e){return(()=>{"use strict";var t={620:o=>{o.exports=e},25:e=>{e.exports=o}},
|
|
1
|
+
!function(o,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("proj4"),require("@turf/boolean-point-in-polygon")):"function"==typeof define&&define.amd?define(["proj4","@turf/boolean-point-in-polygon"],e):"object"==typeof exports?exports["dotted-map"]=e(require("proj4"),require("@turf/boolean-point-in-polygon")):o["dotted-map"]=e(o.proj4,o["@turf/boolean-point-in-polygon"])}(this,(function(o,e){return(()=>{"use strict";var t={620:o=>{o.exports=e},25:e=>{e.exports=o}},n={};function r(o){var e=n[o];if(void 0!==e)return e.exports;var i=n[o]={exports:{}};return t[o](i,i.exports,r),i.exports}r.n=o=>{var e=o&&o.__esModule?()=>o.default:()=>o;return r.d(e,{a:e}),e},r.d=(o,e)=>{for(var t in e)r.o(e,t)&&!r.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:e[t]})},r.o=(o,e)=>Object.prototype.hasOwnProperty.call(o,e),r.r=o=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})};var i={};return(()=>{r.r(i),r.d(i,{default:()=>a});var o=r(25),e=r.n(o),t=r(620),n=r.n(t);const a=function({map:o,avoidOuterPins:t=!1}){const{points:r,X_MIN:i,Y_MAX:a,X_RANGE:s,Y_RANGE:l,region:p,grid:u,width:d,height:c,ystep:f}=o;return{addPin({lat:o,lng:e,data:t,svgOptions:n}){const i={...this.getPin({lat:o,lng:e}),data:t,svgOptions:n};return r[[i.x,i.y].join(";")]=i,i},getPin({lat:o,lng:r}){const[p,g]=e()(e().defs("GOOGLE"),[r,o]);if(t){const o=e()(e().defs("GOOGLE"),e().defs("WGS84"),[p,g]);if(!n()(o,poly))return}let[y,v]=[d*(p-i)/s,c*(a-g)/l];const b=Math.round(v/f);b%2==0&&"diagonal"===u&&(y-=.5);const j=Math.round(y);let[x,O]=[j,Math.round(b)*f];b%2==0&&"diagonal"===u&&(x+=.5);const[h,m]=e()(e().defs("GOOGLE"),e().defs("WGS84"),[x*s/d+i,a-O*l/c]);return{x,y:O,lat:m,lng:h}},getPoints:()=>Object.values(r),getSVG:({shape:o="circle",color:e="current",backgroundColor:t="transparent",radius:n=.5})=>`<svg viewBox="0 0 ${d} ${c}" xmlns="http://www.w3.org/2000/svg" style="background-color: ${t}">\n ${Object.values(r).map((({x:t,y:r,svgOptions:i={}})=>{const a=i.radius||n;if("circle"===o)return`<circle cx="${t}" cy="${r}" r="${a}" fill="${i.color||e}" />`;if("hexagon"===o){const o=Math.sqrt(3)*a;return`<polyline points="${[[t+o,r-a],[t+o,r+a],[t,r+2*a],[t-o,r+a],[t-o,r-a],[t,r-2*a]].map((o=>o.join(","))).join(" ")}" fill="${i.color||e}" />`}})).join("\n")}\n </svg>`,image:{region:p,width:d,height:c}}}})(),i})()}));
|