awing-library 2.1.185-dev → 2.1.187-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.
@@ -1,3 +1,3 @@
1
1
  import { IGoogleMapProps } from './interface';
2
- declare const GGMap: ({ defaultLocation, onUpdateLocation, apiKey, markerPosition, geofenceRadius }: IGoogleMapProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const GGMap: ({ defaultLocation, onUpdateLocation, apiKey, markerPosition, geofenceRadius, sizeMap, sxMap, isDisplayAutoComplete, isTypeTracking, markerPositions, zoomCustomed }: IGoogleMapProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default GGMap;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -9,20 +20,27 @@ var api_1 = require("@react-google-maps/api");
9
20
  var lodash_1 = __importDefault(require("lodash"));
10
21
  var react_1 = require("react");
11
22
  var react_i18next_1 = require("react-i18next");
23
+ var utils_1 = require("./utils");
12
24
  var mapContainerStyle = {
13
25
  height: '320px',
14
26
  width: '100%',
15
27
  };
16
28
  var libraries = ['places'];
29
+ var stylesDefault = {
30
+ position: 'relative',
31
+ '& .pac-container.pac-logo': {
32
+ top: "55px!important",
33
+ left: "0!important",
34
+ }
35
+ };
17
36
  var GGMap = function (_a) {
18
- var _b, _c;
19
- var defaultLocation = _a.defaultLocation, onUpdateLocation = _a.onUpdateLocation, apiKey = _a.apiKey, markerPosition = _a.markerPosition, geofenceRadius = _a.geofenceRadius;
37
+ var defaultLocation = _a.defaultLocation, onUpdateLocation = _a.onUpdateLocation, apiKey = _a.apiKey, markerPosition = _a.markerPosition, geofenceRadius = _a.geofenceRadius, sizeMap = _a.sizeMap, 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;
20
38
  var t = (0, react_i18next_1.useTranslation)().t;
21
39
  var _d = (0, react_1.useState)(), map = _d[0], setMap = _d[1];
22
40
  var _e = (0, react_1.useState)(''), error = _e[0], setError = _e[1];
23
41
  var autocompleteRef = (0, react_1.useRef)(null);
24
42
  var boxRef = (0, react_1.useRef)(null);
25
- var _f = (0, react_1.useState)(15), zoom = _f[0], setZoom = _f[1];
43
+ var _f = (0, react_1.useState)(zoomCustomed || 0), zoom = _f[0], setZoom = _f[1];
26
44
  var onLoad = function (autocomplete) {
27
45
  autocompleteRef.current = autocomplete;
28
46
  };
@@ -33,7 +51,7 @@ var GGMap = function (_a) {
33
51
  if (place.geometry) {
34
52
  var newLat = (_b = (_a = place === null || place === void 0 ? void 0 : place.geometry) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.lat();
35
53
  var newLng = (_d = (_c = place === null || place === void 0 ? void 0 : place.geometry) === null || _c === void 0 ? void 0 : _c.location) === null || _d === void 0 ? void 0 : _d.lng();
36
- onUpdateLocation({
54
+ onUpdateLocation && onUpdateLocation({
37
55
  latitude: newLat !== null && newLat !== void 0 ? newLat : 0,
38
56
  longitude: newLng !== null && newLng !== void 0 ? newLng : 0,
39
57
  });
@@ -48,41 +66,10 @@ var GGMap = function (_a) {
48
66
  var onLoadMap = function (mapInstance) {
49
67
  setMap(mapInstance);
50
68
  };
51
- //Lấy geo fencing
52
- // const getDistance = (
53
- // lat1: number,
54
- // lon1: number,
55
- // lat2: number,
56
- // lon2: number
57
- // ) => {
58
- // const R = 6371e3; // Radius of the Earth in meters
59
- // const φ1 = (lat1 * Math.PI) / 180;
60
- // const φ2 = (lat2 * Math.PI) / 180;
61
- // const Δφ = ((lat2 - lat1) * Math.PI) / 180;
62
- // const Δλ = ((lon2 - lon1) * Math.PI) / 180;
63
- // const a =
64
- // Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
65
- // Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
66
- // const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
67
- // const distance = R * c; // Distance in meters
68
- // return distance;
69
- // };
70
69
  //Lấy vị trí hiện tại của người dùng
71
70
  var getCurrentLocation = function () {
72
- var handleLocationGeoFencing = function (position) {
73
- var userLat = position.coords.latitude;
74
- var userLng = position.coords.longitude;
75
- // const distance = getDistance(
76
- // userLat,
77
- // userLng,
78
- // markerPosition.lat,
79
- // markerPosition.lng
80
- // );
81
- // console.log("distance", distance);
82
- };
83
71
  var showPosition = function (position) {
84
- handleLocationGeoFencing(position);
85
- onUpdateLocation({
72
+ onUpdateLocation && onUpdateLocation({
86
73
  latitude: position.coords.latitude,
87
74
  longitude: position.coords.longitude,
88
75
  });
@@ -112,7 +99,7 @@ var GGMap = function (_a) {
112
99
  };
113
100
  var onMapClick = function (e) {
114
101
  var _a, _b, _c, _d;
115
- onUpdateLocation({
102
+ onUpdateLocation && onUpdateLocation({
116
103
  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,
117
104
  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,
118
105
  });
@@ -122,41 +109,64 @@ var GGMap = function (_a) {
122
109
  getCurrentLocation();
123
110
  }
124
111
  }, [defaultLocation]);
125
- var marker = { lat: (_b = Number(markerPosition === null || markerPosition === void 0 ? void 0 : markerPosition.latitude)) !== null && _b !== void 0 ? _b : 0, lng: (_c = Number(markerPosition === null || markerPosition === void 0 ? void 0 : markerPosition.longitude)) !== null && _c !== void 0 ? _c : 0 };
126
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
127
- position: 'relative',
128
- '& .pac-container.pac-logo': {
129
- top: "55px!important",
130
- left: "0!important",
131
- }
132
- }, ref: boxRef, children: (0, jsx_runtime_1.jsxs)(api_1.LoadScript, { googleMapsApiKey: apiKey || '', libraries: libraries, children: [(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 () {
133
- var _a;
134
- var ggSuggest = document.querySelector('.pac-container.pac-logo');
135
- if (ggSuggest) {
136
- (_a = boxRef.current) === null || _a === void 0 ? void 0 : _a.append(ggSuggest);
137
- }
138
- }, style: {
139
- boxSizing: "border-box",
140
- border: "1px solid transparent",
141
- width: "378px",
142
- height: "40px",
143
- padding: "0 12px",
144
- borderRadius: "3px",
145
- boxShadow: "0 2px 6px rgba(0, 0, 0, 0.3)",
146
- fontSize: "14px",
147
- outline: "none",
148
- textOverflow: "ellipses",
149
- position: 'inherit',
150
- right: '3%',
151
- margin: '10px 0',
152
- zIndex: 99,
153
- top: '50px',
154
- } }) }), (0, jsx_runtime_1.jsx)(api_1.GoogleMap, { id: "map", mapContainerStyle: mapContainerStyle, zoom: zoom, center: marker, onLoad: onLoadMap, onClick: onMapClick, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(api_1.Marker, { position: marker }), (0, jsx_runtime_1.jsx)(api_1.Circle, { center: marker, radius: geofenceRadius, options: {
155
- fillColor: 'red',
156
- fillOpacity: 0.2,
157
- strokeColor: 'red',
158
- strokeOpacity: 1,
159
- strokeWeight: 2,
160
- } })] }) })] }) }));
112
+ var marker = (0, react_1.useMemo)(function () {
113
+ var _a, _b;
114
+ return {
115
+ lat: (_a = Number(markerPosition === null || markerPosition === void 0 ? void 0 : markerPosition.latitude)) !== null && _a !== void 0 ? _a : 0,
116
+ lng: (_b = Number(markerPosition === null || markerPosition === void 0 ? void 0 : markerPosition.longitude)) !== null && _b !== void 0 ? _b : 0,
117
+ };
118
+ }, [markerPosition]);
119
+ 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 &&
120
+ ((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 () {
121
+ var _a;
122
+ var ggSuggest = document.querySelector('.pac-container.pac-logo');
123
+ if (ggSuggest) {
124
+ (_a = boxRef.current) === null || _a === void 0 ? void 0 : _a.append(ggSuggest);
125
+ }
126
+ }, style: {
127
+ boxSizing: "border-box",
128
+ border: "1px solid transparent",
129
+ width: "378px",
130
+ height: "40px",
131
+ padding: "0 12px",
132
+ borderRadius: "3px",
133
+ boxShadow: "0 2px 6px rgba(0, 0, 0, 0.3)",
134
+ fontSize: "14px",
135
+ outline: "none",
136
+ textOverflow: "ellipses",
137
+ position: 'inherit',
138
+ right: '3%',
139
+ margin: '10px 0',
140
+ zIndex: 99,
141
+ top: '50px',
142
+ } }) })), (0, jsx_runtime_1.jsx)(api_1.GoogleMap, __assign({ id: "map", mapContainerStyle: sizeMap !== null && sizeMap !== void 0 ? sizeMap : mapContainerStyle, zoom: zoom, center: marker, onLoad: onLoadMap, onClick: onMapClick }, isTypeTracking && {
143
+ options: {
144
+ disableDefaultUI: true,
145
+ styles: utils_1.mapStyles,
146
+ zoomControl: true,
147
+ streetViewControl: false,
148
+ mapTypeControl: false,
149
+ fullscreenControl: false,
150
+ }
151
+ }, { children: !markerPositions ?
152
+ (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(api_1.Marker, { position: marker }), (0, jsx_runtime_1.jsx)(api_1.Circle, { center: marker, radius: geofenceRadius, options: {
153
+ fillColor: 'red',
154
+ fillOpacity: 0.2,
155
+ strokeColor: 'red',
156
+ strokeOpacity: 1,
157
+ strokeWeight: 2,
158
+ } })] })
159
+ : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: markerPositions === null || markerPositions === void 0 ? void 0 : markerPositions.map(function (coordinates, index, positions) {
160
+ var _a, _b;
161
+ // const radius =
162
+ // Math.max(
163
+ // 30,
164
+ // (coordinates.count /
165
+ // Math.max(...positions.map((p) => p.count))) *
166
+ // 120
167
+ // ) *
168
+ // (1 / 7);
169
+ return (0, jsx_runtime_1.jsx)(api_1.Marker, { position: { lat: (_a = coordinates.latitude) !== null && _a !== void 0 ? _a : 0, lng: (_b = coordinates.longitude) !== null && _b !== void 0 ? _b : 0 } }, index);
170
+ }) }) }))] }) }));
161
171
  };
162
172
  exports.default = GGMap;
@@ -1,3 +1,4 @@
1
+ import { DataObject } from "../../AWING/interface";
1
2
  export interface IGoogleMapProps {
2
3
  defaultLocation?: {
3
4
  lat: number;
@@ -7,10 +8,22 @@ export interface IGoogleMapProps {
7
8
  latitude: number;
8
9
  longitude: number;
9
10
  };
10
- onUpdateLocation: (newValue: {
11
+ onUpdateLocation?: (newValue: {
11
12
  latitude: number;
12
13
  longitude: number;
13
14
  }) => void;
14
15
  apiKey: string;
15
16
  geofenceRadius?: number;
17
+ sizeMap?: {
18
+ height: string;
19
+ width: string;
20
+ };
21
+ sxMap?: DataObject;
22
+ isDisplayAutoComplete?: boolean;
23
+ isTypeTracking?: boolean;
24
+ markerPositions?: {
25
+ longitude: number | null;
26
+ latitude: number | null;
27
+ }[];
28
+ zoomCustomed?: number;
16
29
  }
@@ -0,0 +1,25 @@
1
+ export declare const mapStyles: ({
2
+ elementType: string;
3
+ stylers: {
4
+ color: string;
5
+ }[];
6
+ featureType?: undefined;
7
+ } | {
8
+ elementType: string;
9
+ stylers: {
10
+ visibility: string;
11
+ }[];
12
+ featureType?: undefined;
13
+ } | {
14
+ featureType: string;
15
+ elementType: string;
16
+ stylers: {
17
+ color: string;
18
+ }[];
19
+ } | {
20
+ featureType: string;
21
+ stylers: {
22
+ visibility: string;
23
+ }[];
24
+ elementType?: undefined;
25
+ })[];
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapStyles = void 0;
4
+ exports.mapStyles = [
5
+ {
6
+ "elementType": "geometry",
7
+ "stylers": [
8
+ {
9
+ "color": "#dadce0"
10
+ }
11
+ ]
12
+ },
13
+ {
14
+ "elementType": "labels.icon",
15
+ "stylers": [
16
+ {
17
+ "visibility": "off"
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "elementType": "labels.text.fill",
23
+ "stylers": [
24
+ {
25
+ "color": "#212225"
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ "elementType": "labels.text.stroke",
31
+ "stylers": [
32
+ {
33
+ "color": "#dadce0"
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "featureType": "administrative",
39
+ "elementType": "geometry",
40
+ "stylers": [
41
+ {
42
+ "color": "#212225"
43
+ }
44
+ ]
45
+ },
46
+ {
47
+ "featureType": "administrative.country",
48
+ "elementType": "labels.text.fill",
49
+ "stylers": [
50
+ {
51
+ "color": "#212225"
52
+ }
53
+ ]
54
+ },
55
+ {
56
+ "featureType": "administrative.land_parcel",
57
+ "stylers": [
58
+ {
59
+ "visibility": "off"
60
+ }
61
+ ]
62
+ },
63
+ {
64
+ "featureType": "administrative.locality",
65
+ "elementType": "labels.text.fill",
66
+ "stylers": [
67
+ {
68
+ "color": "#898989"
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ "featureType": "poi",
74
+ "elementType": "labels.text.fill",
75
+ "stylers": [
76
+ {
77
+ "color": "#212225"
78
+ }
79
+ ]
80
+ },
81
+ {
82
+ "featureType": "poi.park",
83
+ "elementType": "labels.text.fill",
84
+ "stylers": [
85
+ {
86
+ "color": "#616161"
87
+ }
88
+ ]
89
+ },
90
+ {
91
+ "featureType": "road",
92
+ "elementType": "geometry.fill",
93
+ "stylers": [
94
+ {
95
+ "color": "#c8c8c8"
96
+ }
97
+ ]
98
+ },
99
+ {
100
+ "featureType": "road",
101
+ "elementType": "labels.text.fill",
102
+ "stylers": [
103
+ {
104
+ "color": "#8a8a8a"
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "featureType": "transit",
110
+ "elementType": "labels.text.fill",
111
+ "stylers": [
112
+ {
113
+ "color": "#212225"
114
+ }
115
+ ]
116
+ },
117
+ {
118
+ "featureType": "water",
119
+ "elementType": "geometry",
120
+ "stylers": [
121
+ {
122
+ "color": "#f8f9fa"
123
+ }
124
+ ]
125
+ },
126
+ {
127
+ "featureType": "water",
128
+ "elementType": "labels.text.fill",
129
+ "stylers": [
130
+ {
131
+ "color": "#f8f9fa"
132
+ }
133
+ ]
134
+ }
135
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.185-dev",
3
+ "version": "2.1.187-dev",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",