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