aio-map 3.0.1 → 3.2.0
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/index.d.ts +3 -1
- package/index.js +12 -5
- package/package.json +3 -2
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FC, ReactNode } from "react";
|
|
|
2
2
|
import * as Leaflet from 'leaflet';
|
|
3
3
|
import 'leaflet/dist/leaflet.css';
|
|
4
4
|
import './index.css';
|
|
5
|
-
type I_pos = [number, number];
|
|
5
|
+
export type I_pos = [number, number];
|
|
6
6
|
export type I_marker = {
|
|
7
7
|
pos: [number, number];
|
|
8
8
|
html?: ReactNode;
|
|
@@ -41,6 +41,7 @@ type I_Map = {
|
|
|
41
41
|
onChangePos?: (coords: I_pos) => void;
|
|
42
42
|
onChangeZoom?: (newZoom: number) => void;
|
|
43
43
|
pos?: I_pos;
|
|
44
|
+
delay?: number;
|
|
44
45
|
zoom?: number;
|
|
45
46
|
zoomOptions?: {
|
|
46
47
|
wheel?: boolean;
|
|
@@ -85,3 +86,4 @@ type I_searchResult = {
|
|
|
85
86
|
before?: ReactNode;
|
|
86
87
|
after?: ReactNode;
|
|
87
88
|
};
|
|
89
|
+
export declare const smooth: (points: [number, number][], acc?: 'low' | 'medium' | 'high') => any;
|
package/index.js
CHANGED
|
@@ -16,10 +16,11 @@ import MarkerClusterGroup from "react-leaflet-cluster";
|
|
|
16
16
|
import AIOInput from "aio-input";
|
|
17
17
|
import 'leaflet/dist/leaflet.css';
|
|
18
18
|
import './index.css';
|
|
19
|
-
import { Debounce } from
|
|
19
|
+
import { Debounce } from 'aio-utils';
|
|
20
|
+
import simplify from 'simplify-js';
|
|
20
21
|
const MAPCTX = createContext({});
|
|
21
22
|
const AIMap = (props) => {
|
|
22
|
-
const { pos: propsPos = [35.699939, 51.338497], getSearchResult, mapRef, zoom: propsZoom = 14, onChangePos = () => { } } = props;
|
|
23
|
+
const { pos: propsPos = [35.699939, 51.338497], getSearchResult, mapRef, zoom: propsZoom = 14, onChangePos = () => { }, delay = 500 } = props;
|
|
23
24
|
const [map, setMap] = useState(null);
|
|
24
25
|
const [z, setZoom] = useState(propsZoom);
|
|
25
26
|
const zoomRef = useRef(z);
|
|
@@ -51,13 +52,13 @@ const AIMap = (props) => {
|
|
|
51
52
|
}
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
const changePos = (newPos) => {
|
|
55
56
|
if (newPos[0] === posRef.current[0] && newPos[1] === posRef.current[1]) {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
setPos(newPos);
|
|
59
|
-
Debounce(() => onChangePos(
|
|
60
|
-
}
|
|
60
|
+
Debounce(() => onChangePos(newPos), delay);
|
|
61
|
+
};
|
|
61
62
|
function getDefaultMarkerIcon() {
|
|
62
63
|
return _jsxs("div", { className: 'marker-icon', children: [_jsx("div", { className: 'marker-icon-circle' }), _jsx("div", { className: 'marker-icon-arrow' })] });
|
|
63
64
|
}
|
|
@@ -218,3 +219,9 @@ function AddToAttrs(attrs, p) {
|
|
|
218
219
|
let newStyle = Object.assign(Object.assign({}, attrs.style), style);
|
|
219
220
|
return Object.assign(Object.assign(Object.assign({}, attrs), { className, style: newStyle }), p.attrs);
|
|
220
221
|
}
|
|
222
|
+
export const smooth = (points, acc) => {
|
|
223
|
+
acc = acc || 'medium';
|
|
224
|
+
const points2D = points.map((p) => ({ x: p[1], y: p[0] })); // simplify-js با x,y کار میکنه
|
|
225
|
+
const simplified = simplify(points2D, acc === 'low' ? 0.001 : (acc === 'medium' ? 0.002 : 0.003), true); // 10 = tolerance (متر تقریبی), true = highQuality
|
|
226
|
+
return simplified.map(p => ([p.y, p.x]));
|
|
227
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-map",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"aio-input": "latest",
|
|
17
17
|
"leaflet": "^1.9.4",
|
|
18
18
|
"react-leaflet": "^5.0.0",
|
|
19
|
-
"react-leaflet-cluster": "^2.1.0"
|
|
19
|
+
"react-leaflet-cluster": "^2.1.0",
|
|
20
|
+
"simplify-js": "^1.2.4"
|
|
20
21
|
},
|
|
21
22
|
"author": "mohammad sharif feiz feiz.ms@gmail.com",
|
|
22
23
|
"license": "ISC",
|