aio-map 3.3.0 → 3.3.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.
- package/index.d.ts +2 -1
- package/index.js +12 -1
- package/package.json +4 -4
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;
|
|
@@ -68,7 +69,7 @@ export type I_Map = {
|
|
|
68
69
|
};
|
|
69
70
|
export type I_layers = {
|
|
70
71
|
position: 'topright' | 'topleft';
|
|
71
|
-
items: I_layerItem[];
|
|
72
|
+
items: (I_layerItem | false | undefined)[];
|
|
72
73
|
};
|
|
73
74
|
export type I_layerItem = {
|
|
74
75
|
name: string;
|
package/index.js
CHANGED
|
@@ -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
|
-
|
|
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" }) }));
|
|
@@ -118,6 +123,9 @@ const MapLayers = () => {
|
|
|
118
123
|
}
|
|
119
124
|
const { position = 'topright', items = [] } = layers;
|
|
120
125
|
return (_jsx(ReactLeaflet.LayersControl, { position: position, children: items.map((o, i) => {
|
|
126
|
+
if (!o) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
121
129
|
const { shapes = [], markers = [], active = true, cluster } = o;
|
|
122
130
|
const content = markers.map((marker, j) => _jsx(MapMarker, { pos: marker.pos, html: marker.html, eventHandlers: marker.eventHandlers }, j));
|
|
123
131
|
return (_jsx(ReactLeaflet.LayersControl.Overlay, { name: o.name, checked: active, children: _jsxs(ReactLeaflet.FeatureGroup, { children: [!!cluster && _jsx(MarkerClusterGroup, { chunkedLoading: true, showCoverageOnHover: false, children: content }), !cluster && content, shapes.map((shape, k) => _jsx(MapShape, { shape: shape }, k))] }) }, i));
|
|
@@ -150,6 +158,9 @@ const MapFooter = () => {
|
|
|
150
158
|
};
|
|
151
159
|
const MapMarker = ({ pos, html, eventHandlers }) => {
|
|
152
160
|
const { getDefaultMarkerIcon } = useContext(MAPCTX);
|
|
161
|
+
if (!pos || !Array.isArray(pos) || typeof pos[0] !== "number" || typeof pos[1] !== "number") {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
153
164
|
function getHtmlIcon(html) {
|
|
154
165
|
return Leaflet.divIcon({
|
|
155
166
|
html: JSXToHTML(html),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-map",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"aio-class": "latest",
|
|
16
16
|
"aio-input": "latest",
|
|
17
|
-
"leaflet": "
|
|
18
|
-
"react-leaflet": "
|
|
19
|
-
"react-leaflet-cluster": "
|
|
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",
|