Release v2.0.0
This commit is contained in:
+3
-1
@@ -1,2 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
test.js
|
test.js
|
||||||
|
*.svg
|
||||||
|
dist/
|
||||||
Vendored
+12
-2
@@ -1,9 +1,14 @@
|
|||||||
namespace DottedMapLib {
|
namespace DottedMapLib {
|
||||||
|
interface Region {
|
||||||
|
lat: { min: number; max: number };
|
||||||
|
lng: { min: number; max: number };
|
||||||
|
}
|
||||||
|
|
||||||
interface Settings {
|
interface Settings {
|
||||||
height?: number;
|
height?: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
countries?: string[];
|
countries?: string[];
|
||||||
region?: { lat: { min: number; max: number }; lng: { min: number; max: number } };
|
region?: Region;
|
||||||
grid?: 'vertical' | 'diagonal';
|
grid?: 'vertical' | 'diagonal';
|
||||||
avoidOuterPins?: false | true;
|
avoidOuterPins?: false | true;
|
||||||
}
|
}
|
||||||
@@ -38,7 +43,12 @@ namespace DottedMapLib {
|
|||||||
export default class DottedMap {
|
export default class DottedMap {
|
||||||
constructor(settings: DottedMapLib.Settings);
|
constructor(settings: DottedMapLib.Settings);
|
||||||
|
|
||||||
addPin(pin: DottedMapLib.Pin): void;
|
addPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
|
||||||
getPoints(): DottedMapLib.Point[];
|
getPoints(): DottedMapLib.Point[];
|
||||||
getSVG(settings: DottedMapLib.SvgSettings): string;
|
getSVG(settings: DottedMapLib.SvgSettings): string;
|
||||||
|
image: {
|
||||||
|
region: DottedMap.Region;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+2433
-21
File diff suppressed because it is too large
Load Diff
+9
-6
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "dotted-map",
|
"name": "dotted-map",
|
||||||
"version": "1.3.0",
|
"version": "2.0.0",
|
||||||
"description": "Create a SVG map filled with dots for the world or countries",
|
"description": "Create a SVG map filled with dots for the world or countries",
|
||||||
"main": "index.js",
|
"main": "dist/dotted-map.js",
|
||||||
|
"module": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"build": "webpack"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"map",
|
"map",
|
||||||
@@ -15,14 +16,16 @@
|
|||||||
"countries",
|
"countries",
|
||||||
"country"
|
"country"
|
||||||
],
|
],
|
||||||
"author": "",
|
"author": "Basile Bruneau <basile@bruneau.email>",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@turf/boolean-point-in-polygon": "^6.0.1",
|
"@turf/boolean-point-in-polygon": "^6.0.1",
|
||||||
"proj4": "^2.6.1"
|
"proj4": "^2.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^2.0.5"
|
"prettier": "^2.0.5",
|
||||||
|
"webpack": "^5.33.2",
|
||||||
|
"webpack-cli": "^4.6.0"
|
||||||
},
|
},
|
||||||
"sideEffects": false
|
"sideEffects": false
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-6
@@ -1,6 +1,12 @@
|
|||||||
const proj4 = require('proj4');
|
import proj4 from 'proj4';
|
||||||
const inside = require('@turf/boolean-point-in-polygon').default;
|
import inside from '@turf/boolean-point-in-polygon';
|
||||||
const geojsonWorld = require('./countries.geo.json');
|
import geojsonWorld from './countries.geo.json';
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// [ ] Handle prefill cache →
|
||||||
|
// [ ] Method to export a cache
|
||||||
|
// [ ] Method to import a cache
|
||||||
|
// [ ] Make two exports: one with countries, one without (reduce bundle size)
|
||||||
|
|
||||||
const geojsonByCountry = geojsonWorld.features.reduce((countries, feature) => {
|
const geojsonByCountry = geojsonWorld.features.reduce((countries, feature) => {
|
||||||
countries[feature.id] = feature;
|
countries[feature.id] = feature;
|
||||||
@@ -119,7 +125,7 @@ function DottedMap({ height = 0, width = 0, countries = [], region, grid = 'vert
|
|||||||
addPin({ lat, lng, data, svgOptions }) {
|
addPin({ lat, lng, data, svgOptions }) {
|
||||||
const [googleX, googleY] = proj4(proj4.defs('GOOGLE'), [lng, lat]);
|
const [googleX, googleY] = proj4(proj4.defs('GOOGLE'), [lng, lat]);
|
||||||
if (avoidOuterPins) {
|
if (avoidOuterPins) {
|
||||||
const wgs84Point = proj4(proj4.defs('GOOGLE'), proj4.defs('WGS84'), [googleX, googleY])
|
const wgs84Point = proj4(proj4.defs('GOOGLE'), proj4.defs('WGS84'), [googleX, googleY]);
|
||||||
if (!inside(wgs84Point, poly)) return;
|
if (!inside(wgs84Point, poly)) return;
|
||||||
}
|
}
|
||||||
let [rawX, rawY] = [(width * (googleX - X_MIN)) / X_RANGE, (height * (Y_MAX - googleY)) / Y_RANGE];
|
let [rawX, rawY] = [(width * (googleX - X_MIN)) / X_RANGE, (height * (Y_MAX - googleY)) / Y_RANGE];
|
||||||
@@ -133,7 +139,11 @@ function DottedMap({ height = 0, width = 0, countries = [], region, grid = 'vert
|
|||||||
localx += 0.5;
|
localx += 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
points[[x, y].join(';')] = { x: localx, y: localy, data, svgOptions };
|
const point = { x: localx, y: localy, data, svgOptions };
|
||||||
|
|
||||||
|
points[[x, y].join(';')] = point;
|
||||||
|
|
||||||
|
return point;
|
||||||
},
|
},
|
||||||
getPoints() {
|
getPoints() {
|
||||||
return Object.values(points);
|
return Object.values(points);
|
||||||
@@ -165,7 +175,12 @@ function DottedMap({ height = 0, width = 0, countries = [], region, grid = 'vert
|
|||||||
${Object.values(points).map(getPoint).join('\n')}
|
${Object.values(points).map(getPoint).join('\n')}
|
||||||
</svg>`;
|
</svg>`;
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
region,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DottedMap;
|
export default DottedMap;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './src/index.js',
|
||||||
|
mode: 'production',
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
filename: 'dotted-map.js',
|
||||||
|
library: {
|
||||||
|
name: 'dotted-map',
|
||||||
|
type: 'umd',
|
||||||
|
},
|
||||||
|
globalObject: 'this',
|
||||||
|
clean: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user