feat: add getPin method
This commit is contained in:
Vendored
+3
@@ -38,6 +38,8 @@ namespace DottedMapLib {
|
||||
type Point = {
|
||||
x: number;
|
||||
y: number;
|
||||
lat: number;
|
||||
lng: number;
|
||||
data?: any;
|
||||
svgOptions?: SvgOptions;
|
||||
};
|
||||
@@ -49,6 +51,7 @@ export default class DottedMap {
|
||||
constructor(settings: DottedMapLib.Settings);
|
||||
|
||||
addPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
|
||||
getPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
|
||||
getPoints(): DottedMapLib.Point[];
|
||||
getSVG(settings: DottedMapLib.SvgSettings): string;
|
||||
image: {
|
||||
|
||||
Generated
+3
-2
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "dotted-map",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"version": "2.1.0",
|
||||
"name": "dotted-map",
|
||||
"version": "2.2.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@turf/boolean-point-in-polygon": "^6.0.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dotted-map",
|
||||
"version": "2.1.1",
|
||||
"version": "2.2.0",
|
||||
"description": "Create a SVG map filled with dots for the world or countries",
|
||||
"main": "./index.js",
|
||||
"exports": {
|
||||
|
||||
@@ -17,6 +17,14 @@ function DottedMapWithoutCountries({ map, avoidOuterPins = false }) {
|
||||
|
||||
return {
|
||||
addPin({ lat, lng, data, svgOptions }) {
|
||||
const pin = getPin({ lat, lng });
|
||||
const point = { ...pin, data, svgOptions };
|
||||
|
||||
points[[x, y].join(';')] = point;
|
||||
|
||||
return point;
|
||||
},
|
||||
getPin({ lat, lng }) {
|
||||
const [googleX, googleY] = proj4(proj4.defs('GOOGLE'), [lng, lat]);
|
||||
if (avoidOuterPins) {
|
||||
const wgs84Point = proj4(proj4.defs('GOOGLE'), proj4.defs('WGS84'), [
|
||||
@@ -39,11 +47,15 @@ function DottedMapWithoutCountries({ map, avoidOuterPins = false }) {
|
||||
localx += 0.5;
|
||||
}
|
||||
|
||||
const point = { x: localx, y: localy, data, svgOptions };
|
||||
const [localLng, localLat] = proj4(
|
||||
proj4.defs('GOOGLE'),
|
||||
proj4.defs('WGS84'),
|
||||
[localx, localy],
|
||||
);
|
||||
|
||||
points[[x, y].join(';')] = point;
|
||||
const pin = { x: localx, y: localy, lat: localLat, lng: localLng };
|
||||
|
||||
return point;
|
||||
return pin;
|
||||
},
|
||||
getPoints() {
|
||||
return Object.values(points);
|
||||
|
||||
Vendored
+5
@@ -44,6 +44,8 @@ namespace DottedMapWithoutCountriesLib {
|
||||
type Point = {
|
||||
x: number;
|
||||
y: number;
|
||||
lat: number;
|
||||
lng: number;
|
||||
data?: any;
|
||||
svgOptions?: SvgOptions;
|
||||
};
|
||||
@@ -55,6 +57,9 @@ export default class DottedMapWithoutCountries {
|
||||
addPin(
|
||||
pin: DottedMapWithoutCountriesLib.Pin,
|
||||
): DottedMapWithoutCountriesLib.Point;
|
||||
getPin(
|
||||
pin: DottedMapWithoutCountriesLib.Pin,
|
||||
): DottedMapWithoutCountriesLib.Point;
|
||||
getPoints(): DottedMapWithoutCountriesLib.Point[];
|
||||
getSVG(settings: DottedMapWithoutCountriesLib.SvgSettings): string;
|
||||
image: {
|
||||
|
||||
Reference in New Issue
Block a user