Release v2.0.0
This commit is contained in:
+3
-1
@@ -1,2 +1,4 @@
|
||||
node_modules/
|
||||
test.js
|
||||
test.js
|
||||
*.svg
|
||||
dist/
|
||||
Vendored
+12
-2
@@ -1,9 +1,14 @@
|
||||
namespace DottedMapLib {
|
||||
interface Region {
|
||||
lat: { min: number; max: number };
|
||||
lng: { min: number; max: number };
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
height?: number;
|
||||
width?: number;
|
||||
countries?: string[];
|
||||
region?: { lat: { min: number; max: number }; lng: { min: number; max: number } };
|
||||
region?: Region;
|
||||
grid?: 'vertical' | 'diagonal';
|
||||
avoidOuterPins?: false | true;
|
||||
}
|
||||
@@ -38,7 +43,12 @@ namespace DottedMapLib {
|
||||
export default class DottedMap {
|
||||
constructor(settings: DottedMapLib.Settings);
|
||||
|
||||
addPin(pin: DottedMapLib.Pin): void;
|
||||
addPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
|
||||
getPoints(): DottedMapLib.Point[];
|
||||
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",
|
||||
"version": "1.3.0",
|
||||
"version": "2.0.0",
|
||||
"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": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"build": "webpack"
|
||||
},
|
||||
"keywords": [
|
||||
"map",
|
||||
@@ -15,14 +16,16 @@
|
||||
"countries",
|
||||
"country"
|
||||
],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"author": "Basile Bruneau <basile@bruneau.email>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@turf/boolean-point-in-polygon": "^6.0.1",
|
||||
"proj4": "^2.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.0.5"
|
||||
"prettier": "^2.0.5",
|
||||
"webpack": "^5.33.2",
|
||||
"webpack-cli": "^4.6.0"
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
|
||||
+21
-6
@@ -1,6 +1,12 @@
|
||||
const proj4 = require('proj4');
|
||||
const inside = require('@turf/boolean-point-in-polygon').default;
|
||||
const geojsonWorld = require('./countries.geo.json');
|
||||
import proj4 from 'proj4';
|
||||
import inside from '@turf/boolean-point-in-polygon';
|
||||
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) => {
|
||||
countries[feature.id] = feature;
|
||||
@@ -119,7 +125,7 @@ function DottedMap({ height = 0, width = 0, countries = [], region, grid = 'vert
|
||||
addPin({ lat, lng, data, svgOptions }) {
|
||||
const [googleX, googleY] = proj4(proj4.defs('GOOGLE'), [lng, lat]);
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
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')}
|
||||
</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