aio-map 3.2.6 → 3.3.1

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 +1 -0
  2. package/index.js +12 -31
  3. package/package.json +5 -5
package/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export type I_Map = {
40
40
  children?: React.ReactNode;
41
41
  onChangePos?: (coords: I_pos) => void;
42
42
  onChangeZoom?: (newZoom: number) => void;
43
+ cluster?: boolean;
43
44
  pos?: I_pos;
44
45
  delay?: number;
45
46
  zoom?: number;
package/index.js CHANGED
@@ -15,7 +15,7 @@ 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 { Debounce } from 'aio-utils';
18
+ import { AddToAttrs, Debounce } from 'aio-class';
19
19
  import './index.css';
20
20
  const MAPCTX = createContext({});
21
21
  const AIMap = (props) => {
@@ -31,6 +31,9 @@ const AIMap = (props) => {
31
31
  if (newZoom === zoomRef.current) {
32
32
  return;
33
33
  }
34
+ if (props.onChangeZoom) {
35
+ props.onChangeZoom(newZoom);
36
+ }
34
37
  setZoom(newZoom);
35
38
  }
36
39
  if (mapRef) {
@@ -81,7 +84,9 @@ const MapBody = () => {
81
84
  const { rootProps, pos, setMap, getDefaultMarkerIcon, zoom } = useContext(MAPCTX);
82
85
  const { mapStyle, dragging = true, children, shapes = [], marker, markers = [], whenReady } = rootProps;
83
86
  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: [!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] }));
87
+ const MRKS = markers.map((marker, i) => _jsx(MapMarker, { pos: marker.pos, html: marker.html, eventHandlers: marker.eventHandlers }, `marker-${i}`));
88
+ 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'), rootProps.cluster !== false &&
89
+ _jsx(MarkerClusterGroup, { chunkedLoading: true, showCoverageOnHover: false, children: MRKS }), rootProps.cluster === false && MRKS, shapes.map((o, i) => _jsx(MapShape, { shape: o }, i)), _jsx(MapLayers, {}), children] }));
85
90
  };
86
91
  const MagnifyIcon = () => {
87
92
  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" }) }));
@@ -105,9 +110,9 @@ const MapHeader = () => {
105
110
  }), 1200);
106
111
  }
107
112
  return (_jsx("div", { className: "ai-map-header", children: _jsx(AIOInput, { type: 'text', value: searchValue, options: (searchResult || []), before: _jsx(MagnifyIcon, {}), onChange: (searchValue) => changeSearch(searchValue), option: {
108
- onClick: (option) => { if (onSearch) {
109
- onSearch(option);
110
- } }
113
+ attrs: (option) => ({ onClick: () => { if (onSearch) {
114
+ onSearch(option);
115
+ } } })
111
116
  } }) }));
112
117
  };
113
118
  const MapLayers = () => {
@@ -153,8 +158,8 @@ const MapMarker = ({ pos, html, eventHandlers }) => {
153
158
  function getHtmlIcon(html) {
154
159
  return Leaflet.divIcon({
155
160
  html: JSXToHTML(html),
156
- className: '',
157
- iconSize: [32, 32],
161
+ className: '', // Optional, for adding custom styles
162
+ iconSize: [32, 32], // size of the icon
158
163
  iconAnchor: [16, 32], // point of the icon which will correspond to marker's location
159
164
  });
160
165
  }
@@ -195,30 +200,6 @@ function MapEvents() {
195
200
  function JSXToHTML(jsx) {
196
201
  return ReactDOMServer.renderToStaticMarkup(jsx);
197
202
  }
198
- function classListToString(classes) {
199
- let list = [];
200
- const getClasses = (cls) => {
201
- if (Array.isArray(cls)) {
202
- return cls.filter((o) => !!o && typeof o === 'string');
203
- }
204
- if (typeof cls === 'string') {
205
- return cls.split(' ');
206
- }
207
- return [];
208
- };
209
- for (let i = 0; i < classes.length; i++) {
210
- const cls = classes[i];
211
- list = [...list, ...getClasses(cls)];
212
- }
213
- return list.length ? list.join(' ') : '';
214
- }
215
- function AddToAttrs(attrs, p) {
216
- attrs = attrs || {};
217
- let { style } = p;
218
- const className = classListToString([attrs.className, p.className]);
219
- let newStyle = Object.assign(Object.assign({}, attrs.style), style);
220
- return Object.assign(Object.assign(Object.assign({}, attrs), { className, style: newStyle }), p.attrs);
221
- }
222
203
  export function getCenterOfPoints(points) {
223
204
  const filteredPoints = points.filter(({ lat, lng }) => typeof lat === 'number' && typeof lng === 'number');
224
205
  let totalLat = 0, totalLng = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-map",
3
- "version": "3.2.6",
3
+ "version": "3.3.1",
4
4
  "description": "",
5
5
  "types": "index.d.ts",
6
6
  "main": "index.js",
@@ -12,11 +12,11 @@
12
12
  "url": "git+https://github.com/mohammadFeiz/aio-map.git"
13
13
  },
14
14
  "dependencies": {
15
- "aio-deps": "latest",
15
+ "aio-class": "latest",
16
16
  "aio-input": "latest",
17
- "leaflet": "^1.9.4",
18
- "react-leaflet": "^5.0.0",
19
- "react-leaflet-cluster": "^2.1.0"
17
+ "leaflet": "latest",
18
+ "react-leaflet": "latest",
19
+ "react-leaflet-cluster": "latest"
20
20
  },
21
21
  "author": "mohammad sharif feiz feiz.ms@gmail.com",
22
22
  "license": "ISC",