aio-map 3.2.0 → 3.2.2

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.
Files changed (3) hide show
  1. package/index.d.ts +9 -1
  2. package/index.js +14 -2
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -36,7 +36,7 @@ export type I_polyline = {
36
36
  style?: I_shapeStyle;
37
37
  };
38
38
  export type I_shape = I_circle | I_rect | I_polyline;
39
- type I_Map = {
39
+ export type I_Map = {
40
40
  children?: React.ReactNode;
41
41
  onChangePos?: (coords: I_pos) => void;
42
42
  onChangeZoom?: (newZoom: number) => void;
@@ -64,6 +64,7 @@ type I_Map = {
64
64
  whenReady?: () => void;
65
65
  onMoveEnd?: (e: Leaflet.LeafletEvent) => void;
66
66
  actionsRef?: any;
67
+ tileAttrs?: any;
67
68
  };
68
69
  export type I_layers = {
69
70
  position: 'topright' | 'topleft';
@@ -87,3 +88,10 @@ type I_searchResult = {
87
88
  after?: ReactNode;
88
89
  };
89
90
  export declare const smooth: (points: [number, number][], acc?: 'low' | 'medium' | 'high') => any;
91
+ export declare function getCenterOfPoints(points: {
92
+ lat: number;
93
+ lng: number;
94
+ }[]): {
95
+ lat: number;
96
+ lng: number;
97
+ };
package/index.js CHANGED
@@ -15,9 +15,9 @@ import * as ReactLeaflet from 'react-leaflet';
15
15
  import MarkerClusterGroup from "react-leaflet-cluster";
16
16
  import AIOInput from "aio-input";
17
17
  import 'leaflet/dist/leaflet.css';
18
- import './index.css';
19
18
  import { Debounce } from 'aio-utils';
20
19
  import simplify from 'simplify-js';
20
+ import './index.css';
21
21
  const MAPCTX = createContext({});
22
22
  const AIMap = (props) => {
23
23
  const { pos: propsPos = [35.699939, 51.338497], getSearchResult, mapRef, zoom: propsZoom = 14, onChangePos = () => { }, delay = 500 } = props;
@@ -81,7 +81,7 @@ const MapBody = () => {
81
81
  const { rootProps, pos, setMap, getDefaultMarkerIcon, zoom } = useContext(MAPCTX);
82
82
  const { mapStyle, dragging = true, children, shapes = [], marker, markers = [], whenReady } = rootProps;
83
83
  const defaultStyle = { width: '100%', height: '100%' };
84
- return (_jsxs(ReactLeaflet.MapContainer, { center: pos, style: Object.assign(Object.assign({}, defaultStyle), mapStyle), zoom: zoom, scrollWheelZoom: ((_a = rootProps.zoomOptions) === null || _a === void 0 ? void 0 : _a.wheel) ? 'center' : undefined, zoomControl: ((_b = rootProps.zoomOptions) === null || _b === void 0 ? void 0 : _b.control) !== false, attributionControl: true, dragging: dragging, ref: setMap, whenReady: whenReady, children: [_jsx(ReactLeaflet.TileLayer, { url: "https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" }), _jsx(MapEvents, {}), marker !== false && _jsx(MapMarker, { pos: pos, html: isValidElement(marker) ? marker : getDefaultMarkerIcon() }, 'main-marker'), _jsx(MarkerClusterGroup, { chunkedLoading: true, showCoverageOnHover: false, children: markers.map((marker, i) => _jsx(MapMarker, { pos: marker.pos, html: marker.html, eventHandlers: marker.eventHandlers }, `marker-${i}`)) }), shapes.map((o, i) => _jsx(MapShape, { shape: o }, i)), _jsx(MapLayers, {}), children] }));
84
+ return (_jsxs(ReactLeaflet.MapContainer, { center: pos, style: Object.assign(Object.assign({}, defaultStyle), mapStyle), zoom: zoom, scrollWheelZoom: ((_a = rootProps.zoomOptions) === null || _a === void 0 ? void 0 : _a.wheel) ? 'center' : undefined, zoomControl: ((_b = rootProps.zoomOptions) === null || _b === void 0 ? void 0 : _b.control) !== false, attributionControl: true, dragging: dragging, ref: setMap, whenReady: whenReady, children: [!rootProps.tileAttrs && _jsx(ReactLeaflet.TileLayer, { url: "https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" }), !!rootProps.tileAttrs && _jsx(ReactLeaflet.TileLayer, Object.assign({}, rootProps.tileAttrs)), _jsx(MapEvents, {}), marker !== false && _jsx(MapMarker, { pos: pos, html: isValidElement(marker) ? marker : getDefaultMarkerIcon() }, 'main-marker'), _jsx(MarkerClusterGroup, { chunkedLoading: true, showCoverageOnHover: false, children: markers.map((marker, i) => _jsx(MapMarker, { pos: marker.pos, html: marker.html, eventHandlers: marker.eventHandlers }, `marker-${i}`)) }), shapes.map((o, i) => _jsx(MapShape, { shape: o }, i)), _jsx(MapLayers, {}), children] }));
85
85
  };
86
86
  const MagnifyIcon = () => {
87
87
  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" }) }));
@@ -225,3 +225,15 @@ export const smooth = (points, acc) => {
225
225
  const simplified = simplify(points2D, acc === 'low' ? 0.001 : (acc === 'medium' ? 0.002 : 0.003), true); // 10 = tolerance (متر تقریبی), true = highQuality
226
226
  return simplified.map(p => ([p.y, p.x]));
227
227
  };
228
+ export function getCenterOfPoints(points) {
229
+ const filteredPoints = points.filter(({ lat, lng }) => typeof lat === 'number' && typeof lng === 'number');
230
+ let totalLat = 0, totalLng = 0;
231
+ for (let i = 0; i < filteredPoints.length; i++) {
232
+ const { lat, lng } = filteredPoints[i];
233
+ totalLat += lat;
234
+ totalLng += lng;
235
+ }
236
+ totalLat /= filteredPoints.length;
237
+ totalLng /= filteredPoints.length;
238
+ return { lat: totalLat, lng: totalLng };
239
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-map",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "",
5
5
  "types": "index.d.ts",
6
6
  "main": "index.js",