aio-map 1.0.1 → 2.0.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.js +33 -6
- package/package.json +1 -3
package/index.js
CHANGED
|
@@ -9,16 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { divIcon } from "leaflet";
|
|
12
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
12
13
|
import { createContext, isValidElement, useContext, useEffect, useRef, useState } from "react";
|
|
13
14
|
import { Circle, FeatureGroup, LayersControl, MapContainer, Marker, Polyline, Rectangle, TileLayer, useMapEvents } from "react-leaflet";
|
|
14
15
|
import AIOInput from "aio-input";
|
|
15
|
-
import { AddToAttrs, JSXToHTML } from "aio-utils";
|
|
16
16
|
import 'leaflet/dist/leaflet.css';
|
|
17
17
|
import './index.css';
|
|
18
18
|
const MAPCTX = createContext({});
|
|
19
19
|
const AIMap = (props) => {
|
|
20
20
|
var _a;
|
|
21
|
-
const { value = [35.699939, 51.338497], getSearchResult,
|
|
21
|
+
const { value = [35.699939, 51.338497], getSearchResult, mapRef } = props;
|
|
22
22
|
const [map, setMap] = useState(null);
|
|
23
23
|
const [zoom, setZoom] = useState(((_a = props.zoom) === null || _a === void 0 ? void 0 : _a.value) || 14);
|
|
24
24
|
const lockChangeZoomState = useRef(false);
|
|
@@ -82,11 +82,11 @@ const MagnifyIcon = () => {
|
|
|
82
82
|
return (_jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, children: _jsx("path", { d: "M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" }) }));
|
|
83
83
|
};
|
|
84
84
|
const MapHeader = () => {
|
|
85
|
-
const { rootProps
|
|
85
|
+
const { rootProps } = useContext(MAPCTX);
|
|
86
86
|
const { getSearchResult, onSearch } = rootProps;
|
|
87
87
|
const [searchValue, setSearchValue] = useState('');
|
|
88
88
|
const [searchResult, setSerachResult] = useState([]);
|
|
89
|
-
const timeout = useRef();
|
|
89
|
+
const timeout = useRef(undefined);
|
|
90
90
|
function changeSearch(searchValue) {
|
|
91
91
|
setSearchValue(searchValue);
|
|
92
92
|
clearTimeout(timeout.current);
|
|
@@ -161,7 +161,7 @@ const MapMarker = ({ pos, html, eventHandlers }) => {
|
|
|
161
161
|
};
|
|
162
162
|
function MapEvents() {
|
|
163
163
|
const { rootProps, move, changeZoom } = useContext(MAPCTX);
|
|
164
|
-
|
|
164
|
+
useMapEvents({
|
|
165
165
|
click: () => rootProps.onClick ? rootProps.onClick() : undefined,
|
|
166
166
|
move: (e) => {
|
|
167
167
|
if (rootProps.dragging === false) {
|
|
@@ -181,8 +181,35 @@ function MapEvents() {
|
|
|
181
181
|
rootProps.onMoveEnd(e);
|
|
182
182
|
}
|
|
183
183
|
},
|
|
184
|
-
movestart: (
|
|
184
|
+
movestart: () => {
|
|
185
185
|
}
|
|
186
186
|
});
|
|
187
187
|
return null;
|
|
188
188
|
}
|
|
189
|
+
function JSXToHTML(jsx) {
|
|
190
|
+
return ReactDOMServer.renderToStaticMarkup(jsx);
|
|
191
|
+
}
|
|
192
|
+
function classListToString(classes) {
|
|
193
|
+
let list = [];
|
|
194
|
+
const getClasses = (cls) => {
|
|
195
|
+
if (Array.isArray(cls)) {
|
|
196
|
+
return cls.filter((o) => !!o && typeof o === 'string');
|
|
197
|
+
}
|
|
198
|
+
if (typeof cls === 'string') {
|
|
199
|
+
return cls.split(' ');
|
|
200
|
+
}
|
|
201
|
+
return [];
|
|
202
|
+
};
|
|
203
|
+
for (let i = 0; i < classes.length; i++) {
|
|
204
|
+
const cls = classes[i];
|
|
205
|
+
list = [...list, ...getClasses(cls)];
|
|
206
|
+
}
|
|
207
|
+
return list.length ? list.join(' ') : '';
|
|
208
|
+
}
|
|
209
|
+
function AddToAttrs(attrs, p) {
|
|
210
|
+
attrs = attrs || {};
|
|
211
|
+
let { style } = p;
|
|
212
|
+
const className = classListToString([attrs.className, p.className]);
|
|
213
|
+
let newStyle = Object.assign(Object.assign({}, attrs.style), style);
|
|
214
|
+
return Object.assign(Object.assign(Object.assign({}, attrs), { className, style: newStyle }), p.attrs);
|
|
215
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-map",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
"url": "git+https://github.com/mohammadFeiz/aio-map.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"jquery": "^3.6.1",
|
|
16
|
-
"aio-utils": "latest",
|
|
17
15
|
"leaflet": "^1.9.4",
|
|
18
16
|
"react-leaflet": "^4.2.1",
|
|
19
17
|
"aio-input":"latest"
|