awing-library 2.1.198-dev → 2.1.199-dev
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.
|
@@ -55,6 +55,6 @@ function Component(props) {
|
|
|
55
55
|
}
|
|
56
56
|
}, error: !!(radius &&
|
|
57
57
|
Number(radius) <
|
|
58
|
-
((limit === null || limit === void 0 ? void 0 : limit.min) || constants_1.MIN_RADIUS)) }) })] })), (isOnlyMap || showMap) && ((0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 12, style: { position: "relative", marginTop: "16px" }, children: (0, jsx_runtime_1.jsx)(AWING_1.GoogleMap, { onUpdateLocation: onGoongMapSelect, apiKey: configs.GOOGLE_MAP_KEY, geofenceRadius: radius ? Number(radius) : 0 }) }))] })] }));
|
|
58
|
+
((limit === null || limit === void 0 ? void 0 : limit.min) || constants_1.MIN_RADIUS)) }) })] })), (isOnlyMap || showMap) && ((0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 12, style: { position: "relative", marginTop: "16px" }, children: (0, jsx_runtime_1.jsx)(AWING_1.GoogleMap, { defaultLocation: { lat: (marker === null || marker === void 0 ? void 0 : marker.latitude) || 0, lng: (marker === null || marker === void 0 ? void 0 : marker.longitude) || 0 }, onUpdateLocation: onGoongMapSelect, apiKey: configs.GOOGLE_MAP_KEY, geofenceRadius: radius ? Number(radius) : 0 }) }))] })] }));
|
|
59
59
|
}
|
|
60
60
|
exports.default = Component;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IGoogleMapProps } from './interface';
|
|
2
|
-
declare const GGMap: ({ defaultLocation, onUpdateLocation, apiKey, geofenceRadius,
|
|
2
|
+
declare const GGMap: ({ defaultLocation, onUpdateLocation, apiKey, geofenceRadius, sxMap, isDisplayAutoComplete, isTypeTracking, markerPositions, zoomCustomed }: IGoogleMapProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default GGMap;
|
|
@@ -3,16 +3,28 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
3
3
|
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
4
|
return cooked;
|
|
5
5
|
};
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
16
28
|
};
|
|
17
29
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
30
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -22,7 +34,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
22
34
|
var material_1 = require("@mui/material");
|
|
23
35
|
var api_1 = require("@react-google-maps/api");
|
|
24
36
|
var lodash_1 = __importDefault(require("lodash"));
|
|
25
|
-
var react_1 = require("react");
|
|
37
|
+
var react_1 = __importStar(require("react"));
|
|
26
38
|
var react_i18next_1 = require("react-i18next");
|
|
27
39
|
var utils_1 = require("./utils");
|
|
28
40
|
var mapContainerStyle = {
|
|
@@ -39,12 +51,13 @@ var stylesDefault = {
|
|
|
39
51
|
}
|
|
40
52
|
};
|
|
41
53
|
var GGMap = function (_a) {
|
|
42
|
-
var defaultLocation = _a.defaultLocation, onUpdateLocation = _a.onUpdateLocation, apiKey = _a.apiKey, geofenceRadius = _a.geofenceRadius,
|
|
54
|
+
var defaultLocation = _a.defaultLocation, onUpdateLocation = _a.onUpdateLocation, apiKey = _a.apiKey, geofenceRadius = _a.geofenceRadius, sxMap = _a.sxMap, _b = _a.isDisplayAutoComplete, isDisplayAutoComplete = _b === void 0 ? false : _b, _c = _a.isTypeTracking, isTypeTracking = _c === void 0 ? false : _c, markerPositions = _a.markerPositions, zoomCustomed = _a.zoomCustomed;
|
|
43
55
|
var t = (0, react_i18next_1.useTranslation)().t;
|
|
44
56
|
var _d = (0, react_1.useState)(), map = _d[0], setMap = _d[1];
|
|
45
57
|
var _e = (0, react_1.useState)(''), error = _e[0], setError = _e[1];
|
|
46
58
|
var autocompleteRef = (0, react_1.useRef)(null);
|
|
47
59
|
var boxRef = (0, react_1.useRef)(null);
|
|
60
|
+
var makerRefs = (0, react_1.useRef)([]);
|
|
48
61
|
var _f = (0, react_1.useState)(zoomCustomed || 5), zoom = _f[0], setZoom = _f[1];
|
|
49
62
|
var onLoad = function (autocomplete) {
|
|
50
63
|
autocompleteRef.current = autocomplete;
|
|
@@ -62,9 +75,13 @@ var GGMap = function (_a) {
|
|
|
62
75
|
}
|
|
63
76
|
return acc;
|
|
64
77
|
}, {})) !== null && _a !== void 0 ? _a : {};
|
|
78
|
+
return Object.values(coordMap).map(function (item, index, arr) {
|
|
79
|
+
var _a;
|
|
80
|
+
item.radius = ((_a = item.count) !== null && _a !== void 0 ? _a : 0) / arr.reduce(function (acc, item) { var _a; return acc + ((_a = item === null || item === void 0 ? void 0 : item.count) !== null && _a !== void 0 ? _a : 0); }, 0) * (Math.pow(2, 10 - (zoom))) * 10000;
|
|
81
|
+
return item;
|
|
82
|
+
});
|
|
65
83
|
// Convert the object to an array
|
|
66
|
-
|
|
67
|
-
}, [markerPositions]);
|
|
84
|
+
}, [markerPositions, zoom]);
|
|
68
85
|
var onPlaceChanged = function () {
|
|
69
86
|
var _a, _b, _c, _d;
|
|
70
87
|
if (autocompleteRef.current !== null) {
|
|
@@ -84,9 +101,9 @@ var GGMap = function (_a) {
|
|
|
84
101
|
console.log('Autocomplete is not loaded yet!');
|
|
85
102
|
}
|
|
86
103
|
};
|
|
87
|
-
var onLoadMap = function (mapInstance) {
|
|
104
|
+
var onLoadMap = react_1.default.useCallback(function (mapInstance) {
|
|
88
105
|
setMap(mapInstance);
|
|
89
|
-
};
|
|
106
|
+
}, []);
|
|
90
107
|
//Lấy vị trí hiện tại của người dùng
|
|
91
108
|
var getCurrentLocation = function () {
|
|
92
109
|
var showPosition = function (position) {
|
|
@@ -118,21 +135,43 @@ var GGMap = function (_a) {
|
|
|
118
135
|
setError('Geolocation is not supported by this browser.');
|
|
119
136
|
}
|
|
120
137
|
};
|
|
121
|
-
var onMapClick = function (e) {
|
|
138
|
+
var onMapClick = react_1.default.useCallback(function (e) {
|
|
122
139
|
var _a, _b, _c, _d;
|
|
123
140
|
onUpdateLocation && onUpdateLocation({
|
|
124
141
|
latitude: (_b = (_a = e === null || e === void 0 ? void 0 : e.latLng) === null || _a === void 0 ? void 0 : _a.lat()) !== null && _b !== void 0 ? _b : 0,
|
|
125
142
|
longitude: (_d = (_c = e === null || e === void 0 ? void 0 : e.latLng) === null || _c === void 0 ? void 0 : _c.lng()) !== null && _d !== void 0 ? _d : 0,
|
|
126
143
|
});
|
|
127
|
-
};
|
|
144
|
+
}, []);
|
|
128
145
|
(0, react_1.useEffect)(function () {
|
|
129
146
|
if (lodash_1.default.isNil(defaultLocation) || defaultLocation.lat === 0 || defaultLocation.lng === 0) {
|
|
130
147
|
getCurrentLocation();
|
|
131
148
|
}
|
|
132
149
|
}, [defaultLocation]);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
150
|
+
(0, react_1.useEffect)(function () {
|
|
151
|
+
if (map) {
|
|
152
|
+
makerRefs.current.forEach(function (marker) {
|
|
153
|
+
marker.setMap(null);
|
|
154
|
+
});
|
|
155
|
+
makerRefs.current = markerConvert.map(function (item) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
var maker = new google.maps.Circle({
|
|
158
|
+
center: { lat: (_a = item.latitude) !== null && _a !== void 0 ? _a : 0, lng: (_b = item.longitude) !== null && _b !== void 0 ? _b : 0 },
|
|
159
|
+
radius: item.radius,
|
|
160
|
+
strokeColor: '#4285F4',
|
|
161
|
+
strokeOpacity: 0.8,
|
|
162
|
+
strokeWeight: 2,
|
|
163
|
+
fillColor: "#4285F4",
|
|
164
|
+
fillOpacity: 0.35,
|
|
165
|
+
});
|
|
166
|
+
maker.setMap(map);
|
|
167
|
+
return maker;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
console.log(markerConvert);
|
|
171
|
+
}, [markerConvert]);
|
|
172
|
+
var handleZoom = (0, react_1.useCallback)(function (zoom) {
|
|
173
|
+
setZoom(zoom);
|
|
174
|
+
}, []);
|
|
136
175
|
return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: sxMap ? sxMap : stylesDefault, ref: boxRef, children: (0, jsx_runtime_1.jsxs)(api_1.LoadScript, { googleMapsApiKey: apiKey || '', libraries: libraries, children: [!isDisplayAutoComplete &&
|
|
137
176
|
((0, jsx_runtime_1.jsx)(api_1.Autocomplete, { onPlaceChanged: onPlaceChanged, onLoad: onLoad, children: (0, jsx_runtime_1.jsx)("input", { type: "text", placeholder: t('Common.PlaceHolderLocation'), onFocus: function () {
|
|
138
177
|
var _a;
|
|
@@ -156,37 +195,47 @@ var GGMap = function (_a) {
|
|
|
156
195
|
margin: '10px 0',
|
|
157
196
|
zIndex: 99,
|
|
158
197
|
top: '50px',
|
|
159
|
-
} }) })), (0, jsx_runtime_1.jsx)(
|
|
160
|
-
var _a;
|
|
161
|
-
setZoom((_a = map === null || map === void 0 ? void 0 : map.getZoom()) !== null && _a !== void 0 ? _a : zoom);
|
|
162
|
-
}, center: defaultLocation, onLoad: onLoadMap, onClick: onMapClick }, isTypeTracking && {
|
|
163
|
-
options: {
|
|
164
|
-
disableDefaultUI: true,
|
|
165
|
-
styles: utils_1.mapStyles,
|
|
166
|
-
zoomControl: true,
|
|
167
|
-
streetViewControl: false,
|
|
168
|
-
mapTypeControl: false,
|
|
169
|
-
fullscreenControl: false,
|
|
170
|
-
minZoom: 2
|
|
171
|
-
}
|
|
172
|
-
}, { children: !markerPositions ?
|
|
173
|
-
(0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(api_1.Marker, { position: defaultLocation !== null && defaultLocation !== void 0 ? defaultLocation : { lat: 21.0063107, lng: 105.8279467 } }), (0, jsx_runtime_1.jsx)(api_1.Circle, { center: defaultLocation, radius: geofenceRadius, options: {
|
|
174
|
-
fillColor: 'red',
|
|
175
|
-
fillOpacity: 0.2,
|
|
176
|
-
strokeColor: 'red',
|
|
177
|
-
strokeOpacity: 1,
|
|
178
|
-
strokeWeight: 2,
|
|
179
|
-
} })] })
|
|
180
|
-
: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: markerConvert === null || markerConvert === void 0 ? void 0 : markerConvert.map(function (coordinates, index, positions) {
|
|
181
|
-
var _a, _b, _c;
|
|
182
|
-
return (0, jsx_runtime_1.jsx)(api_1.CircleF, { center: { lat: (_a = coordinates.latitude) !== null && _a !== void 0 ? _a : 0, lng: (_b = coordinates.longitude) !== null && _b !== void 0 ? _b : 0 }, radius: calculateRadius(zoom * ((_c = coordinates === null || coordinates === void 0 ? void 0 : coordinates.count) !== null && _c !== void 0 ? _c : 0)), options: {
|
|
183
|
-
strokeColor: '#4285F4',
|
|
184
|
-
strokeOpacity: 0.8,
|
|
185
|
-
strokeWeight: 2,
|
|
186
|
-
fillColor: "#4285F4",
|
|
187
|
-
fillOpacity: 0.35,
|
|
188
|
-
} }, index);
|
|
189
|
-
}) }) }))] }) }));
|
|
198
|
+
} }) })), !isTypeTracking ? (0, jsx_runtime_1.jsx)(MaprenderWithoutTracking, { onLoadMap: onLoadMap, onMapClick: onMapClick, onZoomChanged: handleZoom, defaultLocation: defaultLocation !== null && defaultLocation !== void 0 ? defaultLocation : { lat: 21.0063107, lng: 105.8279467 }, geofenceRadius: geofenceRadius !== null && geofenceRadius !== void 0 ? geofenceRadius : 0, zoomCustomed: zoomCustomed !== null && zoomCustomed !== void 0 ? zoomCustomed : 10 }) : (0, jsx_runtime_1.jsx)(Maprender, { onLoadMap: onLoadMap, onMapClick: onMapClick, onZoomChanged: handleZoom })] }) }));
|
|
190
199
|
};
|
|
191
200
|
exports.default = GGMap;
|
|
201
|
+
var Maprender = react_1.default.memo(function (_a) {
|
|
202
|
+
var onLoadMap = _a.onLoadMap, onMapClick = _a.onMapClick, onZoomChanged = _a.onZoomChanged;
|
|
203
|
+
var mapInstance = (0, react_1.useRef)(null);
|
|
204
|
+
return (0, jsx_runtime_1.jsx)(api_1.GoogleMap, { id: "map", mapContainerStyle: { width: "100%", height: "".concat(521, "px") }, zoom: 2, center: {
|
|
205
|
+
lat: 21.0063107,
|
|
206
|
+
lng: 105.8279467
|
|
207
|
+
}, onZoomChanged: function () {
|
|
208
|
+
var _a, _b;
|
|
209
|
+
onZoomChanged((_b = (_a = mapInstance.current) === null || _a === void 0 ? void 0 : _a.getZoom()) !== null && _b !== void 0 ? _b : 0);
|
|
210
|
+
}, onLoad: function (instance) {
|
|
211
|
+
mapInstance.current = instance;
|
|
212
|
+
onLoadMap(instance);
|
|
213
|
+
}, onClick: onMapClick, options: {
|
|
214
|
+
disableDefaultUI: true,
|
|
215
|
+
styles: utils_1.mapStyles,
|
|
216
|
+
zoomControl: true,
|
|
217
|
+
streetViewControl: false,
|
|
218
|
+
mapTypeControl: false,
|
|
219
|
+
fullscreenControl: false,
|
|
220
|
+
minZoom: 2,
|
|
221
|
+
maxZoom: 13,
|
|
222
|
+
} });
|
|
223
|
+
});
|
|
224
|
+
var MaprenderWithoutTracking = react_1.default.memo(function (_a) {
|
|
225
|
+
var onLoadMap = _a.onLoadMap, onMapClick = _a.onMapClick, onZoomChanged = _a.onZoomChanged, defaultLocation = _a.defaultLocation, geofenceRadius = _a.geofenceRadius, zoomCustomed = _a.zoomCustomed;
|
|
226
|
+
var mapInstance = (0, react_1.useRef)(null);
|
|
227
|
+
return (0, jsx_runtime_1.jsx)(api_1.GoogleMap, { id: "map", mapContainerStyle: mapContainerStyle, zoom: zoomCustomed !== null && zoomCustomed !== void 0 ? zoomCustomed : 10, center: defaultLocation, onZoomChanged: function () {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
onZoomChanged((_b = (_a = mapInstance.current) === null || _a === void 0 ? void 0 : _a.getZoom()) !== null && _b !== void 0 ? _b : 0);
|
|
230
|
+
}, onLoad: function (instance) {
|
|
231
|
+
mapInstance.current = instance;
|
|
232
|
+
onLoadMap(instance);
|
|
233
|
+
}, onClick: onMapClick, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(api_1.Marker, { position: defaultLocation !== null && defaultLocation !== void 0 ? defaultLocation : { lat: 21.0063107, lng: 105.8279467 } }), (0, jsx_runtime_1.jsx)(api_1.Circle, { center: defaultLocation, radius: geofenceRadius, options: {
|
|
234
|
+
fillColor: 'red',
|
|
235
|
+
fillOpacity: 0.2,
|
|
236
|
+
strokeColor: 'red',
|
|
237
|
+
strokeOpacity: 1,
|
|
238
|
+
strokeWeight: 2,
|
|
239
|
+
} })] }) });
|
|
240
|
+
});
|
|
192
241
|
var templateObject_1;
|