@wix/editor-react-components 1.2718.0 → 1.2719.0
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/dist/site/components/AccordionComponent/component.js +1300 -1
- package/dist/site/components/Dropdown/component.js +1 -1
- package/dist/site/components/GoogleMap/GoogleMap.types.d.ts +0 -1
- package/dist/site/components/GoogleMap/component.js +2339 -766
- package/dist/site/components/GoogleMap/components/GoogleMapReact.d.ts +0 -1
- package/dist/site/components/GoogleMap/components/GoogleMapReactInteractiveMap.d.ts +0 -1
- package/dist/site/components/GoogleMap/consts.d.ts +1 -0
- package/dist/site/components/GoogleMap/hooks/useGoogleMapProps.d.ts +0 -1
- package/dist/site/components/GoogleMap/manifest.js +0 -10
- package/dist/site/components/chunks/consts.js +2 -0
- package/dist/site/components/chunks/isArrayLike.js +6 -6
- package/package.json +5 -4
- package/dist/site/components/GoogleMap/component.preview.d.ts +0 -3
- package/dist/site/components/chunks/isEqual.js +0 -1303
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import React__default, { forwardRef, useState, useCallback,
|
|
3
|
+
import React__default, { forwardRef, useState, useCallback, useContext, useEffect, useRef, useMemo, useReducer, useImperativeHandle, createContext, useLayoutEffect, Children, memo, Suspense } from "react";
|
|
4
4
|
import { c as clsx } from "../chunks/clsx.js";
|
|
5
5
|
import { f as formatClassNames } from "../chunks/classNames.js";
|
|
6
6
|
import { a as getDataAttributes } from "../chunks/dataUtils.js";
|
|
7
7
|
import { e as getTabIndexAttribute, f as convertA11yKeysToHtmlFormat } from "../chunks/a11y.js";
|
|
8
8
|
import { createPortal } from "react-dom";
|
|
9
|
-
import { g as
|
|
10
|
-
import { i as isEqual } from "../chunks/isEqual.js";
|
|
11
|
-
import { G as GOOGLE_MAPS_DIRECTIONS_BASE_URL, M as MIN_ZOOM, a as MAX_ZOOM, T as TestIds, D as DEFAULT_ZOOM, b as MAP_IDS, c as MAP_TYPES, d as MAP_MOBILE_CONTROL_SIZE, A as API_KEY, e as DEFAULT_LOCATION, f as DefaultTranslations, g as TranslationKeys, h as TRANSLATIONS_NAMESPACES, C as COMPANY_NAME_DEFAULT, i as COMPANY_NAME_KEY, j as COMPONENT_NAME_DEFAULT, k as COMPONENT_NAME_KEY } from "../chunks/consts.js";
|
|
9
|
+
import { G as GOOGLE_MAPS_DIRECTIONS_BASE_URL, M as MIN_ZOOM, a as MAX_ZOOM, T as TestIds, I as INFO_WINDOW_PIXEL_OFFSET, D as DEFAULT_ZOOM, b as MAP_IDS, c as MAP_TYPES, d as MAP_MOBILE_CONTROL_SIZE, A as API_KEY, e as DEFAULT_LOCATION, f as DefaultTranslations, g as TranslationKeys, h as TRANSLATIONS_NAMESPACES, C as COMPANY_NAME_DEFAULT, i as COMPANY_NAME_KEY, j as COMPONENT_NAME_DEFAULT, k as COMPONENT_NAME_KEY } from "../chunks/consts.js";
|
|
12
10
|
import { p as parse } from "../chunks/index4.js";
|
|
13
11
|
import { useService } from "@wix/services-manager-react";
|
|
14
12
|
import { E as EnvironmentDefinition } from "../chunks/index2.js";
|
|
@@ -77,327 +75,1527 @@ const GoogleMapReact = forwardRef((props, forwardedRef) => {
|
|
|
77
75
|
}
|
|
78
76
|
);
|
|
79
77
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
function usePropBinding(object, prop, value) {
|
|
79
|
+
const writtenTo = useRef(null);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!object)
|
|
82
|
+
return;
|
|
83
|
+
if (value === void 0 && writtenTo.current !== object)
|
|
84
|
+
return;
|
|
85
|
+
writtenTo.current = object;
|
|
86
|
+
object[prop] = value;
|
|
87
|
+
}, [object, prop, value]);
|
|
88
|
+
}
|
|
89
|
+
const SafeReact = Object.assign({}, React);
|
|
90
|
+
const useInsertionEffect = SafeReact.useInsertionEffect;
|
|
91
|
+
const useSafeInsertionEffect = (
|
|
92
|
+
// React 17 doesn't have useInsertionEffect.
|
|
93
|
+
useInsertionEffect && // Preact replaces useInsertionEffect with useLayoutEffect and fires too late.
|
|
94
|
+
useInsertionEffect !== SafeReact.useLayoutEffect ? useInsertionEffect : (fn) => {
|
|
95
|
+
fn();
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
function forbiddenInRender() {
|
|
99
|
+
throw new Error("useEffectEvent: invalid call during rendering.");
|
|
100
|
+
}
|
|
101
|
+
function useEffectEventPolyfill(fn) {
|
|
102
|
+
const ref = useRef(forbiddenInRender);
|
|
103
|
+
useSafeInsertionEffect(() => {
|
|
104
|
+
ref.current = fn;
|
|
105
|
+
}, [fn]);
|
|
106
|
+
return ((...args) => ref.current(...args));
|
|
107
|
+
}
|
|
108
|
+
const useEffectEvent = useEffectEventPolyfill;
|
|
109
|
+
const noop$1 = () => {
|
|
110
|
+
};
|
|
111
|
+
function useDomEventListener(target, name, callback) {
|
|
112
|
+
const eventFn = useEffectEvent(callback !== null && callback !== void 0 ? callback : noop$1);
|
|
113
|
+
const isCallbackDefined = Boolean(callback);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!target || !name || !isCallbackDefined)
|
|
116
|
+
return;
|
|
117
|
+
const listenerCallback = eventFn;
|
|
118
|
+
target.addEventListener(name, listenerCallback);
|
|
119
|
+
return () => target.removeEventListener(name, listenerCallback);
|
|
120
|
+
}, [target, name, isCallbackDefined]);
|
|
121
|
+
}
|
|
122
|
+
function __rest(s, e) {
|
|
123
|
+
var t = {};
|
|
124
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
125
|
+
t[p] = s[p];
|
|
126
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
127
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
128
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
129
|
+
t[p[i]] = s[p[i]];
|
|
130
|
+
}
|
|
131
|
+
return t;
|
|
132
|
+
}
|
|
133
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
134
|
+
function adopt(value) {
|
|
135
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
136
|
+
resolve(value);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
140
|
+
function fulfilled(value) {
|
|
141
|
+
try {
|
|
142
|
+
step(generator.next(value));
|
|
143
|
+
} catch (e) {
|
|
144
|
+
reject(e);
|
|
96
145
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
for (i = length; i-- !== 0; )
|
|
104
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
105
|
-
for (i = length; i-- !== 0; ) {
|
|
106
|
-
var key = keys[i];
|
|
107
|
-
if (!equal(a[key], b[key])) return false;
|
|
146
|
+
}
|
|
147
|
+
function rejected(value) {
|
|
148
|
+
try {
|
|
149
|
+
step(generator["throw"](value));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
reject(e);
|
|
108
152
|
}
|
|
153
|
+
}
|
|
154
|
+
function step(result) {
|
|
155
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
156
|
+
}
|
|
157
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
161
|
+
var e = new Error(message);
|
|
162
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
163
|
+
};
|
|
164
|
+
const MSG_REPEATED_SET_OPTIONS = (options) => `The setOptions() function should only be called once. The options passed to the additional call (${JSON.stringify(options)}) will be ignored.`;
|
|
165
|
+
const MSG_IMPORT_LIBRARY_EXISTS = (options) => `The google.maps.importLibrary() function is already defined, and @googlemaps/js-api-loader will use the existing function instead of overwriting it. The options passed to setOptions (${JSON.stringify(options)}) will be ignored.`;
|
|
166
|
+
const MSG_SET_OPTIONS_NOT_CALLED = "No options were set before calling importLibrary. Make sure to configure the loader using setOptions().";
|
|
167
|
+
const MSG_SCRIPT_ELEMENT_EXISTS = "There already is a script loading the Google Maps JavaScript API, and no google.maps.importLibrary function is defined. @googlemaps/js-api-loader will proceed to bootstrap the API with the specified options, but the existing script might cause problems using the API. Make sure to remove the script loading the API.";
|
|
168
|
+
const MSG_API_KEY_USED = "The 'apiKey' parameter was used in setOptions(), but 'key' is the correct parameter name. Please update your configuration.";
|
|
169
|
+
const MSG_TRUSTED_TYPES_POLICY_FAILED = (policyName, error) => `Failed to create Trusted Types policy "${policyName}": ${error instanceof Error ? error.message : String(error)}.
|
|
170
|
+
|
|
171
|
+
If your Content Security Policy uses "require-trusted-types-for 'script'", allow this policy with "trusted-types ${policyName} google-maps-api-loader google-maps-api#html lit-html". The "google-maps-api-loader", "lit-html", and "google-maps-api#html" policies are required for full Maps JavaScript API execution. Falling back to a string script URL.`;
|
|
172
|
+
const __DEV__$1 = process.env.NODE_ENV !== "production";
|
|
173
|
+
const logDevWarning = __DEV__$1 ? (message) => {
|
|
174
|
+
console.warn(`[@googlemaps/js-api-loader] ${message}`);
|
|
175
|
+
} : () => {
|
|
176
|
+
};
|
|
177
|
+
const logDevNotice = __DEV__$1 ? (message) => {
|
|
178
|
+
console.info(`[@googlemaps/js-api-loader] ${message}`);
|
|
179
|
+
} : () => {
|
|
180
|
+
};
|
|
181
|
+
const TRUSTED_TYPES_POLICY_NAME = "@googlemaps/js-api-loader";
|
|
182
|
+
const fallbackPolicy = { createScriptURL: (url) => url };
|
|
183
|
+
let policy;
|
|
184
|
+
function getPolicy() {
|
|
185
|
+
if (policy) {
|
|
186
|
+
return policy;
|
|
187
|
+
}
|
|
188
|
+
const trustedTypes = globalThis.trustedTypes;
|
|
189
|
+
if (!trustedTypes) {
|
|
190
|
+
policy = fallbackPolicy;
|
|
191
|
+
return policy;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
policy = trustedTypes.createPolicy(TRUSTED_TYPES_POLICY_NAME, {
|
|
195
|
+
createScriptURL: (url) => url
|
|
196
|
+
});
|
|
197
|
+
} catch (e) {
|
|
198
|
+
logDevWarning(MSG_TRUSTED_TYPES_POLICY_FAILED(TRUSTED_TYPES_POLICY_NAME, e));
|
|
199
|
+
policy = fallbackPolicy;
|
|
200
|
+
}
|
|
201
|
+
return policy;
|
|
202
|
+
}
|
|
203
|
+
function setScriptSrc(script, src) {
|
|
204
|
+
script.src = getPolicy().createScriptURL(src);
|
|
205
|
+
}
|
|
206
|
+
const bootstrap = (bootstrapParams) => {
|
|
207
|
+
var bootstrapPromise;
|
|
208
|
+
var script;
|
|
209
|
+
var bootstrapParamsKey;
|
|
210
|
+
var PRODUCT_NAME = "The Google Maps JavaScript API";
|
|
211
|
+
var GOOGLE = "google";
|
|
212
|
+
var IMPORT_API_NAME = "importLibrary";
|
|
213
|
+
var PENDING_BOOTSTRAP_KEY = "__ib__";
|
|
214
|
+
var doc = document;
|
|
215
|
+
var global_ = window;
|
|
216
|
+
var google_ = global_[GOOGLE] || (global_[GOOGLE] = {});
|
|
217
|
+
var namespace = google_.maps || (google_.maps = {});
|
|
218
|
+
var libraries = /* @__PURE__ */ new Set();
|
|
219
|
+
var searchParams = new URLSearchParams();
|
|
220
|
+
var triggerBootstrap = () => bootstrapPromise || (bootstrapPromise = new Promise(async (resolve, reject) => {
|
|
221
|
+
var _a;
|
|
222
|
+
await (script = doc.createElement("script"));
|
|
223
|
+
searchParams.set("libraries", [...libraries] + "");
|
|
224
|
+
for (bootstrapParamsKey in bootstrapParams) {
|
|
225
|
+
searchParams.set(bootstrapParamsKey.replace(/[A-Z]/g, (g) => "_" + g[0].toLowerCase()), bootstrapParams[bootstrapParamsKey]);
|
|
226
|
+
}
|
|
227
|
+
searchParams.set("callback", GOOGLE + ".maps." + PENDING_BOOTSTRAP_KEY);
|
|
228
|
+
setScriptSrc(script, "https://maps.googleapis.com/maps/api/js?" + searchParams);
|
|
229
|
+
namespace[PENDING_BOOTSTRAP_KEY] = resolve;
|
|
230
|
+
script.onerror = () => bootstrapPromise = reject(Error(PRODUCT_NAME + " could not load."));
|
|
231
|
+
script.nonce = ((_a = doc.querySelector("script[nonce]")) == null ? void 0 : _a.nonce) || "";
|
|
232
|
+
doc.head.append(script);
|
|
233
|
+
}));
|
|
234
|
+
namespace[IMPORT_API_NAME] ? console.warn(PRODUCT_NAME + " only loads once. Ignoring:", bootstrapParams) : namespace[IMPORT_API_NAME] = (libraryName, ...args) => libraries.add(libraryName) && triggerBootstrap().then(() => namespace[IMPORT_API_NAME](libraryName, ...args));
|
|
235
|
+
};
|
|
236
|
+
const __DEV__ = process.env.NODE_ENV !== "production";
|
|
237
|
+
let setOptionsWasCalled_ = false;
|
|
238
|
+
function setOptions(options) {
|
|
239
|
+
if (setOptionsWasCalled_) {
|
|
240
|
+
logDevWarning(MSG_REPEATED_SET_OPTIONS(options));
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (options.apiKey) {
|
|
244
|
+
logDevWarning(MSG_API_KEY_USED);
|
|
245
|
+
if (!options.key) {
|
|
246
|
+
options.key = options.apiKey;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
installImportLibrary_(options);
|
|
250
|
+
setOptionsWasCalled_ = true;
|
|
251
|
+
}
|
|
252
|
+
async function importLibrary(libraryName) {
|
|
253
|
+
var _a, _b;
|
|
254
|
+
if (!setOptionsWasCalled_) {
|
|
255
|
+
logDevWarning(MSG_SET_OPTIONS_NOT_CALLED);
|
|
256
|
+
}
|
|
257
|
+
if (!((_b = (_a = window == null ? void 0 : window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.importLibrary)) {
|
|
258
|
+
throw new Error("google.maps.importLibrary is not installed.");
|
|
259
|
+
}
|
|
260
|
+
return await google.maps.importLibrary(libraryName);
|
|
261
|
+
}
|
|
262
|
+
function installImportLibrary_(options) {
|
|
263
|
+
var _a, _b;
|
|
264
|
+
const importLibraryExists = Boolean((_b = (_a = window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.importLibrary);
|
|
265
|
+
if (importLibraryExists) {
|
|
266
|
+
logDevNotice(MSG_IMPORT_LIBRARY_EXISTS(options));
|
|
267
|
+
} else if (__DEV__) {
|
|
268
|
+
const scriptEl = document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
|
|
269
|
+
if (scriptEl) {
|
|
270
|
+
logDevWarning(MSG_SCRIPT_ELEMENT_EXISTS);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!importLibraryExists) {
|
|
274
|
+
bootstrap(options);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const APILoadingStatus = {
|
|
278
|
+
NOT_LOADED: "NOT_LOADED",
|
|
279
|
+
LOADING: "LOADING",
|
|
280
|
+
LOADED: "LOADED",
|
|
281
|
+
FAILED: "FAILED",
|
|
282
|
+
AUTH_FAILURE: "AUTH_FAILURE"
|
|
283
|
+
};
|
|
284
|
+
const VERSION = "1.10.1";
|
|
285
|
+
const DEFAULT_SOLUTION_CHANNEL = "GMP_visgl_rgmlibrary_v1_default";
|
|
286
|
+
const DEFAULT_INTERNAL_USAGE_ATTRIBUTION_IDS = [
|
|
287
|
+
`gmp_visgl_reactgooglemaps_v${VERSION}`
|
|
288
|
+
];
|
|
289
|
+
const APIProviderContext = React__default.createContext(null);
|
|
290
|
+
let loadingStatus = APILoadingStatus.NOT_LOADED;
|
|
291
|
+
let serializedApiParams;
|
|
292
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
293
|
+
function updateLoadingStatus(status) {
|
|
294
|
+
if (status === loadingStatus) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
loadingStatus = status;
|
|
298
|
+
listeners.forEach((listener) => listener(loadingStatus));
|
|
299
|
+
}
|
|
300
|
+
function useMapInstances() {
|
|
301
|
+
const [mapInstances, setMapInstances] = useState({});
|
|
302
|
+
const addMapInstance = (mapInstance, id = "default") => {
|
|
303
|
+
setMapInstances((instances) => Object.assign(Object.assign({}, instances), { [id]: mapInstance }));
|
|
304
|
+
};
|
|
305
|
+
const removeMapInstance = (id = "default") => {
|
|
306
|
+
setMapInstances((_a) => {
|
|
307
|
+
var _b = id;
|
|
308
|
+
_a[_b];
|
|
309
|
+
var remaining = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
310
|
+
return remaining;
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const clearMapInstances = () => {
|
|
314
|
+
setMapInstances({});
|
|
315
|
+
};
|
|
316
|
+
return { mapInstances, addMapInstance, removeMapInstance, clearMapInstances };
|
|
317
|
+
}
|
|
318
|
+
function useMap3DInstances() {
|
|
319
|
+
const [map3dInstances, setMap3DInstances] = useState({});
|
|
320
|
+
const addMap3DInstance = (map3dInstance, id = "default") => {
|
|
321
|
+
setMap3DInstances((instances) => Object.assign(Object.assign({}, instances), { [id]: map3dInstance }));
|
|
322
|
+
};
|
|
323
|
+
const removeMap3DInstance = (id = "default") => {
|
|
324
|
+
setMap3DInstances((_a) => {
|
|
325
|
+
var _b = id;
|
|
326
|
+
_a[_b];
|
|
327
|
+
var remaining = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
328
|
+
return remaining;
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const clearMap3DInstances = () => {
|
|
332
|
+
setMap3DInstances({});
|
|
333
|
+
};
|
|
334
|
+
return {
|
|
335
|
+
map3dInstances,
|
|
336
|
+
addMap3DInstance,
|
|
337
|
+
removeMap3DInstance,
|
|
338
|
+
clearMap3DInstances
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function useGoogleMapsApiLoader(props) {
|
|
342
|
+
const { onLoad, onError, apiKey, version, libraries = [], region, language, authReferrerPolicy, channel, solutionChannel, fetchAppCheckToken } = props;
|
|
343
|
+
const [status, setStatus] = useState(loadingStatus);
|
|
344
|
+
const [loadedLibraries, addLoadedLibrary] = useReducer((loadedLibraries2, action) => {
|
|
345
|
+
return loadedLibraries2[action.name] ? loadedLibraries2 : Object.assign(Object.assign({}, loadedLibraries2), { [action.name]: action.value });
|
|
346
|
+
}, {});
|
|
347
|
+
const currentSerializedParams = useMemo(() => {
|
|
348
|
+
const params = {
|
|
349
|
+
apiKey,
|
|
350
|
+
version,
|
|
351
|
+
libraries: libraries.join(","),
|
|
352
|
+
region,
|
|
353
|
+
language,
|
|
354
|
+
authReferrerPolicy,
|
|
355
|
+
channel,
|
|
356
|
+
solutionChannel
|
|
357
|
+
};
|
|
358
|
+
return JSON.stringify(params);
|
|
359
|
+
}, [
|
|
360
|
+
apiKey,
|
|
361
|
+
version,
|
|
362
|
+
libraries,
|
|
363
|
+
region,
|
|
364
|
+
language,
|
|
365
|
+
authReferrerPolicy,
|
|
366
|
+
channel,
|
|
367
|
+
solutionChannel
|
|
368
|
+
]);
|
|
369
|
+
const importLibraryCallback = useCallback((name) => __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
if (loadedLibraries[name]) {
|
|
371
|
+
return loadedLibraries[name];
|
|
372
|
+
}
|
|
373
|
+
const res = yield importLibrary(name);
|
|
374
|
+
addLoadedLibrary({ name, value: res });
|
|
375
|
+
return res;
|
|
376
|
+
}), [loadedLibraries]);
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
listeners.add(setStatus);
|
|
379
|
+
setStatus(loadingStatus);
|
|
380
|
+
return () => {
|
|
381
|
+
listeners.delete(setStatus);
|
|
382
|
+
};
|
|
383
|
+
}, []);
|
|
384
|
+
useEffect(
|
|
385
|
+
() => {
|
|
386
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
try {
|
|
389
|
+
if (serializedApiParams && serializedApiParams !== currentSerializedParams) {
|
|
390
|
+
console.warn(`The Google Maps JavaScript API has already been loaded with different parameters. The new parameters will be ignored. If you need to use different parameters, please refresh the page.`);
|
|
391
|
+
}
|
|
392
|
+
const librariesToLoad = [
|
|
393
|
+
"core",
|
|
394
|
+
"maps",
|
|
395
|
+
...libraries
|
|
396
|
+
];
|
|
397
|
+
const options = Object.fromEntries(Object.entries({
|
|
398
|
+
key: apiKey,
|
|
399
|
+
v: version,
|
|
400
|
+
libraries,
|
|
401
|
+
region,
|
|
402
|
+
language,
|
|
403
|
+
authReferrerPolicy
|
|
404
|
+
}).filter(([, value]) => value !== void 0));
|
|
405
|
+
if (channel !== void 0 && channel >= 0 && channel <= 999) {
|
|
406
|
+
options.channel = String(channel);
|
|
407
|
+
}
|
|
408
|
+
if (solutionChannel === void 0) {
|
|
409
|
+
options.solutionChannel = DEFAULT_SOLUTION_CHANNEL;
|
|
410
|
+
} else if (solutionChannel !== "") {
|
|
411
|
+
options.solutionChannel = solutionChannel;
|
|
412
|
+
}
|
|
413
|
+
if ((_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.importLibrary) {
|
|
414
|
+
const shouldUpdateLoadingStatus = !serializedApiParams;
|
|
415
|
+
if (shouldUpdateLoadingStatus) {
|
|
416
|
+
serializedApiParams = currentSerializedParams;
|
|
417
|
+
setOptions(options);
|
|
418
|
+
}
|
|
419
|
+
yield Promise.all(librariesToLoad.map((name) => importLibraryCallback(name)));
|
|
420
|
+
if (shouldUpdateLoadingStatus) {
|
|
421
|
+
updateLoadingStatus(APILoadingStatus.LOADED);
|
|
422
|
+
}
|
|
423
|
+
if (onLoad)
|
|
424
|
+
onLoad();
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (loadingStatus === APILoadingStatus.LOADING || loadingStatus === APILoadingStatus.LOADED) {
|
|
428
|
+
if (loadingStatus === APILoadingStatus.LOADED && onLoad)
|
|
429
|
+
onLoad();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
serializedApiParams = currentSerializedParams;
|
|
433
|
+
updateLoadingStatus(APILoadingStatus.LOADING);
|
|
434
|
+
setOptions(options);
|
|
435
|
+
yield Promise.all(librariesToLoad.map((name) => importLibraryCallback(name)));
|
|
436
|
+
updateLoadingStatus(APILoadingStatus.LOADED);
|
|
437
|
+
if (onLoad) {
|
|
438
|
+
onLoad();
|
|
439
|
+
}
|
|
440
|
+
} catch (error) {
|
|
441
|
+
updateLoadingStatus(APILoadingStatus.FAILED);
|
|
442
|
+
if (onError) {
|
|
443
|
+
onError(error);
|
|
444
|
+
} else {
|
|
445
|
+
console.error("The Google Maps JavaScript API failed to load.", error);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}))();
|
|
449
|
+
},
|
|
450
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
451
|
+
[currentSerializedParams, onLoad, onError, importLibraryCallback, libraries]
|
|
452
|
+
);
|
|
453
|
+
useEffect(() => {
|
|
454
|
+
if (status !== APILoadingStatus.LOADED)
|
|
455
|
+
return;
|
|
456
|
+
const settings = google.maps.Settings.getInstance();
|
|
457
|
+
if (fetchAppCheckToken) {
|
|
458
|
+
settings.fetchAppCheckToken = fetchAppCheckToken;
|
|
459
|
+
}
|
|
460
|
+
}, [status, fetchAppCheckToken]);
|
|
461
|
+
return {
|
|
462
|
+
status,
|
|
463
|
+
loadedLibraries,
|
|
464
|
+
importLibrary: importLibraryCallback
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function useInternalUsageAttributionIds(props) {
|
|
468
|
+
return useMemo(() => props.disableUsageAttribution ? null : DEFAULT_INTERNAL_USAGE_ATTRIBUTION_IDS, [props.disableUsageAttribution]);
|
|
469
|
+
}
|
|
470
|
+
const APIProvider = (props) => {
|
|
471
|
+
const { children } = props, loaderProps = __rest(props, ["children"]);
|
|
472
|
+
const { mapInstances, addMapInstance, removeMapInstance, clearMapInstances } = useMapInstances();
|
|
473
|
+
const { map3dInstances, addMap3DInstance, removeMap3DInstance, clearMap3DInstances } = useMap3DInstances();
|
|
474
|
+
const { status, loadedLibraries, importLibrary: importLibrary2 } = useGoogleMapsApiLoader(loaderProps);
|
|
475
|
+
const internalUsageAttributionIds = useInternalUsageAttributionIds(loaderProps);
|
|
476
|
+
const contextValue = useMemo(() => ({
|
|
477
|
+
mapInstances,
|
|
478
|
+
addMapInstance,
|
|
479
|
+
removeMapInstance,
|
|
480
|
+
clearMapInstances,
|
|
481
|
+
map3dInstances,
|
|
482
|
+
addMap3DInstance,
|
|
483
|
+
removeMap3DInstance,
|
|
484
|
+
clearMap3DInstances,
|
|
485
|
+
status,
|
|
486
|
+
loadedLibraries,
|
|
487
|
+
importLibrary: importLibrary2,
|
|
488
|
+
internalUsageAttributionIds
|
|
489
|
+
}), [
|
|
490
|
+
mapInstances,
|
|
491
|
+
addMapInstance,
|
|
492
|
+
removeMapInstance,
|
|
493
|
+
clearMapInstances,
|
|
494
|
+
map3dInstances,
|
|
495
|
+
addMap3DInstance,
|
|
496
|
+
removeMap3DInstance,
|
|
497
|
+
clearMap3DInstances,
|
|
498
|
+
status,
|
|
499
|
+
loadedLibraries,
|
|
500
|
+
importLibrary2,
|
|
501
|
+
internalUsageAttributionIds
|
|
502
|
+
]);
|
|
503
|
+
return React__default.createElement(APIProviderContext.Provider, { value: contextValue }, children);
|
|
504
|
+
};
|
|
505
|
+
function useCallbackRef() {
|
|
506
|
+
const [el, setEl] = useState(null);
|
|
507
|
+
const ref = useCallback((value) => setEl(value), [setEl]);
|
|
508
|
+
return [el, ref];
|
|
509
|
+
}
|
|
510
|
+
function useApiLoadingStatus() {
|
|
511
|
+
var _a;
|
|
512
|
+
return ((_a = useContext(APIProviderContext)) === null || _a === void 0 ? void 0 : _a.status) || APILoadingStatus.NOT_LOADED;
|
|
513
|
+
}
|
|
514
|
+
function useApiIsLoaded() {
|
|
515
|
+
const status = useApiLoadingStatus();
|
|
516
|
+
return status === APILoadingStatus.LOADED;
|
|
517
|
+
}
|
|
518
|
+
function useMapsLibrary(name) {
|
|
519
|
+
var _a;
|
|
520
|
+
const apiIsLoaded = useApiIsLoaded();
|
|
521
|
+
const ctx = useContext(APIProviderContext);
|
|
522
|
+
useEffect(() => {
|
|
523
|
+
if (!apiIsLoaded || !ctx)
|
|
524
|
+
return;
|
|
525
|
+
void ctx.importLibrary(name);
|
|
526
|
+
}, [apiIsLoaded, ctx, name]);
|
|
527
|
+
return (_a = ctx === null || ctx === void 0 ? void 0 : ctx.loadedLibraries[name]) !== null && _a !== void 0 ? _a : null;
|
|
528
|
+
}
|
|
529
|
+
function useForceUpdate() {
|
|
530
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
531
|
+
return forceUpdate;
|
|
532
|
+
}
|
|
533
|
+
const DEFAULT_CAMERA_STATE = {
|
|
534
|
+
center: { lat: 0, lng: 0, altitude: 0 },
|
|
535
|
+
range: 0,
|
|
536
|
+
heading: 0,
|
|
537
|
+
tilt: 0,
|
|
538
|
+
roll: 0
|
|
539
|
+
};
|
|
540
|
+
const CAMERA_PROPS = ["center", "range", "heading", "tilt", "roll"];
|
|
541
|
+
function updateCameraState(map3d, ref, prop) {
|
|
542
|
+
const value = map3d[prop];
|
|
543
|
+
if (value == null)
|
|
544
|
+
return;
|
|
545
|
+
if (prop === "center") {
|
|
546
|
+
const center = value;
|
|
547
|
+
ref.current.center = center.toJSON ? center.toJSON() : center;
|
|
548
|
+
} else {
|
|
549
|
+
ref.current[prop] = value;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function useTrackedCameraStateRef3D(map3d) {
|
|
553
|
+
const forceUpdate = useForceUpdate();
|
|
554
|
+
const ref = useRef(Object.assign({}, DEFAULT_CAMERA_STATE));
|
|
555
|
+
useEffect(() => {
|
|
556
|
+
if (!map3d)
|
|
557
|
+
return;
|
|
558
|
+
const listeners2 = [];
|
|
559
|
+
for (const prop of CAMERA_PROPS) {
|
|
560
|
+
const eventName = `gmp-${prop}change`;
|
|
561
|
+
const handler = () => {
|
|
562
|
+
updateCameraState(map3d, ref, prop);
|
|
563
|
+
forceUpdate();
|
|
564
|
+
};
|
|
565
|
+
map3d.addEventListener(eventName, handler);
|
|
566
|
+
listeners2.push(() => map3d.removeEventListener(eventName, handler));
|
|
567
|
+
}
|
|
568
|
+
return () => {
|
|
569
|
+
for (const removeListener of listeners2) {
|
|
570
|
+
removeListener();
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}, [map3d, forceUpdate]);
|
|
574
|
+
return ref;
|
|
575
|
+
}
|
|
576
|
+
function useMap3DInstance(props) {
|
|
577
|
+
const maps3dLib = useMapsLibrary("maps3d");
|
|
578
|
+
const [customElementReady, setCustomElementReady] = useState(false);
|
|
579
|
+
const [, containerRef] = useCallbackRef();
|
|
580
|
+
const [map3d, map3dRef] = useCallbackRef();
|
|
581
|
+
const cameraStateRef = useTrackedCameraStateRef3D(map3d);
|
|
582
|
+
useEffect(() => {
|
|
583
|
+
customElements.whenDefined("gmp-map-3d").then(() => {
|
|
584
|
+
setCustomElementReady(true);
|
|
585
|
+
});
|
|
586
|
+
}, []);
|
|
587
|
+
useEffect(
|
|
588
|
+
() => {
|
|
589
|
+
if (!map3d)
|
|
590
|
+
return;
|
|
591
|
+
const {
|
|
592
|
+
center,
|
|
593
|
+
heading,
|
|
594
|
+
tilt,
|
|
595
|
+
range,
|
|
596
|
+
roll,
|
|
597
|
+
defaultCenter,
|
|
598
|
+
defaultHeading,
|
|
599
|
+
defaultTilt,
|
|
600
|
+
defaultRange,
|
|
601
|
+
defaultRoll,
|
|
602
|
+
// Non-element props to exclude
|
|
603
|
+
id,
|
|
604
|
+
style: style2,
|
|
605
|
+
className,
|
|
606
|
+
children,
|
|
607
|
+
onCenterChanged,
|
|
608
|
+
onHeadingChanged,
|
|
609
|
+
onTiltChanged,
|
|
610
|
+
onRangeChanged,
|
|
611
|
+
onRollChanged,
|
|
612
|
+
onCameraChanged,
|
|
613
|
+
onClick,
|
|
614
|
+
onSteadyChange,
|
|
615
|
+
onAnimationEnd,
|
|
616
|
+
onError,
|
|
617
|
+
mode,
|
|
618
|
+
gestureHandling
|
|
619
|
+
} = props, elementOptions = __rest(props, ["center", "heading", "tilt", "range", "roll", "defaultCenter", "defaultHeading", "defaultTilt", "defaultRange", "defaultRoll", "id", "style", "className", "children", "onCenterChanged", "onHeadingChanged", "onTiltChanged", "onRangeChanged", "onRollChanged", "onCameraChanged", "onClick", "onSteadyChange", "onAnimationEnd", "onError", "mode", "gestureHandling"]);
|
|
620
|
+
const initialCenter = center !== null && center !== void 0 ? center : defaultCenter;
|
|
621
|
+
const initialHeading = heading !== null && heading !== void 0 ? heading : defaultHeading;
|
|
622
|
+
const initialTilt = tilt !== null && tilt !== void 0 ? tilt : defaultTilt;
|
|
623
|
+
const initialRange = range !== null && range !== void 0 ? range : defaultRange;
|
|
624
|
+
const initialRoll = roll !== null && roll !== void 0 ? roll : defaultRoll;
|
|
625
|
+
const initialOptions = Object.assign({}, elementOptions);
|
|
626
|
+
if (initialCenter)
|
|
627
|
+
initialOptions.center = initialCenter;
|
|
628
|
+
if (initialHeading !== void 0)
|
|
629
|
+
initialOptions.heading = initialHeading;
|
|
630
|
+
if (initialTilt !== void 0)
|
|
631
|
+
initialOptions.tilt = initialTilt;
|
|
632
|
+
if (initialRange !== void 0)
|
|
633
|
+
initialOptions.range = initialRange;
|
|
634
|
+
if (initialRoll !== void 0)
|
|
635
|
+
initialOptions.roll = initialRoll;
|
|
636
|
+
Object.assign(map3d, initialOptions);
|
|
637
|
+
},
|
|
638
|
+
// this effect should only run when the map3d element first becomes
|
|
639
|
+
// available, so we skip re-running it when other props change.
|
|
640
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
641
|
+
[map3d]
|
|
642
|
+
);
|
|
643
|
+
const isReady = !!maps3dLib && customElementReady;
|
|
644
|
+
return [map3d, containerRef, map3dRef, cameraStateRef, isReady];
|
|
645
|
+
}
|
|
646
|
+
function toLatLngAltitudeLiteral(value) {
|
|
647
|
+
if (!value)
|
|
648
|
+
return null;
|
|
649
|
+
if ("toJSON" in value && typeof value.toJSON === "function") {
|
|
650
|
+
return value.toJSON();
|
|
651
|
+
}
|
|
652
|
+
return value;
|
|
653
|
+
}
|
|
654
|
+
function useMap3DCameraParams(map3d, cameraStateRef, props) {
|
|
655
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
656
|
+
const centerLiteral = toLatLngAltitudeLiteral(props.center);
|
|
657
|
+
const lat = (_a = centerLiteral === null || centerLiteral === void 0 ? void 0 : centerLiteral.lat) !== null && _a !== void 0 ? _a : null;
|
|
658
|
+
const lng = (_b = centerLiteral === null || centerLiteral === void 0 ? void 0 : centerLiteral.lng) !== null && _b !== void 0 ? _b : null;
|
|
659
|
+
const altitude = (_c = centerLiteral === null || centerLiteral === void 0 ? void 0 : centerLiteral.altitude) !== null && _c !== void 0 ? _c : null;
|
|
660
|
+
const range = (_d = props.range) !== null && _d !== void 0 ? _d : null;
|
|
661
|
+
const heading = (_e = props.heading) !== null && _e !== void 0 ? _e : null;
|
|
662
|
+
const tilt = (_f = props.tilt) !== null && _f !== void 0 ? _f : null;
|
|
663
|
+
const roll = (_g = props.roll) !== null && _g !== void 0 ? _g : null;
|
|
664
|
+
useLayoutEffect(() => {
|
|
665
|
+
var _a2;
|
|
666
|
+
if (!map3d)
|
|
667
|
+
return;
|
|
668
|
+
const currentState = cameraStateRef.current;
|
|
669
|
+
if (lat !== null && lng !== null && (currentState.center.lat !== lat || currentState.center.lng !== lng || altitude !== null && currentState.center.altitude !== altitude)) {
|
|
670
|
+
map3d.center = {
|
|
671
|
+
lat,
|
|
672
|
+
lng,
|
|
673
|
+
altitude: (_a2 = altitude !== null && altitude !== void 0 ? altitude : currentState.center.altitude) !== null && _a2 !== void 0 ? _a2 : 0
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
if (range !== null && currentState.range !== range) {
|
|
677
|
+
map3d.range = range;
|
|
678
|
+
}
|
|
679
|
+
if (heading !== null && currentState.heading !== heading) {
|
|
680
|
+
map3d.heading = heading;
|
|
681
|
+
}
|
|
682
|
+
if (tilt !== null && currentState.tilt !== tilt) {
|
|
683
|
+
map3d.tilt = tilt;
|
|
684
|
+
}
|
|
685
|
+
if (roll !== null && currentState.roll !== roll) {
|
|
686
|
+
map3d.roll = roll;
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
const CAMERA_EVENTS = [
|
|
691
|
+
"gmp-centerchange",
|
|
692
|
+
"gmp-headingchange",
|
|
693
|
+
"gmp-tiltchange",
|
|
694
|
+
"gmp-rangechange",
|
|
695
|
+
"gmp-rollchange"
|
|
696
|
+
];
|
|
697
|
+
function createCameraEvent(map3d, type) {
|
|
698
|
+
const center = map3d.center;
|
|
699
|
+
let centerLiteral;
|
|
700
|
+
if (center && "toJSON" in center && typeof center.toJSON === "function") {
|
|
701
|
+
centerLiteral = center.toJSON();
|
|
702
|
+
} else if (center) {
|
|
703
|
+
centerLiteral = center;
|
|
704
|
+
} else {
|
|
705
|
+
centerLiteral = { lat: 0, lng: 0, altitude: 0 };
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
type,
|
|
709
|
+
map3d,
|
|
710
|
+
detail: {
|
|
711
|
+
center: centerLiteral,
|
|
712
|
+
range: map3d.range || 0,
|
|
713
|
+
heading: map3d.heading || 0,
|
|
714
|
+
tilt: map3d.tilt || 0,
|
|
715
|
+
roll: map3d.roll || 0
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function createClickEvent(map3d, srcEvent) {
|
|
720
|
+
const placeClickEvent = srcEvent;
|
|
721
|
+
return {
|
|
722
|
+
type: "gmp-click",
|
|
723
|
+
map3d,
|
|
724
|
+
detail: {
|
|
725
|
+
position: srcEvent.position || null,
|
|
726
|
+
placeId: placeClickEvent.placeId
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
function createSteadyChangeEvent(map3d, srcEvent) {
|
|
731
|
+
return {
|
|
732
|
+
type: "gmp-steadychange",
|
|
733
|
+
map3d,
|
|
734
|
+
detail: {
|
|
735
|
+
isSteady: srcEvent.isSteady
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function useMap3DEvents(map3d, props) {
|
|
740
|
+
const { onCenterChanged, onHeadingChanged, onTiltChanged, onRangeChanged, onRollChanged, onCameraChanged, onClick, onSteadyChange, onAnimationEnd, onError } = props;
|
|
741
|
+
useMap3DEvent(map3d, "gmp-centerchange", onCenterChanged, createCameraEvent);
|
|
742
|
+
useMap3DEvent(map3d, "gmp-headingchange", onHeadingChanged, createCameraEvent);
|
|
743
|
+
useMap3DEvent(map3d, "gmp-tiltchange", onTiltChanged, createCameraEvent);
|
|
744
|
+
useMap3DEvent(map3d, "gmp-rangechange", onRangeChanged, createCameraEvent);
|
|
745
|
+
useMap3DEvent(map3d, "gmp-rollchange", onRollChanged, createCameraEvent);
|
|
746
|
+
useEffect(() => {
|
|
747
|
+
if (!map3d || !onCameraChanged)
|
|
748
|
+
return;
|
|
749
|
+
const handler = () => {
|
|
750
|
+
onCameraChanged(createCameraEvent(map3d, "camerachange"));
|
|
751
|
+
};
|
|
752
|
+
for (const eventName of CAMERA_EVENTS) {
|
|
753
|
+
map3d.addEventListener(eventName, handler);
|
|
754
|
+
}
|
|
755
|
+
return () => {
|
|
756
|
+
for (const eventName of CAMERA_EVENTS) {
|
|
757
|
+
map3d.removeEventListener(eventName, handler);
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}, [map3d, onCameraChanged]);
|
|
761
|
+
useEffect(() => {
|
|
762
|
+
if (!map3d || !onClick)
|
|
763
|
+
return;
|
|
764
|
+
const handler = (ev) => {
|
|
765
|
+
onClick(createClickEvent(map3d, ev));
|
|
766
|
+
};
|
|
767
|
+
map3d.addEventListener("gmp-click", handler);
|
|
768
|
+
return () => map3d.removeEventListener("gmp-click", handler);
|
|
769
|
+
}, [map3d, onClick]);
|
|
770
|
+
useEffect(() => {
|
|
771
|
+
if (!map3d || !onSteadyChange)
|
|
772
|
+
return;
|
|
773
|
+
const handler = (ev) => {
|
|
774
|
+
onSteadyChange(createSteadyChangeEvent(map3d, ev));
|
|
775
|
+
};
|
|
776
|
+
map3d.addEventListener("gmp-steadychange", handler);
|
|
777
|
+
return () => map3d.removeEventListener("gmp-steadychange", handler);
|
|
778
|
+
}, [map3d, onSteadyChange]);
|
|
779
|
+
useMap3DEvent(map3d, "gmp-animationend", onAnimationEnd, (map3d2, type) => ({
|
|
780
|
+
type,
|
|
781
|
+
map3d: map3d2
|
|
782
|
+
}));
|
|
783
|
+
useMap3DEvent(map3d, "gmp-error", onError, (map3d2, type) => ({
|
|
784
|
+
type,
|
|
785
|
+
map3d: map3d2
|
|
786
|
+
}));
|
|
787
|
+
}
|
|
788
|
+
function useMap3DEvent(map3d, eventName, handler, createEvent) {
|
|
789
|
+
useEffect(() => {
|
|
790
|
+
if (!map3d || !handler)
|
|
791
|
+
return;
|
|
792
|
+
const listener = () => {
|
|
793
|
+
handler(createEvent(map3d, eventName));
|
|
794
|
+
};
|
|
795
|
+
map3d.addEventListener(eventName, listener);
|
|
796
|
+
return () => map3d.removeEventListener(eventName, listener);
|
|
797
|
+
}, [map3d, eventName, handler, createEvent]);
|
|
798
|
+
}
|
|
799
|
+
function useMemoized(value, isEqual) {
|
|
800
|
+
const ref = useRef(value);
|
|
801
|
+
if (!isEqual(value, ref.current)) {
|
|
802
|
+
ref.current = value;
|
|
803
|
+
}
|
|
804
|
+
return ref.current;
|
|
805
|
+
}
|
|
806
|
+
function useCustomCompareEffect(effect, dependencies, isEqual) {
|
|
807
|
+
useEffect(effect, [useMemoized(dependencies, isEqual)]);
|
|
808
|
+
}
|
|
809
|
+
const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
|
|
810
|
+
const { hasOwnProperty } = Object.prototype;
|
|
811
|
+
function combineComparators(comparatorA, comparatorB) {
|
|
812
|
+
return function isEqual(a, b, state) {
|
|
813
|
+
return comparatorA(a, b, state) && comparatorB(a, b, state);
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function createIsCircular(areItemsEqual) {
|
|
817
|
+
return function isCircular(a, b, state) {
|
|
818
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") {
|
|
819
|
+
return areItemsEqual(a, b, state);
|
|
820
|
+
}
|
|
821
|
+
const { cache } = state;
|
|
822
|
+
const cachedA = cache.get(a);
|
|
823
|
+
const cachedB = cache.get(b);
|
|
824
|
+
if (cachedA && cachedB) {
|
|
825
|
+
return cachedA === b && cachedB === a;
|
|
826
|
+
}
|
|
827
|
+
cache.set(a, b);
|
|
828
|
+
cache.set(b, a);
|
|
829
|
+
const result = areItemsEqual(a, b, state);
|
|
830
|
+
cache.delete(a);
|
|
831
|
+
cache.delete(b);
|
|
832
|
+
return result;
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function getStrictProperties(object) {
|
|
836
|
+
const symbols = getOwnPropertySymbols(object);
|
|
837
|
+
return symbols.length ? getOwnPropertyNames(object).concat(symbols) : getOwnPropertyNames(object);
|
|
838
|
+
}
|
|
839
|
+
const hasOwn$1 = (
|
|
840
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
841
|
+
Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property))
|
|
842
|
+
);
|
|
843
|
+
const PREACT_VNODE = "__v";
|
|
844
|
+
const PREACT_OWNER = "__o";
|
|
845
|
+
const REACT_OWNER = "_owner";
|
|
846
|
+
const HAS_FLOAT_16_ARRAY = typeof Float16Array !== "undefined";
|
|
847
|
+
const { getOwnPropertyDescriptor, keys } = Object;
|
|
848
|
+
const sameValueEqual = (
|
|
849
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
850
|
+
Object.is || function sameValueEqual2(a, b) {
|
|
851
|
+
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
852
|
+
}
|
|
853
|
+
);
|
|
854
|
+
function strictEqual(a, b) {
|
|
855
|
+
return a === b;
|
|
856
|
+
}
|
|
857
|
+
function areArrayBuffersEqual(a, b) {
|
|
858
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
|
|
859
|
+
}
|
|
860
|
+
function areArraysEqual(a, b, state) {
|
|
861
|
+
let index = a.length;
|
|
862
|
+
if (b.length !== index) {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
while (index-- > 0) {
|
|
866
|
+
if (!state.equals(a[index], b[index], index, index, a, b, state)) {
|
|
867
|
+
return false;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
function areDataViewsEqual(a, b) {
|
|
873
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength));
|
|
874
|
+
}
|
|
875
|
+
function areDatesEqual(a, b) {
|
|
876
|
+
return sameValueEqual(a.getTime(), b.getTime());
|
|
877
|
+
}
|
|
878
|
+
function areErrorsEqual(a, b, state) {
|
|
879
|
+
return a.name === b.name && a.message === b.message && a.stack === b.stack && state.equals(a.cause, b.cause, "cause", "cause", a, b, state);
|
|
880
|
+
}
|
|
881
|
+
function areMapsEqual(a, b, state) {
|
|
882
|
+
const size = a.size;
|
|
883
|
+
if (size !== b.size) {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
if (!size) {
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
const matchedIndices = new Uint8Array(size);
|
|
890
|
+
const aIterable = a.entries();
|
|
891
|
+
let aResult;
|
|
892
|
+
let bResult;
|
|
893
|
+
let index = 0;
|
|
894
|
+
while (aResult = aIterable.next()) {
|
|
895
|
+
if (aResult.done) {
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
const bIterable = b.entries();
|
|
899
|
+
let hasMatch = 0;
|
|
900
|
+
let matchIndex = 0;
|
|
901
|
+
while (bResult = bIterable.next()) {
|
|
902
|
+
if (bResult.done) {
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
if (matchedIndices[matchIndex]) {
|
|
906
|
+
matchIndex++;
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
const aEntry = aResult.value;
|
|
910
|
+
const bEntry = bResult.value;
|
|
911
|
+
if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
|
|
912
|
+
hasMatch = matchedIndices[matchIndex] = 1;
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
915
|
+
matchIndex++;
|
|
916
|
+
}
|
|
917
|
+
if (!hasMatch) {
|
|
918
|
+
return false;
|
|
919
|
+
}
|
|
920
|
+
index++;
|
|
921
|
+
}
|
|
922
|
+
return true;
|
|
923
|
+
}
|
|
924
|
+
function areObjectsEqual(a, b, state) {
|
|
925
|
+
const properties = keys(a);
|
|
926
|
+
let index = properties.length;
|
|
927
|
+
if (keys(b).length !== index) {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
while (index-- > 0) {
|
|
931
|
+
if (!isPropertyEqual(a, b, state, properties[index])) {
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
function areObjectsEqualStrict(a, b, state) {
|
|
938
|
+
const properties = getStrictProperties(a);
|
|
939
|
+
let index = properties.length;
|
|
940
|
+
if (getStrictProperties(b).length !== index) {
|
|
941
|
+
return false;
|
|
942
|
+
}
|
|
943
|
+
let property;
|
|
944
|
+
let descriptorA;
|
|
945
|
+
let descriptorB;
|
|
946
|
+
while (index-- > 0) {
|
|
947
|
+
property = properties[index];
|
|
948
|
+
if (!isPropertyEqual(a, b, state, property)) {
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
descriptorA = getOwnPropertyDescriptor(a, property);
|
|
952
|
+
descriptorB = getOwnPropertyDescriptor(b, property);
|
|
953
|
+
if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
|
|
954
|
+
return false;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return true;
|
|
958
|
+
}
|
|
959
|
+
function arePrimitiveWrappersEqual(a, b) {
|
|
960
|
+
return sameValueEqual(a.valueOf(), b.valueOf());
|
|
961
|
+
}
|
|
962
|
+
function areRegExpsEqual(a, b) {
|
|
963
|
+
return a.source === b.source && a.flags === b.flags;
|
|
964
|
+
}
|
|
965
|
+
function areSetsEqual(a, b, state) {
|
|
966
|
+
const size = a.size;
|
|
967
|
+
if (size !== b.size) {
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
if (!size) {
|
|
971
|
+
return true;
|
|
972
|
+
}
|
|
973
|
+
const matchedIndices = new Uint8Array(size);
|
|
974
|
+
const aIterable = a.values();
|
|
975
|
+
let aResult;
|
|
976
|
+
let bResult;
|
|
977
|
+
while (aResult = aIterable.next()) {
|
|
978
|
+
if (aResult.done) {
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
const bIterable = b.values();
|
|
982
|
+
let hasMatch = 0;
|
|
983
|
+
let matchIndex = 0;
|
|
984
|
+
while (bResult = bIterable.next()) {
|
|
985
|
+
if (bResult.done) {
|
|
986
|
+
break;
|
|
987
|
+
}
|
|
988
|
+
if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
|
|
989
|
+
hasMatch = matchedIndices[matchIndex] = 1;
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
matchIndex++;
|
|
993
|
+
}
|
|
994
|
+
if (!hasMatch) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return true;
|
|
999
|
+
}
|
|
1000
|
+
function areTypedArraysEqual(a, b) {
|
|
1001
|
+
let index = a.length;
|
|
1002
|
+
if (b.length !== index || a.byteOffset !== b.byteOffset) {
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
if (a instanceof Float64Array || a instanceof Float32Array || HAS_FLOAT_16_ARRAY && a instanceof Float16Array) {
|
|
1006
|
+
while (index-- > 0) {
|
|
1007
|
+
if (a[index] !== b[index] && (a[index] === a[index] || b[index] === b[index])) {
|
|
1008
|
+
return false;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
while (index-- > 0) {
|
|
1014
|
+
if (a[index] !== b[index]) {
|
|
1015
|
+
return false;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return true;
|
|
1019
|
+
}
|
|
1020
|
+
function areUrlsEqual(a, b) {
|
|
1021
|
+
if (a.href === b.href) {
|
|
1022
|
+
return true;
|
|
1023
|
+
}
|
|
1024
|
+
return a.protocol === b.protocol && a.username === b.username && a.password === b.password && a.host === b.host && a.pathname === b.pathname && a.hash === b.hash && areSearchParamsEqual(a.searchParams, b.searchParams);
|
|
1025
|
+
}
|
|
1026
|
+
function areSearchParamsEqual(a, b) {
|
|
1027
|
+
const serializedA = a.toString();
|
|
1028
|
+
const serializedB = b.toString();
|
|
1029
|
+
return serializedA === serializedB || sortSearchParams(serializedA) === sortSearchParams(serializedB);
|
|
1030
|
+
}
|
|
1031
|
+
function sortSearchParams(serialized) {
|
|
1032
|
+
return serialized.split("&").sort().join("&");
|
|
1033
|
+
}
|
|
1034
|
+
function isPropertyEqual(a, b, state, property) {
|
|
1035
|
+
if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) {
|
|
1036
|
+
return true;
|
|
1037
|
+
}
|
|
1038
|
+
return hasOwn$1(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
1039
|
+
}
|
|
1040
|
+
const toString = Object.prototype.toString;
|
|
1041
|
+
function createEqualityComparator(config) {
|
|
1042
|
+
const supportedComparatorMap = createSupportedComparatorMap(config);
|
|
1043
|
+
const { areArraysEqual: areArraysEqual2, areDatesEqual: areDatesEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areNumbersEqual, areObjectsEqual: areObjectsEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, getUnsupportedCustomComparator } = config;
|
|
1044
|
+
return function comparator(a, b, state) {
|
|
1045
|
+
if (a === b) {
|
|
109
1046
|
return true;
|
|
110
1047
|
}
|
|
111
|
-
|
|
1048
|
+
if (a == null || b == null) {
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
const type = typeof a;
|
|
1052
|
+
if (type !== typeof b) {
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
1055
|
+
if (type !== "object") {
|
|
1056
|
+
if (type === "number" || type === "bigint") {
|
|
1057
|
+
return areNumbersEqual(a, b, state);
|
|
1058
|
+
}
|
|
1059
|
+
if (type === "function") {
|
|
1060
|
+
return areFunctionsEqual(a, b, state);
|
|
1061
|
+
}
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
const constructor = a.constructor;
|
|
1065
|
+
if (constructor !== b.constructor) {
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
if (constructor === Object) {
|
|
1069
|
+
return areObjectsEqual2(a, b, state);
|
|
1070
|
+
}
|
|
1071
|
+
if (constructor === Array) {
|
|
1072
|
+
return areArraysEqual2(a, b, state);
|
|
1073
|
+
}
|
|
1074
|
+
if (constructor === Date) {
|
|
1075
|
+
return areDatesEqual2(a, b, state);
|
|
1076
|
+
}
|
|
1077
|
+
if (constructor === RegExp) {
|
|
1078
|
+
return areRegExpsEqual2(a, b, state);
|
|
1079
|
+
}
|
|
1080
|
+
if (constructor === Map) {
|
|
1081
|
+
return areMapsEqual2(a, b, state);
|
|
1082
|
+
}
|
|
1083
|
+
if (constructor === Set) {
|
|
1084
|
+
return areSetsEqual2(a, b, state);
|
|
1085
|
+
}
|
|
1086
|
+
if (constructor === Promise) {
|
|
1087
|
+
return false;
|
|
1088
|
+
}
|
|
1089
|
+
if (Array.isArray(a)) {
|
|
1090
|
+
return areArraysEqual2(a, b, state);
|
|
1091
|
+
}
|
|
1092
|
+
const tag = toString.call(a);
|
|
1093
|
+
const supportedComparator = supportedComparatorMap[tag];
|
|
1094
|
+
if (supportedComparator) {
|
|
1095
|
+
return supportedComparator(a, b, state);
|
|
1096
|
+
}
|
|
1097
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
1098
|
+
if (unsupportedCustomComparator) {
|
|
1099
|
+
return unsupportedCustomComparator(a, b, state);
|
|
1100
|
+
}
|
|
1101
|
+
return false;
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict }) {
|
|
1105
|
+
let config = {
|
|
1106
|
+
areArrayBuffersEqual,
|
|
1107
|
+
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
1108
|
+
areDataViewsEqual,
|
|
1109
|
+
areDatesEqual,
|
|
1110
|
+
// `Error` subclasses routinely carry their own enumerable properties (`status`, `code`, ...),
|
|
1111
|
+
// which the error comparator alone does not see, so it is composed with the object comparator.
|
|
1112
|
+
// `name` / `message` / `stack` are own but not enumerable, which is why errors need a
|
|
1113
|
+
// comparator of their own rather than being treated as plain objects in the first place.
|
|
1114
|
+
areErrorsEqual: strict ? combineComparators(areErrorsEqual, areObjectsEqualStrict) : combineComparators(areErrorsEqual, areObjectsEqual),
|
|
1115
|
+
areFunctionsEqual: strictEqual,
|
|
1116
|
+
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
1117
|
+
areNumbersEqual: sameValueEqual,
|
|
1118
|
+
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
1119
|
+
arePrimitiveWrappersEqual,
|
|
1120
|
+
areRegExpsEqual,
|
|
1121
|
+
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
1122
|
+
areTypedArraysEqual: strict ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict) : areTypedArraysEqual,
|
|
1123
|
+
areUrlsEqual,
|
|
1124
|
+
getUnsupportedCustomComparator: void 0
|
|
1125
|
+
};
|
|
1126
|
+
if (createCustomConfig) {
|
|
1127
|
+
config = Object.assign({}, config, createCustomConfig(config));
|
|
1128
|
+
}
|
|
1129
|
+
if (circular) {
|
|
1130
|
+
const areArraysEqual2 = createIsCircular(config.areArraysEqual);
|
|
1131
|
+
const areErrorsEqual2 = createIsCircular(config.areErrorsEqual);
|
|
1132
|
+
const areMapsEqual2 = createIsCircular(config.areMapsEqual);
|
|
1133
|
+
const areObjectsEqual2 = createIsCircular(config.areObjectsEqual);
|
|
1134
|
+
const areSetsEqual2 = createIsCircular(config.areSetsEqual);
|
|
1135
|
+
config = Object.assign({}, config, {
|
|
1136
|
+
areArraysEqual: areArraysEqual2,
|
|
1137
|
+
areErrorsEqual: areErrorsEqual2,
|
|
1138
|
+
areMapsEqual: areMapsEqual2,
|
|
1139
|
+
areObjectsEqual: areObjectsEqual2,
|
|
1140
|
+
areSetsEqual: areSetsEqual2
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
return config;
|
|
1144
|
+
}
|
|
1145
|
+
function createInternalEqualityComparator(compare) {
|
|
1146
|
+
return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
|
|
1147
|
+
return compare(a, b, state);
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
function createIsEqual({ circular, comparator, createState, equals, strict }) {
|
|
1151
|
+
if (createState) {
|
|
1152
|
+
return function isEqual(a, b) {
|
|
1153
|
+
const { cache = circular ? /* @__PURE__ */ new WeakMap() : void 0, meta } = createState();
|
|
1154
|
+
return comparator(a, b, {
|
|
1155
|
+
cache,
|
|
1156
|
+
equals,
|
|
1157
|
+
meta,
|
|
1158
|
+
strict
|
|
1159
|
+
});
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
if (circular) {
|
|
1163
|
+
return function isEqual(a, b) {
|
|
1164
|
+
return comparator(a, b, {
|
|
1165
|
+
cache: /* @__PURE__ */ new WeakMap(),
|
|
1166
|
+
equals,
|
|
1167
|
+
meta: void 0,
|
|
1168
|
+
strict
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
const state = {
|
|
1173
|
+
cache: void 0,
|
|
1174
|
+
equals,
|
|
1175
|
+
meta: void 0,
|
|
1176
|
+
strict
|
|
1177
|
+
};
|
|
1178
|
+
return function isEqual(a, b) {
|
|
1179
|
+
return comparator(a, b, state);
|
|
112
1180
|
};
|
|
113
|
-
return fastDeepEqual;
|
|
114
1181
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1182
|
+
function createSupportedComparatorMap({ areArrayBuffersEqual: areArrayBuffersEqual2, areArraysEqual: areArraysEqual2, areDataViewsEqual: areDataViewsEqual2, areDatesEqual: areDatesEqual2, areErrorsEqual: areErrorsEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areObjectsEqual: areObjectsEqual2, arePrimitiveWrappersEqual: arePrimitiveWrappersEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, areTypedArraysEqual: areTypedArraysEqual2, areUrlsEqual: areUrlsEqual2 }) {
|
|
1183
|
+
return {
|
|
1184
|
+
"[object Arguments]": areObjectsEqual2,
|
|
1185
|
+
"[object Array]": areArraysEqual2,
|
|
1186
|
+
"[object ArrayBuffer]": areArrayBuffersEqual2,
|
|
1187
|
+
"[object AsyncGeneratorFunction]": areFunctionsEqual,
|
|
1188
|
+
"[object BigInt]": arePrimitiveWrappersEqual2,
|
|
1189
|
+
"[object BigInt64Array]": areTypedArraysEqual2,
|
|
1190
|
+
"[object BigUint64Array]": areTypedArraysEqual2,
|
|
1191
|
+
"[object Boolean]": arePrimitiveWrappersEqual2,
|
|
1192
|
+
"[object DataView]": areDataViewsEqual2,
|
|
1193
|
+
"[object Date]": areDatesEqual2,
|
|
1194
|
+
// If an error tag, it should be tested explicitly. Like RegExp, the properties are not
|
|
1195
|
+
// enumerable, and therefore will give false positives if tested like a standard object.
|
|
1196
|
+
"[object Error]": areErrorsEqual2,
|
|
1197
|
+
"[object Float16Array]": areTypedArraysEqual2,
|
|
1198
|
+
"[object Float32Array]": areTypedArraysEqual2,
|
|
1199
|
+
"[object Float64Array]": areTypedArraysEqual2,
|
|
1200
|
+
"[object Function]": areFunctionsEqual,
|
|
1201
|
+
"[object GeneratorFunction]": areFunctionsEqual,
|
|
1202
|
+
"[object Int8Array]": areTypedArraysEqual2,
|
|
1203
|
+
"[object Int16Array]": areTypedArraysEqual2,
|
|
1204
|
+
"[object Int32Array]": areTypedArraysEqual2,
|
|
1205
|
+
"[object Map]": areMapsEqual2,
|
|
1206
|
+
"[object Number]": arePrimitiveWrappersEqual2,
|
|
1207
|
+
"[object Object]": (a, b, state) => (
|
|
1208
|
+
// The exception for value comparison is custom `Promise`-like class instances. These should
|
|
1209
|
+
// be treated the same as standard `Promise` objects, which means strict equality, and if
|
|
1210
|
+
// it reaches this point then that strict equality comparison has already failed.
|
|
1211
|
+
typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state)
|
|
1212
|
+
),
|
|
1213
|
+
// For RegExp, the properties are not enumerable, and therefore will give false positives if
|
|
1214
|
+
// tested like a standard object.
|
|
1215
|
+
"[object RegExp]": areRegExpsEqual2,
|
|
1216
|
+
"[object Set]": areSetsEqual2,
|
|
1217
|
+
"[object String]": arePrimitiveWrappersEqual2,
|
|
1218
|
+
"[object URL]": areUrlsEqual2,
|
|
1219
|
+
"[object Uint8Array]": areTypedArraysEqual2,
|
|
1220
|
+
"[object Uint8ClampedArray]": areTypedArraysEqual2,
|
|
1221
|
+
"[object Uint16Array]": areTypedArraysEqual2,
|
|
1222
|
+
"[object Uint32Array]": areTypedArraysEqual2
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
const deepEqual = createCustomEqual();
|
|
1226
|
+
createCustomEqual({ strict: true });
|
|
1227
|
+
createCustomEqual({ circular: true });
|
|
1228
|
+
createCustomEqual({
|
|
1229
|
+
circular: true,
|
|
1230
|
+
strict: true
|
|
1231
|
+
});
|
|
1232
|
+
createCustomEqual({
|
|
1233
|
+
createInternalComparator: () => sameValueEqual
|
|
1234
|
+
});
|
|
1235
|
+
createCustomEqual({
|
|
1236
|
+
strict: true,
|
|
1237
|
+
createInternalComparator: () => sameValueEqual
|
|
1238
|
+
});
|
|
1239
|
+
createCustomEqual({
|
|
1240
|
+
circular: true,
|
|
1241
|
+
createInternalComparator: () => sameValueEqual
|
|
1242
|
+
});
|
|
1243
|
+
createCustomEqual({
|
|
1244
|
+
circular: true,
|
|
1245
|
+
createInternalComparator: () => sameValueEqual,
|
|
1246
|
+
strict: true
|
|
1247
|
+
});
|
|
1248
|
+
function createCustomEqual(options = {}) {
|
|
1249
|
+
const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false } = options;
|
|
1250
|
+
const config = createEqualityComparatorConfig(options);
|
|
1251
|
+
const comparator = createEqualityComparator(config);
|
|
1252
|
+
const equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
|
|
1253
|
+
return createIsEqual({ circular, comparator, createState, equals, strict });
|
|
1254
|
+
}
|
|
1255
|
+
function useDeepCompareEffect(effect, dependencies) {
|
|
1256
|
+
useCustomCompareEffect(effect, dependencies, deepEqual);
|
|
1257
|
+
}
|
|
1258
|
+
const MAP_3D_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1259
|
+
"bounds",
|
|
1260
|
+
"defaultUIHidden",
|
|
1261
|
+
"gestureHandling",
|
|
1262
|
+
"internalUsageAttributionIds",
|
|
1263
|
+
"maxAltitude",
|
|
1264
|
+
"maxHeading",
|
|
1265
|
+
"maxTilt",
|
|
1266
|
+
"minAltitude",
|
|
1267
|
+
"minHeading",
|
|
1268
|
+
"minTilt",
|
|
1269
|
+
"mode"
|
|
1270
|
+
]);
|
|
1271
|
+
function useMap3DOptions(map3d, props) {
|
|
1272
|
+
const options = useMemo(() => {
|
|
1273
|
+
const result = {};
|
|
1274
|
+
const keys2 = Object.keys(props);
|
|
1275
|
+
for (const key of keys2) {
|
|
1276
|
+
if (!MAP_3D_OPTION_KEYS.has(key))
|
|
1277
|
+
continue;
|
|
1278
|
+
const value = props[key];
|
|
1279
|
+
if (value === void 0)
|
|
1280
|
+
continue;
|
|
1281
|
+
result[key] = value;
|
|
122
1282
|
}
|
|
123
|
-
return
|
|
124
|
-
},
|
|
1283
|
+
return result;
|
|
1284
|
+
}, [props]);
|
|
1285
|
+
useDeepCompareEffect(() => {
|
|
1286
|
+
if (!map3d)
|
|
1287
|
+
return;
|
|
1288
|
+
Object.assign(map3d, options);
|
|
1289
|
+
}, [map3d, options]);
|
|
125
1290
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
1291
|
+
const GoogleMaps3DContext = React__default.createContext(null);
|
|
1292
|
+
const DEFAULT_CONTAINER_STYLE = {
|
|
1293
|
+
width: "100%",
|
|
1294
|
+
height: "100%",
|
|
1295
|
+
position: "relative"
|
|
1296
|
+
};
|
|
1297
|
+
const Map3D = forwardRef((props, ref) => {
|
|
1298
|
+
const { children, id, className, style: style2 } = props;
|
|
1299
|
+
const context = useContext(APIProviderContext);
|
|
1300
|
+
if (!context) {
|
|
1301
|
+
throw new Error("<Map3D> can only be used inside an <APIProvider> component.");
|
|
1302
|
+
}
|
|
1303
|
+
const { addMap3DInstance, removeMap3DInstance } = context;
|
|
1304
|
+
const [map3d, containerRef, map3dRef, cameraStateRef, isReady] = useMap3DInstance(props);
|
|
1305
|
+
useMap3DCameraParams(map3d, cameraStateRef, props);
|
|
1306
|
+
useMap3DEvents(map3d, props);
|
|
1307
|
+
useMap3DOptions(map3d, props);
|
|
1308
|
+
useEffect(() => {
|
|
1309
|
+
if (!map3d)
|
|
1310
|
+
return;
|
|
1311
|
+
const instanceId = id !== null && id !== void 0 ? id : "default";
|
|
1312
|
+
addMap3DInstance(map3d, instanceId);
|
|
1313
|
+
return () => {
|
|
1314
|
+
removeMap3DInstance(instanceId);
|
|
1315
|
+
};
|
|
1316
|
+
}, [map3d, id]);
|
|
1317
|
+
useImperativeHandle(ref, () => ({
|
|
1318
|
+
map3d,
|
|
1319
|
+
flyCameraAround: (options) => {
|
|
1320
|
+
map3d === null || map3d === void 0 ? void 0 : map3d.flyCameraAround(options);
|
|
1321
|
+
},
|
|
1322
|
+
flyCameraTo: (options) => {
|
|
1323
|
+
map3d === null || map3d === void 0 ? void 0 : map3d.flyCameraTo(options);
|
|
1324
|
+
},
|
|
1325
|
+
stopCameraAnimation: () => {
|
|
1326
|
+
map3d === null || map3d === void 0 ? void 0 : map3d.stopCameraAnimation();
|
|
1327
|
+
}
|
|
1328
|
+
}), [map3d]);
|
|
1329
|
+
const combinedStyle = useMemo(() => Object.assign(Object.assign({}, DEFAULT_CONTAINER_STYLE), style2), [style2]);
|
|
1330
|
+
const contextValue = useMemo(() => ({ map3d }), [map3d]);
|
|
1331
|
+
if (!isReady) {
|
|
1332
|
+
return React__default.createElement("div", Object.assign({ ref: containerRef, "data-testid": "map-3d", style: className ? void 0 : combinedStyle, className }, id ? { id } : {}));
|
|
1333
|
+
}
|
|
1334
|
+
return React__default.createElement(
|
|
1335
|
+
"div",
|
|
1336
|
+
Object.assign({ ref: containerRef, "data-testid": "map-3d", style: className ? void 0 : combinedStyle, className }, id ? { id } : {}),
|
|
1337
|
+
React__default.createElement("gmp-map-3d", { ref: map3dRef, style: { width: "100%", height: "100%" } }, map3d && React__default.createElement(GoogleMaps3DContext.Provider, { value: contextValue }, children))
|
|
1338
|
+
);
|
|
1339
|
+
});
|
|
1340
|
+
Map3D.displayName = "Map3D";
|
|
1341
|
+
const Marker3DContext = createContext(null);
|
|
1342
|
+
const Marker3D = forwardRef(function Marker3D2(props, ref) {
|
|
1343
|
+
const { children, onClick, position, altitudeMode, collisionBehavior, drawsWhenOccluded, extruded, label, sizePreserved, zIndex, title: title2 } = props;
|
|
1344
|
+
const isInteractive = Boolean(onClick);
|
|
1345
|
+
const [marker, setMarker] = useState(null);
|
|
1346
|
+
const [contentHandledExternally, setContentHandledExternally] = useState(false);
|
|
1347
|
+
const contentContainer = useMemo(() => {
|
|
1348
|
+
const container = document.createElement("div");
|
|
1349
|
+
container.style.display = "none";
|
|
1350
|
+
document.body.appendChild(container);
|
|
1351
|
+
return container;
|
|
1352
|
+
}, []);
|
|
1353
|
+
useEffect(() => {
|
|
1354
|
+
return () => contentContainer.remove();
|
|
1355
|
+
}, [contentContainer]);
|
|
1356
|
+
const markerRef = useCallback((node) => {
|
|
1357
|
+
setMarker(node);
|
|
1358
|
+
if (typeof ref === "function") {
|
|
1359
|
+
ref(node);
|
|
1360
|
+
} else if (ref) {
|
|
1361
|
+
ref.current = node;
|
|
1362
|
+
}
|
|
1363
|
+
}, [ref]);
|
|
1364
|
+
useDomEventListener(marker, "gmp-click", onClick);
|
|
1365
|
+
useLayoutEffect(() => {
|
|
1366
|
+
if (contentHandledExternally)
|
|
1367
|
+
return;
|
|
1368
|
+
if (!marker || !contentContainer)
|
|
1369
|
+
return;
|
|
1370
|
+
while (marker.firstChild) {
|
|
1371
|
+
marker.removeChild(marker.firstChild);
|
|
1372
|
+
}
|
|
1373
|
+
const childNodes = Array.from(contentContainer.childNodes);
|
|
1374
|
+
for (const node of childNodes) {
|
|
1375
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
1376
|
+
continue;
|
|
1377
|
+
const element = node;
|
|
1378
|
+
const tagName = element.tagName.toLowerCase();
|
|
1379
|
+
if (tagName === "img" || tagName === "svg") {
|
|
1380
|
+
const template = document.createElement("template");
|
|
1381
|
+
template.content.appendChild(element.cloneNode(true));
|
|
1382
|
+
marker.appendChild(template);
|
|
1383
|
+
} else {
|
|
1384
|
+
marker.appendChild(element.cloneNode(true));
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}, [marker, contentContainer, children, contentHandledExternally]);
|
|
1388
|
+
const contextValue = useMemo(() => ({ marker, setContentHandledExternally }), [marker]);
|
|
1389
|
+
usePropBinding(marker, "position", position);
|
|
1390
|
+
usePropBinding(marker, "altitudeMode", altitudeMode);
|
|
1391
|
+
usePropBinding(marker, "collisionBehavior", collisionBehavior);
|
|
1392
|
+
usePropBinding(marker, "drawsWhenOccluded", drawsWhenOccluded);
|
|
1393
|
+
usePropBinding(marker, "extruded", extruded);
|
|
1394
|
+
usePropBinding(marker, "label", label);
|
|
1395
|
+
usePropBinding(marker, "sizePreserved", sizePreserved);
|
|
1396
|
+
usePropBinding(marker, "zIndex", zIndex);
|
|
1397
|
+
usePropBinding(marker, "title", title2 !== null && title2 !== void 0 ? title2 : "");
|
|
1398
|
+
return React__default.createElement(
|
|
1399
|
+
Marker3DContext.Provider,
|
|
1400
|
+
{ value: contextValue },
|
|
1401
|
+
isInteractive ? React__default.createElement("gmp-marker-3d-interactive", { ref: markerRef }) : React__default.createElement("gmp-marker-3d", { ref: markerRef }),
|
|
1402
|
+
createPortal(children, contentContainer)
|
|
1403
|
+
);
|
|
1404
|
+
});
|
|
1405
|
+
Marker3D.displayName = "Marker3D";
|
|
1406
|
+
function setValueForStyles(element, styles2, prevStyles) {
|
|
1407
|
+
if (styles2 != null && typeof styles2 !== "object") {
|
|
1408
|
+
throw new Error("The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.");
|
|
1409
|
+
}
|
|
1410
|
+
const elementStyle = element.style;
|
|
1411
|
+
if (prevStyles == null) {
|
|
1412
|
+
if (styles2 == null)
|
|
1413
|
+
return;
|
|
1414
|
+
for (const styleName in styles2) {
|
|
1415
|
+
if (!styles2.hasOwnProperty(styleName))
|
|
1416
|
+
continue;
|
|
1417
|
+
setValueForStyle(elementStyle, styleName, styles2[styleName]);
|
|
1418
|
+
}
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
for (const styleName in prevStyles) {
|
|
1422
|
+
if (prevStyles.hasOwnProperty(styleName) && (styles2 == null || !styles2.hasOwnProperty(styleName))) {
|
|
1423
|
+
const isCustomProperty = styleName.indexOf("--") === 0;
|
|
1424
|
+
if (isCustomProperty) {
|
|
1425
|
+
elementStyle.setProperty(styleName, "");
|
|
1426
|
+
} else if (styleName === "float") {
|
|
1427
|
+
elementStyle.cssFloat = "";
|
|
1428
|
+
} else {
|
|
1429
|
+
elementStyle[styleName] = "";
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (styles2 == null)
|
|
1434
|
+
return;
|
|
1435
|
+
for (const styleName in styles2) {
|
|
1436
|
+
const value = styles2[styleName];
|
|
1437
|
+
if (styles2.hasOwnProperty(styleName) && prevStyles[styleName] !== value) {
|
|
1438
|
+
setValueForStyle(elementStyle, styleName, value);
|
|
1439
|
+
}
|
|
132
1440
|
}
|
|
133
|
-
return t;
|
|
134
1441
|
}
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if ("
|
|
141
|
-
|
|
1442
|
+
function setValueForStyle(elementStyle, styleName, value) {
|
|
1443
|
+
const isCustomProperty = styleName.indexOf("--") === 0;
|
|
1444
|
+
if (value == null || typeof value === "boolean" || value === "") {
|
|
1445
|
+
if (isCustomProperty) {
|
|
1446
|
+
elementStyle.setProperty(styleName, "");
|
|
1447
|
+
} else if (styleName === "float") {
|
|
1448
|
+
elementStyle.cssFloat = "";
|
|
1449
|
+
} else {
|
|
1450
|
+
elementStyle[styleName] = "";
|
|
1451
|
+
}
|
|
1452
|
+
} else if (isCustomProperty) {
|
|
1453
|
+
elementStyle.setProperty(styleName, value);
|
|
1454
|
+
} else if (typeof value === "number" && value !== 0 && !isUnitlessNumber(styleName)) {
|
|
1455
|
+
elementStyle[styleName] = value + "px";
|
|
1456
|
+
} else {
|
|
1457
|
+
if (styleName === "float") {
|
|
1458
|
+
elementStyle.cssFloat = value;
|
|
1459
|
+
} else {
|
|
1460
|
+
elementStyle[styleName] = ("" + value).trim();
|
|
1461
|
+
}
|
|
142
1462
|
}
|
|
143
|
-
return String(t);
|
|
144
1463
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
1464
|
+
const unitlessNumbers = /* @__PURE__ */ new Set([
|
|
1465
|
+
"animationIterationCount",
|
|
1466
|
+
"aspectRatio",
|
|
1467
|
+
"borderImageOutset",
|
|
1468
|
+
"borderImageSlice",
|
|
1469
|
+
"borderImageWidth",
|
|
1470
|
+
"boxFlex",
|
|
1471
|
+
"boxFlexGroup",
|
|
1472
|
+
"boxOrdinalGroup",
|
|
1473
|
+
"columnCount",
|
|
1474
|
+
"columns",
|
|
1475
|
+
"flex",
|
|
1476
|
+
"flexGrow",
|
|
1477
|
+
"flexPositive",
|
|
1478
|
+
"flexShrink",
|
|
1479
|
+
"flexNegative",
|
|
1480
|
+
"flexOrder",
|
|
1481
|
+
"gridArea",
|
|
1482
|
+
"gridRow",
|
|
1483
|
+
"gridRowEnd",
|
|
1484
|
+
"gridRowSpan",
|
|
1485
|
+
"gridRowStart",
|
|
1486
|
+
"gridColumn",
|
|
1487
|
+
"gridColumnEnd",
|
|
1488
|
+
"gridColumnSpan",
|
|
1489
|
+
"gridColumnStart",
|
|
1490
|
+
"fontWeight",
|
|
1491
|
+
"lineClamp",
|
|
1492
|
+
"lineHeight",
|
|
1493
|
+
"opacity",
|
|
1494
|
+
"order",
|
|
1495
|
+
"orphans",
|
|
1496
|
+
"scale",
|
|
1497
|
+
"tabSize",
|
|
1498
|
+
"widows",
|
|
1499
|
+
"zIndex",
|
|
1500
|
+
"zoom",
|
|
1501
|
+
"fillOpacity",
|
|
1502
|
+
// SVG-related properties
|
|
1503
|
+
"floodOpacity",
|
|
1504
|
+
"stopOpacity",
|
|
1505
|
+
"strokeDasharray",
|
|
1506
|
+
"strokeDashoffset",
|
|
1507
|
+
"strokeMiterlimit",
|
|
1508
|
+
"strokeOpacity",
|
|
1509
|
+
"strokeWidth"
|
|
1510
|
+
]);
|
|
1511
|
+
function isUnitlessNumber(name) {
|
|
1512
|
+
return unitlessNumbers.has(name);
|
|
148
1513
|
}
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* The returned promise resolves when loading completes
|
|
165
|
-
* and rejects in case of an error or when the loading was aborted.
|
|
166
|
-
*/
|
|
167
|
-
static async load(params, onLoadingStatusChange) {
|
|
168
|
-
var _window$google;
|
|
169
|
-
const libraries = params.libraries ? params.libraries.split(",") : [];
|
|
170
|
-
const serializedParams = this.serializeParams(params);
|
|
171
|
-
this.listeners.push(onLoadingStatusChange);
|
|
172
|
-
if ((_window$google = window.google) != null && (_window$google = _window$google.maps) != null && _window$google.importLibrary) {
|
|
173
|
-
if (!this.serializedApiParams) {
|
|
174
|
-
this.loadingStatus = APILoadingStatus.LOADED;
|
|
175
|
-
}
|
|
176
|
-
this.notifyLoadingStatusListeners();
|
|
177
|
-
} else {
|
|
178
|
-
this.serializedApiParams = serializedParams;
|
|
179
|
-
this.initImportLibrary(params);
|
|
180
|
-
}
|
|
181
|
-
if (this.serializedApiParams && this.serializedApiParams !== serializedParams) {
|
|
182
|
-
console.warn(`[google-maps-api-loader] The maps API has already been loaded with different parameters and will not be loaded again. Refresh the page for new values to have effect.`);
|
|
183
|
-
}
|
|
184
|
-
const librariesToLoad = ["maps", ...libraries];
|
|
185
|
-
await Promise.all(librariesToLoad.map((name) => google.maps.importLibrary(name)));
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Serialize the parameters used to load the library for easier comparison.
|
|
189
|
-
*/
|
|
190
|
-
static serializeParams(params) {
|
|
191
|
-
return [params.v, params.key, params.language, params.region, params.authReferrerPolicy, params.solutionChannel].join("/");
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Creates the global `google.maps.importLibrary` function for bootstrapping.
|
|
195
|
-
* This is essentially a formatted version of the dynamic loading script
|
|
196
|
-
* from the official documentation with some minor adjustments.
|
|
197
|
-
*
|
|
198
|
-
* The created importLibrary function will load the Google Maps JavaScript API,
|
|
199
|
-
* which will then replace the `google.maps.importLibrary` function with the full
|
|
200
|
-
* implementation.
|
|
201
|
-
*
|
|
202
|
-
* @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import
|
|
203
|
-
*/
|
|
204
|
-
static initImportLibrary(params) {
|
|
205
|
-
if (!window.google) window.google = {};
|
|
206
|
-
if (!window.google.maps) window.google.maps = {};
|
|
207
|
-
if (window.google.maps["importLibrary"]) {
|
|
208
|
-
console.error("[google-maps-api-loader-internal]: initImportLibrary must only be called once");
|
|
1514
|
+
const Popover = forwardRef(function Popover2(props, ref) {
|
|
1515
|
+
var _a;
|
|
1516
|
+
const { children, headerContent, style: style2, className, open = true, position, anchor, anchorId, altitudeMode, lightDismissDisabled, autoPanDisabled, onClose } = props;
|
|
1517
|
+
const [popover, setPopover] = useState(null);
|
|
1518
|
+
const prevStyleRef = useRef(null);
|
|
1519
|
+
useImperativeHandle(ref, () => popover, [popover]);
|
|
1520
|
+
usePopoverCloseObserver(popover, open, onClose);
|
|
1521
|
+
usePropBinding(popover, "open", open !== null && open !== void 0 ? open : false);
|
|
1522
|
+
usePropBinding(popover, "altitudeMode", altitudeMode);
|
|
1523
|
+
usePropBinding(popover, "lightDismissDisabled", lightDismissDisabled);
|
|
1524
|
+
usePropBinding(popover, "autoPanDisabled", autoPanDisabled);
|
|
1525
|
+
const positionAnchor = (_a = anchor !== null && anchor !== void 0 ? anchor : anchorId) !== null && _a !== void 0 ? _a : position;
|
|
1526
|
+
usePropBinding(popover, "positionAnchor", positionAnchor);
|
|
1527
|
+
useLayoutEffect(() => {
|
|
1528
|
+
if (!popover)
|
|
209
1529
|
return;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
1530
|
+
setValueForStyles(popover, style2 || null, prevStyleRef.current);
|
|
1531
|
+
prevStyleRef.current = style2 || null;
|
|
1532
|
+
}, [popover, style2]);
|
|
1533
|
+
return React__default.createElement(
|
|
1534
|
+
"gmp-popover",
|
|
1535
|
+
{ ref: setPopover, className },
|
|
1536
|
+
headerContent && React__default.createElement("div", { slot: "header" }, headerContent),
|
|
1537
|
+
children
|
|
1538
|
+
);
|
|
1539
|
+
});
|
|
1540
|
+
Popover.displayName = "Popover";
|
|
1541
|
+
function usePopoverCloseObserver(popover, open, onClose) {
|
|
1542
|
+
const previousOpenState = useRef(void 0);
|
|
1543
|
+
const openPropRef = useRef(open);
|
|
1544
|
+
useEffect(() => {
|
|
1545
|
+
openPropRef.current = open;
|
|
1546
|
+
}, [open]);
|
|
1547
|
+
useEffect(() => {
|
|
1548
|
+
if (!popover || !onClose)
|
|
1549
|
+
return;
|
|
1550
|
+
const observer = new MutationObserver((mutations) => {
|
|
1551
|
+
for (const mutation of mutations) {
|
|
1552
|
+
if (mutation.type === "attributes" && mutation.attributeName === "open") {
|
|
1553
|
+
const isOpen = popover.hasAttribute("open");
|
|
1554
|
+
if (previousOpenState.current === true && !isOpen && openPropRef.current !== false) {
|
|
1555
|
+
onClose();
|
|
1556
|
+
}
|
|
1557
|
+
previousOpenState.current = isOpen;
|
|
221
1558
|
}
|
|
222
|
-
|
|
223
|
-
urlParams.set("callback", "__googleMapsCallback__");
|
|
224
|
-
scriptElement.async = true;
|
|
225
|
-
scriptElement.src = MAPS_API_BASE_URL + `?` + urlParams.toString();
|
|
226
|
-
scriptElement.nonce = ((_document$querySelect = document.querySelector("script[nonce]")) == null ? void 0 : _document$querySelect.nonce) || "";
|
|
227
|
-
scriptElement.onerror = () => {
|
|
228
|
-
this.loadingStatus = APILoadingStatus.FAILED;
|
|
229
|
-
this.notifyLoadingStatusListeners();
|
|
230
|
-
reject(new Error("The Google Maps JavaScript API could not load."));
|
|
231
|
-
};
|
|
232
|
-
window.__googleMapsCallback__ = () => {
|
|
233
|
-
this.loadingStatus = APILoadingStatus.LOADED;
|
|
234
|
-
this.notifyLoadingStatusListeners();
|
|
235
|
-
resolve();
|
|
236
|
-
};
|
|
237
|
-
window.gm_authFailure = () => {
|
|
238
|
-
this.loadingStatus = APILoadingStatus.AUTH_FAILURE;
|
|
239
|
-
this.notifyLoadingStatusListeners();
|
|
240
|
-
};
|
|
241
|
-
this.loadingStatus = APILoadingStatus.LOADING;
|
|
242
|
-
this.notifyLoadingStatusListeners();
|
|
243
|
-
document.head.append(scriptElement);
|
|
244
|
-
});
|
|
245
|
-
return apiPromise;
|
|
246
|
-
};
|
|
247
|
-
google.maps.importLibrary = (libraryName) => loadApi().then(() => google.maps.importLibrary(libraryName));
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Calls all registered loadingStatusListeners after a status update.
|
|
251
|
-
*/
|
|
252
|
-
static notifyLoadingStatusListeners() {
|
|
253
|
-
for (const fn of this.listeners) {
|
|
254
|
-
fn(this.loadingStatus);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
GoogleMapsApiLoader.loadingStatus = APILoadingStatus.NOT_LOADED;
|
|
259
|
-
GoogleMapsApiLoader.serializedApiParams = void 0;
|
|
260
|
-
GoogleMapsApiLoader.listeners = [];
|
|
261
|
-
const _excluded$3 = ["onLoad", "onError", "apiKey", "version", "libraries"], _excluded2$1 = ["children"];
|
|
262
|
-
const DEFAULT_SOLUTION_CHANNEL = "GMP_visgl_rgmlibrary_v1_default";
|
|
263
|
-
const APIProviderContext = React__default.createContext(null);
|
|
264
|
-
function useMapInstances() {
|
|
265
|
-
const [mapInstances, setMapInstances] = useState({});
|
|
266
|
-
const addMapInstance = (mapInstance, id = "default") => {
|
|
267
|
-
setMapInstances((instances) => _extends({}, instances, {
|
|
268
|
-
[id]: mapInstance
|
|
269
|
-
}));
|
|
270
|
-
};
|
|
271
|
-
const removeMapInstance = (id = "default") => {
|
|
272
|
-
setMapInstances((_ref) => {
|
|
273
|
-
let remaining = _objectWithoutPropertiesLoose(_ref, [id].map(_toPropertyKey));
|
|
274
|
-
return remaining;
|
|
275
|
-
});
|
|
276
|
-
};
|
|
277
|
-
const clearMapInstances = () => {
|
|
278
|
-
setMapInstances({});
|
|
279
|
-
};
|
|
280
|
-
return {
|
|
281
|
-
mapInstances,
|
|
282
|
-
addMapInstance,
|
|
283
|
-
removeMapInstance,
|
|
284
|
-
clearMapInstances
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function useGoogleMapsApiLoader(props) {
|
|
288
|
-
const {
|
|
289
|
-
onLoad,
|
|
290
|
-
onError,
|
|
291
|
-
apiKey,
|
|
292
|
-
version,
|
|
293
|
-
libraries = []
|
|
294
|
-
} = props, otherApiParams = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
295
|
-
const [status, setStatus] = useState(GoogleMapsApiLoader.loadingStatus);
|
|
296
|
-
const [loadedLibraries, addLoadedLibrary] = useReducer((loadedLibraries2, action) => {
|
|
297
|
-
return loadedLibraries2[action.name] ? loadedLibraries2 : _extends({}, loadedLibraries2, {
|
|
298
|
-
[action.name]: action.value
|
|
1559
|
+
}
|
|
299
1560
|
});
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
apiKey,
|
|
304
|
-
version
|
|
305
|
-
}, otherApiParams)), [apiKey, version, otherApiParams]);
|
|
306
|
-
const importLibrary = useCallback(async (name) => {
|
|
307
|
-
var _google;
|
|
308
|
-
if (loadedLibraries[name]) {
|
|
309
|
-
return loadedLibraries[name];
|
|
310
|
-
}
|
|
311
|
-
if (!((_google = google) != null && (_google = _google.maps) != null && _google.importLibrary)) {
|
|
312
|
-
throw new Error("[api-provider-internal] importLibrary was called before google.maps.importLibrary was defined.");
|
|
313
|
-
}
|
|
314
|
-
const res = await window.google.maps.importLibrary(name);
|
|
315
|
-
addLoadedLibrary({
|
|
316
|
-
name,
|
|
317
|
-
value: res
|
|
1561
|
+
observer.observe(popover, {
|
|
1562
|
+
attributes: true,
|
|
1563
|
+
attributeFilter: ["open"]
|
|
318
1564
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
else if (params.solutionChannel === "") delete params.solutionChannel;
|
|
333
|
-
await GoogleMapsApiLoader.load(params, (status2) => setStatus(status2));
|
|
334
|
-
for (const name of ["core", "maps", ...libraries]) {
|
|
335
|
-
await importLibrary(name);
|
|
336
|
-
}
|
|
337
|
-
if (onLoad) {
|
|
338
|
-
onLoad();
|
|
339
|
-
}
|
|
340
|
-
} catch (error) {
|
|
341
|
-
if (onError) {
|
|
342
|
-
onError(error);
|
|
343
|
-
} else {
|
|
344
|
-
console.error("<ApiProvider> failed to load the Google Maps JavaScript API", error);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
})();
|
|
348
|
-
},
|
|
349
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
350
|
-
[apiKey, librariesString, serializedParams]
|
|
351
|
-
);
|
|
352
|
-
return {
|
|
353
|
-
status,
|
|
354
|
-
loadedLibraries,
|
|
355
|
-
importLibrary
|
|
356
|
-
};
|
|
1565
|
+
previousOpenState.current = popover.hasAttribute("open");
|
|
1566
|
+
return () => {
|
|
1567
|
+
observer.disconnect();
|
|
1568
|
+
};
|
|
1569
|
+
}, [popover, onClose]);
|
|
1570
|
+
}
|
|
1571
|
+
const shownMessages = /* @__PURE__ */ new Set();
|
|
1572
|
+
function logErrorOnce(...args) {
|
|
1573
|
+
const key = JSON.stringify(args);
|
|
1574
|
+
if (!shownMessages.has(key)) {
|
|
1575
|
+
shownMessages.add(key);
|
|
1576
|
+
console.error(...args);
|
|
1577
|
+
}
|
|
357
1578
|
}
|
|
358
|
-
const APIProvider = (props) => {
|
|
359
|
-
const {
|
|
360
|
-
children
|
|
361
|
-
} = props, loaderProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
|
|
362
|
-
const {
|
|
363
|
-
mapInstances,
|
|
364
|
-
addMapInstance,
|
|
365
|
-
removeMapInstance,
|
|
366
|
-
clearMapInstances
|
|
367
|
-
} = useMapInstances();
|
|
368
|
-
const {
|
|
369
|
-
status,
|
|
370
|
-
loadedLibraries,
|
|
371
|
-
importLibrary
|
|
372
|
-
} = useGoogleMapsApiLoader(loaderProps);
|
|
373
|
-
const contextValue = useMemo(() => ({
|
|
374
|
-
mapInstances,
|
|
375
|
-
addMapInstance,
|
|
376
|
-
removeMapInstance,
|
|
377
|
-
clearMapInstances,
|
|
378
|
-
status,
|
|
379
|
-
loadedLibraries,
|
|
380
|
-
importLibrary
|
|
381
|
-
}), [mapInstances, addMapInstance, removeMapInstance, clearMapInstances, status, loadedLibraries, importLibrary]);
|
|
382
|
-
return /* @__PURE__ */ React__default.createElement(APIProviderContext.Provider, {
|
|
383
|
-
value: contextValue
|
|
384
|
-
}, children);
|
|
385
|
-
};
|
|
386
1579
|
function useMapEvents(map, props) {
|
|
387
1580
|
for (const propName of eventPropNames) {
|
|
388
1581
|
const handler = props[propName];
|
|
389
1582
|
const eventType = propNameToEventType[propName];
|
|
390
1583
|
useEffect(() => {
|
|
391
|
-
if (!map)
|
|
392
|
-
|
|
1584
|
+
if (!map)
|
|
1585
|
+
return;
|
|
1586
|
+
if (!handler)
|
|
1587
|
+
return;
|
|
393
1588
|
const listener = google.maps.event.addListener(map, eventType, (ev) => {
|
|
394
|
-
|
|
1589
|
+
const mapEvent = createMapEvent(eventType, map, ev);
|
|
1590
|
+
if (mapEvent)
|
|
1591
|
+
handler(mapEvent);
|
|
395
1592
|
});
|
|
396
1593
|
return () => listener.remove();
|
|
397
1594
|
}, [map, eventType, handler]);
|
|
398
1595
|
}
|
|
399
1596
|
}
|
|
400
1597
|
function createMapEvent(type, map, srcEvent) {
|
|
1598
|
+
var _a;
|
|
401
1599
|
const ev = {
|
|
402
1600
|
type,
|
|
403
1601
|
map,
|
|
@@ -415,32 +1613,25 @@ function createMapEvent(type, map, srcEvent) {
|
|
|
415
1613
|
const bounds = map.getBounds();
|
|
416
1614
|
if (!center || !bounds || !Number.isFinite(zoom)) {
|
|
417
1615
|
console.warn("[createEvent] at least one of the values from the map returned undefined. This is not expected to happen. Please report an issue at https://github.com/visgl/react-google-maps/issues/new");
|
|
1616
|
+
return null;
|
|
418
1617
|
}
|
|
419
1618
|
camEvent.detail = {
|
|
420
|
-
center:
|
|
421
|
-
|
|
422
|
-
lng: 0
|
|
423
|
-
},
|
|
424
|
-
zoom: zoom || 0,
|
|
1619
|
+
center: center.toJSON(),
|
|
1620
|
+
zoom,
|
|
425
1621
|
heading,
|
|
426
1622
|
tilt,
|
|
427
|
-
bounds:
|
|
428
|
-
north: 90,
|
|
429
|
-
east: 180,
|
|
430
|
-
south: -90,
|
|
431
|
-
west: -180
|
|
432
|
-
}
|
|
1623
|
+
bounds: bounds.toJSON()
|
|
433
1624
|
};
|
|
434
1625
|
return camEvent;
|
|
435
1626
|
} else if (mouseEventTypes.includes(type)) {
|
|
436
|
-
|
|
437
|
-
|
|
1627
|
+
if (!srcEvent)
|
|
1628
|
+
throw new Error("[createEvent] mouse events must provide a srcEvent");
|
|
438
1629
|
const mouseEvent = ev;
|
|
439
1630
|
mouseEvent.domEvent = srcEvent.domEvent;
|
|
440
1631
|
mouseEvent.stoppable = true;
|
|
441
1632
|
mouseEvent.stop = () => srcEvent.stop();
|
|
442
1633
|
mouseEvent.detail = {
|
|
443
|
-
latLng: ((
|
|
1634
|
+
latLng: ((_a = srcEvent.latLng) === null || _a === void 0 ? void 0 : _a.toJSON()) || null,
|
|
444
1635
|
placeId: srcEvent.placeId
|
|
445
1636
|
};
|
|
446
1637
|
return mouseEvent;
|
|
@@ -474,53 +1665,82 @@ const propNameToEventType = {
|
|
|
474
1665
|
// updated.
|
|
475
1666
|
onCameraChanged: "bounds_changed"
|
|
476
1667
|
};
|
|
477
|
-
const cameraEventTypes = [
|
|
478
|
-
|
|
1668
|
+
const cameraEventTypes = [
|
|
1669
|
+
"bounds_changed",
|
|
1670
|
+
"center_changed",
|
|
1671
|
+
"heading_changed",
|
|
1672
|
+
"tilt_changed",
|
|
1673
|
+
"zoom_changed"
|
|
1674
|
+
];
|
|
1675
|
+
const mouseEventTypes = [
|
|
1676
|
+
"click",
|
|
1677
|
+
"contextmenu",
|
|
1678
|
+
"dblclick",
|
|
1679
|
+
"mousemove",
|
|
1680
|
+
"mouseout",
|
|
1681
|
+
"mouseover"
|
|
1682
|
+
];
|
|
479
1683
|
const eventPropNames = Object.keys(propNameToEventType);
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
1684
|
+
const mapOptionKeys = /* @__PURE__ */ new Set([
|
|
1685
|
+
"backgroundColor",
|
|
1686
|
+
"clickableIcons",
|
|
1687
|
+
"controlSize",
|
|
1688
|
+
"disableDefaultUI",
|
|
1689
|
+
"disableDoubleClickZoom",
|
|
1690
|
+
"draggable",
|
|
1691
|
+
"draggableCursor",
|
|
1692
|
+
"draggingCursor",
|
|
1693
|
+
"fullscreenControl",
|
|
1694
|
+
"fullscreenControlOptions",
|
|
1695
|
+
"gestureHandling",
|
|
1696
|
+
"headingInteractionEnabled",
|
|
1697
|
+
"isFractionalZoomEnabled",
|
|
1698
|
+
"keyboardShortcuts",
|
|
1699
|
+
"mapTypeControl",
|
|
1700
|
+
"mapTypeControlOptions",
|
|
1701
|
+
"mapTypeId",
|
|
1702
|
+
"maxZoom",
|
|
1703
|
+
"minZoom",
|
|
1704
|
+
"noClear",
|
|
1705
|
+
"panControl",
|
|
1706
|
+
"panControlOptions",
|
|
1707
|
+
"restriction",
|
|
1708
|
+
"rotateControl",
|
|
1709
|
+
"rotateControlOptions",
|
|
1710
|
+
"scaleControl",
|
|
1711
|
+
"scaleControlOptions",
|
|
1712
|
+
"scrollwheel",
|
|
1713
|
+
"streetView",
|
|
1714
|
+
"streetViewControl",
|
|
1715
|
+
"streetViewControlOptions",
|
|
1716
|
+
"styles",
|
|
1717
|
+
"tiltInteractionEnabled",
|
|
1718
|
+
"zoomControl",
|
|
1719
|
+
"zoomControlOptions"
|
|
1720
|
+
]);
|
|
488
1721
|
function useMapOptions(map, mapProps) {
|
|
489
1722
|
const mapOptions = {};
|
|
490
|
-
const
|
|
491
|
-
for (const key of
|
|
492
|
-
if (!mapOptionKeys.has(key))
|
|
1723
|
+
const keys2 = Object.keys(mapProps);
|
|
1724
|
+
for (const key of keys2) {
|
|
1725
|
+
if (!mapOptionKeys.has(key))
|
|
1726
|
+
continue;
|
|
493
1727
|
mapOptions[key] = mapProps[key];
|
|
494
1728
|
}
|
|
495
1729
|
useDeepCompareEffect(() => {
|
|
496
|
-
if (!map)
|
|
1730
|
+
if (!map)
|
|
1731
|
+
return;
|
|
497
1732
|
map.setOptions(mapOptions);
|
|
498
1733
|
}, [mapOptions]);
|
|
499
1734
|
}
|
|
500
|
-
function useApiLoadingStatus() {
|
|
501
|
-
var _useContext;
|
|
502
|
-
return ((_useContext = useContext(APIProviderContext)) == null ? void 0 : _useContext.status) || APILoadingStatus.NOT_LOADED;
|
|
503
|
-
}
|
|
504
1735
|
function useDeckGLCameraUpdate(map, props) {
|
|
505
|
-
const {
|
|
506
|
-
viewport,
|
|
507
|
-
viewState
|
|
508
|
-
} = props;
|
|
1736
|
+
const { viewport, viewState } = props;
|
|
509
1737
|
const isDeckGlControlled = !!viewport;
|
|
510
1738
|
useLayoutEffect(() => {
|
|
511
|
-
if (!map || !viewState)
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
longitude,
|
|
515
|
-
bearing: heading,
|
|
516
|
-
pitch: tilt,
|
|
517
|
-
zoom
|
|
518
|
-
} = viewState;
|
|
1739
|
+
if (!map || !viewState)
|
|
1740
|
+
return;
|
|
1741
|
+
const { latitude, longitude, bearing: heading, pitch: tilt, zoom } = viewState;
|
|
519
1742
|
map.moveCamera({
|
|
520
|
-
center: {
|
|
521
|
-
lat: latitude,
|
|
522
|
-
lng: longitude
|
|
523
|
-
},
|
|
1743
|
+
center: { lat: latitude, lng: longitude },
|
|
524
1744
|
heading,
|
|
525
1745
|
tilt,
|
|
526
1746
|
zoom: zoom + 1
|
|
@@ -529,14 +1749,70 @@ function useDeckGLCameraUpdate(map, props) {
|
|
|
529
1749
|
return isDeckGlControlled;
|
|
530
1750
|
}
|
|
531
1751
|
function isLatLngLiteral(obj) {
|
|
532
|
-
if (!obj || typeof obj !== "object")
|
|
533
|
-
|
|
1752
|
+
if (!obj || typeof obj !== "object")
|
|
1753
|
+
return false;
|
|
1754
|
+
if (!("lat" in obj && "lng" in obj))
|
|
1755
|
+
return false;
|
|
534
1756
|
return Number.isFinite(obj.lat) && Number.isFinite(obj.lng);
|
|
535
1757
|
}
|
|
1758
|
+
function latLngEquals(a, b) {
|
|
1759
|
+
if (!a || !b)
|
|
1760
|
+
return false;
|
|
1761
|
+
const A = toLatLngLiteral(a);
|
|
1762
|
+
const B = toLatLngLiteral(b);
|
|
1763
|
+
if (A.lat !== B.lat || A.lng !== B.lng)
|
|
1764
|
+
return false;
|
|
1765
|
+
return true;
|
|
1766
|
+
}
|
|
536
1767
|
function toLatLngLiteral(obj) {
|
|
537
|
-
if (isLatLngLiteral(obj))
|
|
1768
|
+
if (isLatLngLiteral(obj))
|
|
1769
|
+
return obj;
|
|
538
1770
|
return obj.toJSON();
|
|
539
1771
|
}
|
|
1772
|
+
function toLatLngBoundsLiteral(obj) {
|
|
1773
|
+
if ("north" in obj && "south" in obj && "east" in obj && "west" in obj) {
|
|
1774
|
+
return obj;
|
|
1775
|
+
}
|
|
1776
|
+
const ne = obj.getNorthEast().toJSON();
|
|
1777
|
+
const sw = obj.getSouthWest().toJSON();
|
|
1778
|
+
return {
|
|
1779
|
+
north: ne.lat,
|
|
1780
|
+
east: ne.lng,
|
|
1781
|
+
south: sw.lat,
|
|
1782
|
+
west: sw.lng
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
function boundsEquals(a, b) {
|
|
1786
|
+
if (!a || !b)
|
|
1787
|
+
return false;
|
|
1788
|
+
const A = toLatLngBoundsLiteral(a);
|
|
1789
|
+
const B = toLatLngBoundsLiteral(b);
|
|
1790
|
+
return A.north === B.north && A.south === B.south && A.east === B.east && A.west === B.west;
|
|
1791
|
+
}
|
|
1792
|
+
function pathEquals(a, b) {
|
|
1793
|
+
if (!a || !b)
|
|
1794
|
+
return a === b;
|
|
1795
|
+
const arrayB = "getArray" in b ? b.getArray() : b;
|
|
1796
|
+
if (a.length !== arrayB.length)
|
|
1797
|
+
return false;
|
|
1798
|
+
for (let i = 0; i < a.length; i++) {
|
|
1799
|
+
if (!latLngEquals(a[i], arrayB[i]))
|
|
1800
|
+
return false;
|
|
1801
|
+
}
|
|
1802
|
+
return true;
|
|
1803
|
+
}
|
|
1804
|
+
function pathsEquals(a, b) {
|
|
1805
|
+
if (!a || !b)
|
|
1806
|
+
return a === b;
|
|
1807
|
+
const arrayB = "getArray" in b ? b.getArray().map((inner) => inner.getArray()) : b;
|
|
1808
|
+
if (a.length !== arrayB.length)
|
|
1809
|
+
return false;
|
|
1810
|
+
for (let i = 0; i < a.length; i++) {
|
|
1811
|
+
if (!pathEquals(a[i], arrayB[i]))
|
|
1812
|
+
return false;
|
|
1813
|
+
}
|
|
1814
|
+
return true;
|
|
1815
|
+
}
|
|
540
1816
|
function useMapCameraParams(map, cameraStateRef, mapProps) {
|
|
541
1817
|
const center = mapProps.center ? toLatLngLiteral(mapProps.center) : null;
|
|
542
1818
|
let lat = null;
|
|
@@ -549,14 +1825,12 @@ function useMapCameraParams(map, cameraStateRef, mapProps) {
|
|
|
549
1825
|
const heading = Number.isFinite(mapProps.heading) ? mapProps.heading : null;
|
|
550
1826
|
const tilt = Number.isFinite(mapProps.tilt) ? mapProps.tilt : null;
|
|
551
1827
|
useLayoutEffect(() => {
|
|
552
|
-
if (!map)
|
|
1828
|
+
if (!map)
|
|
1829
|
+
return;
|
|
553
1830
|
const nextCamera = {};
|
|
554
1831
|
let needsUpdate = false;
|
|
555
1832
|
if (lat !== null && lng !== null && (cameraStateRef.current.center.lat !== lat || cameraStateRef.current.center.lng !== lng)) {
|
|
556
|
-
nextCamera.center = {
|
|
557
|
-
lat,
|
|
558
|
-
lng
|
|
559
|
-
};
|
|
1833
|
+
nextCamera.center = { lat, lng };
|
|
560
1834
|
needsUpdate = true;
|
|
561
1835
|
}
|
|
562
1836
|
if (zoom !== null && cameraStateRef.current.zoom !== zoom) {
|
|
@@ -593,38 +1867,31 @@ const AuthFailureMessage = () => {
|
|
|
593
1867
|
background: "#dddddd",
|
|
594
1868
|
padding: "1rem 1.5rem"
|
|
595
1869
|
};
|
|
596
|
-
return
|
|
597
|
-
|
|
598
|
-
|
|
1870
|
+
return React__default.createElement(
|
|
1871
|
+
"div",
|
|
1872
|
+
{ style: style2 },
|
|
1873
|
+
React__default.createElement("h2", null, "Error: AuthFailure"),
|
|
1874
|
+
React__default.createElement(
|
|
1875
|
+
"p",
|
|
1876
|
+
null,
|
|
1877
|
+
"A problem with your API key prevents the map from rendering correctly. Please make sure the value of the ",
|
|
1878
|
+
React__default.createElement("code", null, "APIProvider.apiKey"),
|
|
1879
|
+
" prop is correct. Check the error-message in the console for further details."
|
|
1880
|
+
)
|
|
1881
|
+
);
|
|
599
1882
|
};
|
|
600
|
-
function useCallbackRef() {
|
|
601
|
-
const [el, setEl] = useState(null);
|
|
602
|
-
const ref = useCallback((value) => setEl(value), [setEl]);
|
|
603
|
-
return [el, ref];
|
|
604
|
-
}
|
|
605
|
-
function useApiIsLoaded() {
|
|
606
|
-
const status = useApiLoadingStatus();
|
|
607
|
-
return status === APILoadingStatus.LOADED;
|
|
608
|
-
}
|
|
609
|
-
function useForceUpdate() {
|
|
610
|
-
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
611
|
-
return forceUpdate;
|
|
612
|
-
}
|
|
613
1883
|
function handleBoundsChange(map, ref) {
|
|
614
1884
|
const center = map.getCenter();
|
|
615
1885
|
const zoom = map.getZoom();
|
|
616
1886
|
const heading = map.getHeading() || 0;
|
|
617
1887
|
const tilt = map.getTilt() || 0;
|
|
618
|
-
|
|
619
|
-
if (!center || !bounds || !Number.isFinite(zoom)) {
|
|
1888
|
+
if (!center || !Number.isFinite(zoom)) {
|
|
620
1889
|
console.warn("[useTrackedCameraState] at least one of the values from the map returned undefined. This is not expected to happen. Please report an issue at https://github.com/visgl/react-google-maps/issues/new");
|
|
1890
|
+
return;
|
|
621
1891
|
}
|
|
622
1892
|
Object.assign(ref.current, {
|
|
623
|
-
center:
|
|
624
|
-
|
|
625
|
-
lng: 0
|
|
626
|
-
},
|
|
627
|
-
zoom: zoom || 0,
|
|
1893
|
+
center: center.toJSON(),
|
|
1894
|
+
zoom,
|
|
628
1895
|
heading,
|
|
629
1896
|
tilt
|
|
630
1897
|
});
|
|
@@ -632,16 +1899,14 @@ function handleBoundsChange(map, ref) {
|
|
|
632
1899
|
function useTrackedCameraStateRef(map) {
|
|
633
1900
|
const forceUpdate = useForceUpdate();
|
|
634
1901
|
const ref = useRef({
|
|
635
|
-
center: {
|
|
636
|
-
lat: 0,
|
|
637
|
-
lng: 0
|
|
638
|
-
},
|
|
1902
|
+
center: { lat: 0, lng: 0 },
|
|
639
1903
|
heading: 0,
|
|
640
1904
|
tilt: 0,
|
|
641
1905
|
zoom: 0
|
|
642
1906
|
});
|
|
643
1907
|
useEffect(() => {
|
|
644
|
-
if (!map)
|
|
1908
|
+
if (!map)
|
|
1909
|
+
return;
|
|
645
1910
|
const listener = google.maps.event.addListener(map, "bounds_changed", () => {
|
|
646
1911
|
handleBoundsChange(map, ref);
|
|
647
1912
|
forceUpdate();
|
|
@@ -650,17 +1915,18 @@ function useTrackedCameraStateRef(map) {
|
|
|
650
1915
|
}, [map, forceUpdate]);
|
|
651
1916
|
return ref;
|
|
652
1917
|
}
|
|
653
|
-
const _excluded$2 = ["id", "defaultBounds", "defaultCenter", "defaultZoom", "defaultHeading", "defaultTilt", "reuseMaps", "renderingType", "colorScheme"], _excluded2 = ["padding"];
|
|
654
1918
|
class CachedMapStack {
|
|
655
1919
|
static has(key) {
|
|
656
1920
|
return this.entries[key] && this.entries[key].length > 0;
|
|
657
1921
|
}
|
|
658
1922
|
static pop(key) {
|
|
659
|
-
if (!this.entries[key])
|
|
1923
|
+
if (!this.entries[key])
|
|
1924
|
+
return null;
|
|
660
1925
|
return this.entries[key].pop() || null;
|
|
661
1926
|
}
|
|
662
1927
|
static push(key, value) {
|
|
663
|
-
if (!this.entries[key])
|
|
1928
|
+
if (!this.entries[key])
|
|
1929
|
+
this.entries[key] = [];
|
|
664
1930
|
this.entries[key].push(value);
|
|
665
1931
|
}
|
|
666
1932
|
}
|
|
@@ -670,79 +1936,75 @@ function useMapInstance(props, context) {
|
|
|
670
1936
|
const [map, setMap] = useState(null);
|
|
671
1937
|
const [container, containerRef] = useCallbackRef();
|
|
672
1938
|
const cameraStateRef = useTrackedCameraStateRef(map);
|
|
673
|
-
const {
|
|
674
|
-
id,
|
|
675
|
-
defaultBounds,
|
|
676
|
-
defaultCenter,
|
|
677
|
-
defaultZoom,
|
|
678
|
-
defaultHeading,
|
|
679
|
-
defaultTilt,
|
|
680
|
-
reuseMaps,
|
|
681
|
-
renderingType,
|
|
682
|
-
colorScheme
|
|
683
|
-
} = props, mapOptions = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
1939
|
+
const { id, defaultBounds, defaultCenter, defaultZoom, defaultHeading, defaultTilt, reuseMaps, renderingType, colorScheme } = props, mapOptions = __rest(props, ["id", "defaultBounds", "defaultCenter", "defaultZoom", "defaultHeading", "defaultTilt", "reuseMaps", "renderingType", "colorScheme"]);
|
|
684
1940
|
const hasZoom = props.zoom !== void 0 || props.defaultZoom !== void 0;
|
|
685
1941
|
const hasCenter = props.center !== void 0 || props.defaultCenter !== void 0;
|
|
686
1942
|
if (!defaultBounds && (!hasZoom || !hasCenter)) {
|
|
687
1943
|
console.warn("<Map> component is missing configuration. You have to provide zoom and center (via the `zoom`/`defaultZoom` and `center`/`defaultCenter` props) or specify the region to show using `defaultBounds`. See https://visgl.github.io/react-google-maps/docs/api-reference/components/map#required");
|
|
688
1944
|
}
|
|
689
|
-
if (!mapOptions.center && defaultCenter)
|
|
690
|
-
|
|
691
|
-
if (!mapOptions.
|
|
692
|
-
|
|
693
|
-
|
|
1945
|
+
if (!mapOptions.center && defaultCenter)
|
|
1946
|
+
mapOptions.center = defaultCenter;
|
|
1947
|
+
if (!mapOptions.zoom && Number.isFinite(defaultZoom))
|
|
1948
|
+
mapOptions.zoom = defaultZoom;
|
|
1949
|
+
if (!mapOptions.heading && Number.isFinite(defaultHeading))
|
|
1950
|
+
mapOptions.heading = defaultHeading;
|
|
1951
|
+
if (!mapOptions.tilt && Number.isFinite(defaultTilt))
|
|
1952
|
+
mapOptions.tilt = defaultTilt;
|
|
1953
|
+
const customIds = mapOptions.internalUsageAttributionIds;
|
|
1954
|
+
if (customIds == null) {
|
|
1955
|
+
mapOptions.internalUsageAttributionIds = context.internalUsageAttributionIds;
|
|
1956
|
+
} else {
|
|
1957
|
+
mapOptions.internalUsageAttributionIds = [
|
|
1958
|
+
...context.internalUsageAttributionIds || [],
|
|
1959
|
+
...customIds
|
|
1960
|
+
];
|
|
1961
|
+
}
|
|
1962
|
+
for (const key of Object.keys(mapOptions))
|
|
1963
|
+
if (mapOptions[key] === void 0)
|
|
1964
|
+
delete mapOptions[key];
|
|
694
1965
|
const savedMapStateRef = useRef(void 0);
|
|
1966
|
+
const reuseMapsRef = useRef(reuseMaps);
|
|
1967
|
+
useEffect(() => {
|
|
1968
|
+
reuseMapsRef.current = reuseMaps;
|
|
1969
|
+
}, [reuseMaps]);
|
|
695
1970
|
useEffect(
|
|
696
1971
|
() => {
|
|
697
|
-
if (!container || !apiIsLoaded)
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
} = context;
|
|
702
|
-
const {
|
|
703
|
-
mapId
|
|
704
|
-
} = props;
|
|
1972
|
+
if (!container || !apiIsLoaded)
|
|
1973
|
+
return;
|
|
1974
|
+
const { addMapInstance, removeMapInstance } = context;
|
|
1975
|
+
const { mapId } = props;
|
|
705
1976
|
const cacheKey = `${mapId || "default"}:${renderingType || "default"}:${colorScheme || "LIGHT"}`;
|
|
706
1977
|
let mapDiv;
|
|
707
1978
|
let map2;
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
1979
|
+
const cachedMap = reuseMapsRef.current && CachedMapStack.has(cacheKey) ? CachedMapStack.pop(cacheKey) : null;
|
|
1980
|
+
const cachedMapDiv = cachedMap === null || cachedMap === void 0 ? void 0 : cachedMap.getDiv();
|
|
1981
|
+
const reusedMap = cachedMap && cachedMapDiv instanceof Node ? cachedMap : null;
|
|
1982
|
+
if (reusedMap) {
|
|
1983
|
+
map2 = reusedMap;
|
|
1984
|
+
mapDiv = cachedMapDiv;
|
|
711
1985
|
container.appendChild(mapDiv);
|
|
712
1986
|
map2.setOptions(mapOptions);
|
|
713
|
-
setTimeout(() => map2.
|
|
1987
|
+
setTimeout(() => map2.moveCamera({}), 0);
|
|
714
1988
|
} else {
|
|
1989
|
+
if (cachedMap)
|
|
1990
|
+
google.maps.event.clearInstanceListeners(cachedMap);
|
|
715
1991
|
mapDiv = document.createElement("div");
|
|
716
1992
|
mapDiv.style.height = "100%";
|
|
717
1993
|
container.appendChild(mapDiv);
|
|
718
|
-
map2 = new google.maps.Map(mapDiv,
|
|
719
|
-
renderingType
|
|
720
|
-
} : {}, colorScheme ? {
|
|
721
|
-
colorScheme
|
|
722
|
-
} : {}));
|
|
1994
|
+
map2 = new google.maps.Map(mapDiv, Object.assign(Object.assign(Object.assign({}, mapOptions), renderingType ? { renderingType } : {}), colorScheme ? { colorScheme } : {}));
|
|
723
1995
|
}
|
|
724
1996
|
setMap(map2);
|
|
725
1997
|
addMapInstance(map2, id);
|
|
726
1998
|
if (defaultBounds) {
|
|
727
|
-
const {
|
|
728
|
-
padding
|
|
729
|
-
} = defaultBounds, defBounds = _objectWithoutPropertiesLoose(defaultBounds, _excluded2);
|
|
1999
|
+
const { padding } = defaultBounds, defBounds = __rest(defaultBounds, ["padding"]);
|
|
730
2000
|
map2.fitBounds(defBounds, padding);
|
|
731
2001
|
} else if (!hasZoom || !hasCenter) {
|
|
732
|
-
map2.fitBounds({
|
|
733
|
-
east: 180,
|
|
734
|
-
west: -180,
|
|
735
|
-
south: -90,
|
|
736
|
-
north: 90
|
|
737
|
-
});
|
|
2002
|
+
map2.fitBounds({ east: 180, west: -180, south: -90, north: 90 });
|
|
738
2003
|
}
|
|
739
2004
|
if (savedMapStateRef.current) {
|
|
740
|
-
const {
|
|
741
|
-
mapId: savedMapId,
|
|
742
|
-
cameraState: savedCameraState
|
|
743
|
-
} = savedMapStateRef.current;
|
|
2005
|
+
const { mapId: savedMapId, cameraState: savedCameraState } = savedMapStateRef.current;
|
|
744
2006
|
if (savedMapId !== mapId) {
|
|
745
|
-
map2.
|
|
2007
|
+
map2.moveCamera(savedCameraState);
|
|
746
2008
|
}
|
|
747
2009
|
}
|
|
748
2010
|
return () => {
|
|
@@ -752,7 +2014,7 @@ function useMapInstance(props, context) {
|
|
|
752
2014
|
cameraState: cameraStateRef.current
|
|
753
2015
|
};
|
|
754
2016
|
mapDiv.remove();
|
|
755
|
-
if (
|
|
2017
|
+
if (reuseMapsRef.current) {
|
|
756
2018
|
CachedMapStack.push(cacheKey, map2);
|
|
757
2019
|
} else {
|
|
758
2020
|
google.maps.event.clearInstanceListeners(map2);
|
|
@@ -780,15 +2042,10 @@ function useMapInstance(props, context) {
|
|
|
780
2042
|
return [map, containerRef, cameraStateRef];
|
|
781
2043
|
}
|
|
782
2044
|
const GoogleMapsContext = React__default.createContext(null);
|
|
783
|
-
const Map = (props) => {
|
|
784
|
-
const {
|
|
785
|
-
children,
|
|
786
|
-
id,
|
|
787
|
-
className,
|
|
788
|
-
style: style2
|
|
789
|
-
} = props;
|
|
2045
|
+
const Map$1 = (props) => {
|
|
2046
|
+
const { children, id, className, style: style2 } = props;
|
|
790
2047
|
const context = useContext(APIProviderContext);
|
|
791
|
-
const
|
|
2048
|
+
const loadingStatus2 = useApiLoadingStatus();
|
|
792
2049
|
if (!context) {
|
|
793
2050
|
throw new Error("<Map> can only be used inside an <ApiProvider> component.");
|
|
794
2051
|
}
|
|
@@ -799,11 +2056,10 @@ const Map = (props) => {
|
|
|
799
2056
|
const isDeckGlControlled = useDeckGLCameraUpdate(map, props);
|
|
800
2057
|
const isControlledExternally = !!props.controlled;
|
|
801
2058
|
useEffect(() => {
|
|
802
|
-
if (!map)
|
|
2059
|
+
if (!map)
|
|
2060
|
+
return;
|
|
803
2061
|
if (isDeckGlControlled) {
|
|
804
|
-
map.setOptions({
|
|
805
|
-
disableDefaultUI: true
|
|
806
|
-
});
|
|
2062
|
+
map.setOptions({ disableDefaultUI: true });
|
|
807
2063
|
}
|
|
808
2064
|
if (isDeckGlControlled || isControlledExternally) {
|
|
809
2065
|
map.setOptions({
|
|
@@ -817,7 +2073,13 @@ const Map = (props) => {
|
|
|
817
2073
|
keyboardShortcuts: props.keyboardShortcuts
|
|
818
2074
|
});
|
|
819
2075
|
};
|
|
820
|
-
}, [
|
|
2076
|
+
}, [
|
|
2077
|
+
map,
|
|
2078
|
+
isDeckGlControlled,
|
|
2079
|
+
isControlledExternally,
|
|
2080
|
+
props.gestureHandling,
|
|
2081
|
+
props.keyboardShortcuts
|
|
2082
|
+
]);
|
|
821
2083
|
const center = props.center ? toLatLngLiteral(props.center) : null;
|
|
822
2084
|
let lat = null;
|
|
823
2085
|
let lng = null;
|
|
@@ -826,348 +2088,352 @@ const Map = (props) => {
|
|
|
826
2088
|
lng = center.lng;
|
|
827
2089
|
}
|
|
828
2090
|
const cameraOptions = useMemo(() => {
|
|
829
|
-
var
|
|
2091
|
+
var _a, _b, _c;
|
|
830
2092
|
return {
|
|
831
|
-
center: {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
zoom: (_props$zoom = props.zoom) != null ? _props$zoom : 0,
|
|
836
|
-
heading: (_props$heading = props.heading) != null ? _props$heading : 0,
|
|
837
|
-
tilt: (_props$tilt = props.tilt) != null ? _props$tilt : 0
|
|
2093
|
+
center: { lat: lat !== null && lat !== void 0 ? lat : 0, lng: lng !== null && lng !== void 0 ? lng : 0 },
|
|
2094
|
+
zoom: (_a = props.zoom) !== null && _a !== void 0 ? _a : 0,
|
|
2095
|
+
heading: (_b = props.heading) !== null && _b !== void 0 ? _b : 0,
|
|
2096
|
+
tilt: (_c = props.tilt) !== null && _c !== void 0 ? _c : 0
|
|
838
2097
|
};
|
|
839
2098
|
}, [lat, lng, props.zoom, props.heading, props.tilt]);
|
|
840
2099
|
useLayoutEffect(() => {
|
|
841
|
-
if (!map || !isControlledExternally)
|
|
2100
|
+
if (!map || !isControlledExternally)
|
|
2101
|
+
return;
|
|
842
2102
|
map.moveCamera(cameraOptions);
|
|
843
2103
|
const listener = map.addListener("bounds_changed", () => {
|
|
844
2104
|
map.moveCamera(cameraOptions);
|
|
845
2105
|
});
|
|
846
2106
|
return () => listener.remove();
|
|
847
2107
|
}, [map, isControlledExternally, cameraOptions]);
|
|
848
|
-
const combinedStyle = useMemo(() =>
|
|
2108
|
+
const combinedStyle = useMemo(() => Object.assign({
|
|
849
2109
|
width: "100%",
|
|
850
2110
|
height: "100%",
|
|
851
2111
|
position: "relative",
|
|
852
2112
|
// when using deckgl, the map should be sent to the back
|
|
853
2113
|
zIndex: isDeckGlControlled ? -1 : 0
|
|
854
2114
|
}, style2), [style2, isDeckGlControlled]);
|
|
855
|
-
const contextValue = useMemo(() => ({
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}, className ? {} : combinedStyle),
|
|
863
|
-
className
|
|
864
|
-
}, /* @__PURE__ */ React__default.createElement(AuthFailureMessage, null));
|
|
865
|
-
}
|
|
866
|
-
return /* @__PURE__ */ React__default.createElement("div", _extends({
|
|
867
|
-
ref: mapRef,
|
|
868
|
-
"data-testid": "map",
|
|
869
|
-
style: className ? void 0 : combinedStyle,
|
|
870
|
-
className
|
|
871
|
-
}, id ? {
|
|
872
|
-
id
|
|
873
|
-
} : {}), map ? /* @__PURE__ */ React__default.createElement(GoogleMapsContext.Provider, {
|
|
874
|
-
value: contextValue
|
|
875
|
-
}, children) : null);
|
|
876
|
-
};
|
|
877
|
-
Map.deckGLViewProps = true;
|
|
878
|
-
const shownMessages = /* @__PURE__ */ new Set();
|
|
879
|
-
function logErrorOnce(...args) {
|
|
880
|
-
const key = JSON.stringify(args);
|
|
881
|
-
if (!shownMessages.has(key)) {
|
|
882
|
-
shownMessages.add(key);
|
|
883
|
-
console.error(...args);
|
|
2115
|
+
const contextValue = useMemo(() => ({ map }), [map]);
|
|
2116
|
+
if (loadingStatus2 === APILoadingStatus.AUTH_FAILURE) {
|
|
2117
|
+
return React__default.createElement(
|
|
2118
|
+
"div",
|
|
2119
|
+
{ style: Object.assign({ position: "relative" }, className ? {} : combinedStyle), className },
|
|
2120
|
+
React__default.createElement(AuthFailureMessage, null)
|
|
2121
|
+
);
|
|
884
2122
|
}
|
|
885
|
-
}
|
|
2123
|
+
return React__default.createElement("div", Object.assign({ ref: mapRef, "data-testid": "map", style: className ? void 0 : combinedStyle, className }, id ? { id } : {}), map ? React__default.createElement(GoogleMapsContext.Provider, { value: contextValue }, children) : null);
|
|
2124
|
+
};
|
|
2125
|
+
Map$1.deckGLViewProps = true;
|
|
886
2126
|
const useMap = (id = null) => {
|
|
887
2127
|
const ctx = useContext(APIProviderContext);
|
|
888
|
-
const {
|
|
889
|
-
map
|
|
890
|
-
} = useContext(GoogleMapsContext) || {};
|
|
2128
|
+
const { map } = useContext(GoogleMapsContext) || {};
|
|
891
2129
|
if (ctx === null) {
|
|
892
2130
|
logErrorOnce("useMap(): failed to retrieve APIProviderContext. Make sure that the <APIProvider> component exists and that the component you are calling `useMap()` from is a sibling of the <APIProvider>.");
|
|
893
2131
|
return null;
|
|
894
2132
|
}
|
|
895
|
-
const {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
if (
|
|
899
|
-
|
|
2133
|
+
const { mapInstances } = ctx;
|
|
2134
|
+
if (id !== null)
|
|
2135
|
+
return mapInstances[id] || null;
|
|
2136
|
+
if (map)
|
|
2137
|
+
return map;
|
|
900
2138
|
return mapInstances["default"] || null;
|
|
901
2139
|
};
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
const ctx = useContext(APIProviderContext);
|
|
905
|
-
useEffect(() => {
|
|
906
|
-
if (!apiIsLoaded || !ctx) return;
|
|
907
|
-
void ctx.importLibrary(name);
|
|
908
|
-
}, [apiIsLoaded, ctx, name]);
|
|
909
|
-
return (ctx == null ? void 0 : ctx.loadedLibraries[name]) || null;
|
|
910
|
-
}
|
|
2140
|
+
const noop = () => {
|
|
2141
|
+
};
|
|
911
2142
|
function useMapsEventListener(target, name, callback) {
|
|
2143
|
+
const eventFn = useEffectEvent(callback !== null && callback !== void 0 ? callback : noop);
|
|
2144
|
+
const isCallbackDefined = Boolean(callback);
|
|
912
2145
|
useEffect(() => {
|
|
913
|
-
if (!target || !name || !
|
|
914
|
-
|
|
2146
|
+
if (!target || !name || !isCallbackDefined)
|
|
2147
|
+
return;
|
|
2148
|
+
const listener = google.maps.event.addListener(target, name, eventFn);
|
|
915
2149
|
return () => listener.remove();
|
|
916
|
-
}, [target, name,
|
|
2150
|
+
}, [target, name, isCallbackDefined]);
|
|
917
2151
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
}
|
|
2152
|
+
class GlobalStyleManager {
|
|
2153
|
+
constructor() {
|
|
2154
|
+
this.renderedStyles = /* @__PURE__ */ new Set();
|
|
2155
|
+
this.styleElement = null;
|
|
2156
|
+
}
|
|
2157
|
+
getStyleElement() {
|
|
2158
|
+
if (!this.styleElement) {
|
|
2159
|
+
this.styleElement = document.createElement("style");
|
|
2160
|
+
this.styleElement.setAttribute("data-rgm-anchor-styles", "");
|
|
2161
|
+
document.head.appendChild(this.styleElement);
|
|
2162
|
+
}
|
|
2163
|
+
return this.styleElement;
|
|
2164
|
+
}
|
|
2165
|
+
addAdvancedMarkerPointerEventsOverwrite() {
|
|
2166
|
+
if (this.renderedStyles.has("marker-pointer-events")) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
const styleElement = this.getStyleElement();
|
|
2170
|
+
styleElement.textContent += `
|
|
2171
|
+
gmp-advanced-marker[data-origin='rgm'] {
|
|
2172
|
+
pointer-events: none !important;
|
|
2173
|
+
}
|
|
2174
|
+
`;
|
|
2175
|
+
this.renderedStyles.add("marker-pointer-events");
|
|
2176
|
+
}
|
|
2177
|
+
cleanup() {
|
|
2178
|
+
if (this.styleElement) {
|
|
2179
|
+
this.styleElement.remove();
|
|
2180
|
+
this.styleElement = null;
|
|
2181
|
+
this.renderedStyles.clear();
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
923
2184
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
return
|
|
929
|
-
|
|
2185
|
+
const globalStyleManager = new GlobalStyleManager();
|
|
2186
|
+
function isVersionGreaterEqual(major, minor) {
|
|
2187
|
+
var _a;
|
|
2188
|
+
if (!((_a = google === null || google === void 0 ? void 0 : google.maps) === null || _a === void 0 ? void 0 : _a.version))
|
|
2189
|
+
return void 0;
|
|
2190
|
+
const version = google.maps.version.split(".");
|
|
2191
|
+
const currentMajor = parseInt(version[0], 10);
|
|
2192
|
+
const currentMinor = parseInt(version[1], 10);
|
|
2193
|
+
return currentMajor > major || currentMajor === major && currentMinor >= minor;
|
|
930
2194
|
}
|
|
2195
|
+
const AdvancedMarkerContext = React__default.createContext(null);
|
|
2196
|
+
const AdvancedMarkerAnchorPoint = {
|
|
2197
|
+
BOTTOM: ["50%", "100%"]
|
|
2198
|
+
};
|
|
2199
|
+
const AdvancedMarker = forwardRef((props, ref) => {
|
|
2200
|
+
const { children, style: style2, className, anchorPoint } = props;
|
|
2201
|
+
const [marker, contentContainer] = useAdvancedMarker(props);
|
|
2202
|
+
const advancedMarkerContextValue = useMemo(() => marker ? { marker } : null, [marker]);
|
|
2203
|
+
useImperativeHandle(ref, () => marker, [marker]);
|
|
2204
|
+
if (!contentContainer)
|
|
2205
|
+
return null;
|
|
2206
|
+
return React__default.createElement(AdvancedMarkerContext.Provider, { value: advancedMarkerContextValue }, createPortal(React__default.createElement(MarkerContent, { anchorPoint, styles: style2, className }, children), contentContainer));
|
|
2207
|
+
});
|
|
2208
|
+
AdvancedMarker.displayName = "AdvancedMarker";
|
|
931
2209
|
function isAdvancedMarker(marker) {
|
|
932
2210
|
return marker.content !== void 0;
|
|
933
2211
|
}
|
|
934
2212
|
function isElementNode(node) {
|
|
935
2213
|
return node.nodeType === Node.ELEMENT_NODE;
|
|
936
2214
|
}
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
BOTTOM: ["50%", "100%"]
|
|
940
|
-
};
|
|
941
|
-
const MarkerContent = ({
|
|
942
|
-
children,
|
|
943
|
-
styles: styles2,
|
|
944
|
-
className,
|
|
945
|
-
anchorPoint
|
|
946
|
-
}) => {
|
|
947
|
-
const [xTranslation, yTranslation] = anchorPoint != null ? anchorPoint : AdvancedMarkerAnchorPoint["BOTTOM"];
|
|
948
|
-
let xTranslationFlipped = `-${xTranslation}`;
|
|
949
|
-
let yTranslationFlipped = `-${yTranslation}`;
|
|
950
|
-
if (xTranslation.trimStart().startsWith("-")) {
|
|
951
|
-
xTranslationFlipped = xTranslation.substring(1);
|
|
952
|
-
}
|
|
953
|
-
if (yTranslation.trimStart().startsWith("-")) {
|
|
954
|
-
yTranslationFlipped = yTranslation.substring(1);
|
|
955
|
-
}
|
|
956
|
-
const transformStyle = `translate(50%, 100%) translate(${xTranslationFlipped}, ${yTranslationFlipped})`;
|
|
957
|
-
return (
|
|
958
|
-
// anchoring container
|
|
959
|
-
/* @__PURE__ */ React__default.createElement("div", {
|
|
960
|
-
style: {
|
|
961
|
-
transform: transformStyle
|
|
962
|
-
}
|
|
963
|
-
}, /* @__PURE__ */ React__default.createElement("div", {
|
|
964
|
-
className,
|
|
965
|
-
style: styles2
|
|
966
|
-
}, children))
|
|
967
|
-
);
|
|
2215
|
+
const MarkerContent = ({ children, styles: styles2, className }) => {
|
|
2216
|
+
return React__default.createElement("div", { className, style: styles2 }, children);
|
|
968
2217
|
};
|
|
969
2218
|
function useAdvancedMarker(props) {
|
|
970
2219
|
const [marker, setMarker] = useState(null);
|
|
971
2220
|
const [contentContainer, setContentContainer] = useState(null);
|
|
972
2221
|
const map = useMap();
|
|
973
|
-
const markerLibrary = useMapsLibrary("marker");
|
|
974
|
-
const {
|
|
975
|
-
children,
|
|
976
|
-
onClick,
|
|
977
|
-
className,
|
|
978
|
-
onMouseEnter,
|
|
979
|
-
onMouseLeave,
|
|
980
|
-
onDrag,
|
|
981
|
-
onDragStart,
|
|
982
|
-
onDragEnd,
|
|
983
|
-
collisionBehavior,
|
|
984
|
-
clickable,
|
|
985
|
-
draggable,
|
|
986
|
-
position,
|
|
987
|
-
title: title2,
|
|
988
|
-
zIndex
|
|
989
|
-
} = props;
|
|
2222
|
+
const markerLibrary = useMapsLibrary("marker");
|
|
2223
|
+
const { children, onClick, onKeyDown, onKeyUp, className, onMouseEnter, onMouseLeave, onDrag, onDragStart, onDragEnd, collisionBehavior, clickable, draggable, position, title: title2, zIndex, anchorPoint, anchorLeft, anchorTop } = props;
|
|
990
2224
|
const numChildren = Children.count(children);
|
|
991
2225
|
useEffect(() => {
|
|
992
|
-
if (!map || !markerLibrary)
|
|
2226
|
+
if (!map || !markerLibrary)
|
|
2227
|
+
return;
|
|
993
2228
|
const newMarker = new markerLibrary.AdvancedMarkerElement();
|
|
994
2229
|
newMarker.map = map;
|
|
995
2230
|
setMarker(newMarker);
|
|
996
2231
|
let contentElement = null;
|
|
997
2232
|
if (numChildren > 0) {
|
|
998
2233
|
contentElement = document.createElement("div");
|
|
999
|
-
contentElement.isCustomMarker = true;
|
|
1000
2234
|
newMarker.content = contentElement;
|
|
1001
2235
|
setContentContainer(contentElement);
|
|
1002
2236
|
}
|
|
1003
2237
|
return () => {
|
|
1004
|
-
var _contentElement;
|
|
1005
2238
|
newMarker.map = null;
|
|
1006
|
-
|
|
2239
|
+
contentElement === null || contentElement === void 0 ? void 0 : contentElement.remove();
|
|
1007
2240
|
setMarker(null);
|
|
1008
2241
|
setContentContainer(null);
|
|
1009
2242
|
};
|
|
1010
2243
|
}, [map, markerLibrary, numChildren]);
|
|
1011
2244
|
useEffect(() => {
|
|
1012
|
-
if (!marker || !marker.content || numChildren > 0)
|
|
1013
|
-
|
|
2245
|
+
if (!(marker === null || marker === void 0 ? void 0 : marker.content) || !isElementNode(marker.content) || numChildren > 0)
|
|
2246
|
+
return;
|
|
2247
|
+
marker.content.className = className !== null && className !== void 0 ? className : "";
|
|
1014
2248
|
}, [marker, className, numChildren]);
|
|
2249
|
+
useAdvancedMarkerAnchoring(marker, anchorPoint, anchorLeft, anchorTop, numChildren > 0);
|
|
1015
2250
|
usePropBinding(marker, "position", position);
|
|
1016
|
-
usePropBinding(marker, "title", title2
|
|
2251
|
+
usePropBinding(marker, "title", title2 !== null && title2 !== void 0 ? title2 : "");
|
|
1017
2252
|
usePropBinding(marker, "zIndex", zIndex);
|
|
1018
2253
|
usePropBinding(marker, "collisionBehavior", collisionBehavior);
|
|
1019
2254
|
useEffect(() => {
|
|
1020
|
-
if (!marker)
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
2255
|
+
if (!marker)
|
|
2256
|
+
return;
|
|
2257
|
+
if (draggable !== void 0)
|
|
2258
|
+
marker.gmpDraggable = draggable;
|
|
2259
|
+
else if (onDrag || onDragStart || onDragEnd)
|
|
2260
|
+
marker.gmpDraggable = true;
|
|
2261
|
+
else
|
|
2262
|
+
marker.gmpDraggable = false;
|
|
1024
2263
|
}, [marker, draggable, onDrag, onDragEnd, onDragStart]);
|
|
1025
2264
|
useEffect(() => {
|
|
1026
|
-
if (!marker)
|
|
1027
|
-
|
|
2265
|
+
if (!marker)
|
|
2266
|
+
return;
|
|
2267
|
+
const gmpClickable = clickable !== void 0 ? clickable : Boolean(onClick) || Boolean(onKeyDown) || Boolean(onKeyUp) || Boolean(onMouseEnter) || Boolean(onMouseLeave);
|
|
1028
2268
|
marker.gmpClickable = gmpClickable;
|
|
1029
|
-
if (
|
|
1030
|
-
marker.content.style.pointerEvents = "none";
|
|
1031
|
-
|
|
1032
|
-
marker.content.firstElementChild.style.pointerEvents = "all";
|
|
1033
|
-
}
|
|
2269
|
+
if ((marker === null || marker === void 0 ? void 0 : marker.content) && isElementNode(marker.content)) {
|
|
2270
|
+
marker.content.style.pointerEvents = gmpClickable ? "all" : "none";
|
|
2271
|
+
marker.content.style.cursor = gmpClickable && onClick ? "pointer" : "";
|
|
1034
2272
|
}
|
|
1035
|
-
}, [
|
|
1036
|
-
|
|
2273
|
+
}, [
|
|
2274
|
+
marker,
|
|
2275
|
+
clickable,
|
|
2276
|
+
onClick,
|
|
2277
|
+
onKeyDown,
|
|
2278
|
+
onKeyUp,
|
|
2279
|
+
onMouseEnter,
|
|
2280
|
+
onMouseLeave
|
|
2281
|
+
]);
|
|
1037
2282
|
useMapsEventListener(marker, "drag", onDrag);
|
|
1038
2283
|
useMapsEventListener(marker, "dragstart", onDragStart);
|
|
1039
2284
|
useMapsEventListener(marker, "dragend", onDragEnd);
|
|
1040
|
-
useDomEventListener(marker
|
|
1041
|
-
useDomEventListener(marker
|
|
2285
|
+
useDomEventListener(marker, "gmp-click", onClick);
|
|
2286
|
+
useDomEventListener(marker, "keydown", onKeyDown);
|
|
2287
|
+
useDomEventListener(marker, "keyup", onKeyUp);
|
|
2288
|
+
useDomEventListener(marker, "mouseenter", onMouseEnter);
|
|
2289
|
+
useDomEventListener(marker, "mouseleave", onMouseLeave);
|
|
1042
2290
|
return [marker, contentContainer];
|
|
1043
2291
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
className
|
|
1063
|
-
}, children), contentContainer));
|
|
1064
|
-
});
|
|
1065
|
-
function setValueForStyles(element, styles2, prevStyles) {
|
|
1066
|
-
if (styles2 != null && typeof styles2 !== "object") {
|
|
1067
|
-
throw new Error("The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.");
|
|
1068
|
-
}
|
|
1069
|
-
const elementStyle = element.style;
|
|
1070
|
-
if (prevStyles == null) {
|
|
1071
|
-
if (styles2 == null) return;
|
|
1072
|
-
for (const styleName in styles2) {
|
|
1073
|
-
if (!styles2.hasOwnProperty(styleName)) continue;
|
|
1074
|
-
setValueForStyle(elementStyle, styleName, styles2[styleName]);
|
|
2292
|
+
function useAdvancedMarkerAnchoring(marker, anchorPoint, anchorLeft, anchorTop, hasChildren) {
|
|
2293
|
+
useEffect(() => {
|
|
2294
|
+
if (!marker || !hasChildren)
|
|
2295
|
+
return;
|
|
2296
|
+
const anchorOptionsSupported = isVersionGreaterEqual(3, 62);
|
|
2297
|
+
const contentElement = marker.content;
|
|
2298
|
+
if (!contentElement || !isElementNode(contentElement))
|
|
2299
|
+
return;
|
|
2300
|
+
if (anchorLeft !== void 0 || anchorTop !== void 0) {
|
|
2301
|
+
if (!anchorOptionsSupported) {
|
|
2302
|
+
console.warn(`AdvancedMarker: The anchorLeft and anchorTop props are only supported in Google Maps API version 3.62 and above. The current version is ${google.maps.version}.`);
|
|
2303
|
+
}
|
|
2304
|
+
marker.anchorLeft = anchorLeft;
|
|
2305
|
+
marker.anchorTop = anchorTop;
|
|
2306
|
+
if (anchorPoint !== void 0) {
|
|
2307
|
+
console.warn("AdvancedMarker: the anchorPoint prop is ignored when anchorLeft and/or anchorTop are set.");
|
|
2308
|
+
}
|
|
2309
|
+
return;
|
|
1075
2310
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
elementStyle.cssFloat = "";
|
|
2311
|
+
if (anchorPoint !== void 0) {
|
|
2312
|
+
const [x, y] = anchorPoint !== null && anchorPoint !== void 0 ? anchorPoint : AdvancedMarkerAnchorPoint["BOTTOM"];
|
|
2313
|
+
const translateX = `calc(-1 * ${x})`;
|
|
2314
|
+
const translateY = `calc(-1 * ${y})`;
|
|
2315
|
+
if (anchorOptionsSupported) {
|
|
2316
|
+
marker.anchorLeft = translateX;
|
|
2317
|
+
marker.anchorTop = translateY;
|
|
2318
|
+
contentElement.style.transform = "";
|
|
1085
2319
|
} else {
|
|
1086
|
-
|
|
2320
|
+
contentElement.style.transform = `translate(50%, 100%) translate(${translateX}, ${translateY})`;
|
|
2321
|
+
marker.dataset.origin = "rgm";
|
|
2322
|
+
globalStyleManager.addAdvancedMarkerPointerEventsOverwrite();
|
|
1087
2323
|
}
|
|
1088
2324
|
}
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
2325
|
+
}, [marker, anchorPoint, anchorLeft, anchorTop, hasChildren]);
|
|
2326
|
+
}
|
|
2327
|
+
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
2328
|
+
const UNSET = null;
|
|
2329
|
+
function getChangedOptions(nextOptions, trackedOptions) {
|
|
2330
|
+
let changedOptions = null;
|
|
2331
|
+
const keys2 = /* @__PURE__ */ new Set([
|
|
2332
|
+
...Object.keys(trackedOptions),
|
|
2333
|
+
...Object.keys(nextOptions)
|
|
2334
|
+
]);
|
|
2335
|
+
for (const key of keys2) {
|
|
2336
|
+
if (!hasOwn(nextOptions, key)) {
|
|
2337
|
+
changedOptions !== null && changedOptions !== void 0 ? changedOptions : changedOptions = /* @__PURE__ */ Object.create(null);
|
|
2338
|
+
changedOptions[key] = UNSET;
|
|
2339
|
+
continue;
|
|
1095
2340
|
}
|
|
2341
|
+
if (hasOwn(trackedOptions, key) && deepEqual(trackedOptions[key], nextOptions[key]))
|
|
2342
|
+
continue;
|
|
2343
|
+
changedOptions !== null && changedOptions !== void 0 ? changedOptions : changedOptions = /* @__PURE__ */ Object.create(null);
|
|
2344
|
+
changedOptions[key] = nextOptions[key];
|
|
1096
2345
|
}
|
|
2346
|
+
return changedOptions;
|
|
1097
2347
|
}
|
|
1098
|
-
function
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
2348
|
+
function snapshotOptions(value) {
|
|
2349
|
+
if (Array.isArray(value))
|
|
2350
|
+
return value.map((entry) => snapshotOptions(entry));
|
|
2351
|
+
if (value === null || typeof value !== "object")
|
|
2352
|
+
return value;
|
|
2353
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2354
|
+
if (prototype !== Object.prototype)
|
|
2355
|
+
return value;
|
|
2356
|
+
const copy = {};
|
|
2357
|
+
for (const key of Object.keys(value))
|
|
2358
|
+
copy[key] = snapshotOptions(value[key]);
|
|
2359
|
+
return copy;
|
|
2360
|
+
}
|
|
2361
|
+
const appliedOptionsByObject = /* @__PURE__ */ new WeakMap();
|
|
2362
|
+
function setMapObjectOptions(object, options, { alreadyApplied = false } = {}) {
|
|
2363
|
+
var _a;
|
|
2364
|
+
if (alreadyApplied) {
|
|
2365
|
+
appliedOptionsByObject.set(object, snapshotOptions(options));
|
|
2366
|
+
return;
|
|
1118
2367
|
}
|
|
2368
|
+
const appliedOptions = (_a = appliedOptionsByObject.get(object)) !== null && _a !== void 0 ? _a : {};
|
|
2369
|
+
const changedOptions = getChangedOptions(options, appliedOptions);
|
|
2370
|
+
if (!changedOptions)
|
|
2371
|
+
return;
|
|
2372
|
+
object.setOptions(changedOptions);
|
|
2373
|
+
appliedOptionsByObject.set(object, snapshotOptions(options));
|
|
1119
2374
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
"
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
"
|
|
1142
|
-
"
|
|
1143
|
-
"
|
|
1144
|
-
"
|
|
1145
|
-
"
|
|
1146
|
-
"
|
|
1147
|
-
"
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
"
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
]);
|
|
1167
|
-
|
|
1168
|
-
|
|
2375
|
+
function useCircle(props) {
|
|
2376
|
+
var _a, _b, _c;
|
|
2377
|
+
const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onRadiusChanged, onCenterChanged, center, defaultCenter, radius, defaultRadius } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onRadiusChanged", "onCenterChanged", "center", "defaultCenter", "radius", "defaultRadius"]);
|
|
2378
|
+
const [circle, setCircle] = useState(null);
|
|
2379
|
+
const map = useMap();
|
|
2380
|
+
const circleOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onCenterChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onRadiusChanged) }), deepEqual);
|
|
2381
|
+
useEffect(() => {
|
|
2382
|
+
if (!map) {
|
|
2383
|
+
if (map === void 0)
|
|
2384
|
+
console.error("<Circle> has to be inside a Map component.");
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
const newCircle = new google.maps.Circle(Object.assign(Object.assign({}, circleOptions), { center: center !== null && center !== void 0 ? center : defaultCenter, radius: radius !== null && radius !== void 0 ? radius : defaultRadius }));
|
|
2388
|
+
setMapObjectOptions(newCircle, circleOptions, { alreadyApplied: true });
|
|
2389
|
+
newCircle.setMap(map);
|
|
2390
|
+
setCircle(newCircle);
|
|
2391
|
+
return () => {
|
|
2392
|
+
newCircle.setMap(null);
|
|
2393
|
+
setCircle(null);
|
|
2394
|
+
};
|
|
2395
|
+
}, [map]);
|
|
2396
|
+
useMapsEventListener(circle, "click", onClick);
|
|
2397
|
+
useMapsEventListener(circle, "drag", onDrag);
|
|
2398
|
+
useMapsEventListener(circle, "dragstart", onDragStart);
|
|
2399
|
+
useMapsEventListener(circle, "dragend", onDragEnd);
|
|
2400
|
+
useMapsEventListener(circle, "mouseover", onMouseOver);
|
|
2401
|
+
useMapsEventListener(circle, "mouseout", onMouseOut);
|
|
2402
|
+
useMapsEventListener(circle, "radius_changed", onRadiusChanged ? () => {
|
|
2403
|
+
const newRadius = circle === null || circle === void 0 ? void 0 : circle.getRadius();
|
|
2404
|
+
if (newRadius !== void 0)
|
|
2405
|
+
onRadiusChanged(newRadius);
|
|
2406
|
+
} : null);
|
|
2407
|
+
useMapsEventListener(circle, "center_changed", onCenterChanged ? () => {
|
|
2408
|
+
onCenterChanged(circle === null || circle === void 0 ? void 0 : circle.getCenter());
|
|
2409
|
+
} : null);
|
|
2410
|
+
useEffect(() => {
|
|
2411
|
+
if (!circle)
|
|
2412
|
+
return;
|
|
2413
|
+
setMapObjectOptions(circle, circleOptions);
|
|
2414
|
+
}, [circle, circleOptions]);
|
|
2415
|
+
useEffect(() => {
|
|
2416
|
+
if (!circle || !center)
|
|
2417
|
+
return;
|
|
2418
|
+
if (!latLngEquals(center, circle.getCenter())) {
|
|
2419
|
+
circle.setCenter(center);
|
|
2420
|
+
}
|
|
2421
|
+
}, [circle, center]);
|
|
2422
|
+
useEffect(() => {
|
|
2423
|
+
if (!circle || radius === void 0)
|
|
2424
|
+
return;
|
|
2425
|
+
if (radius !== circle.getRadius()) {
|
|
2426
|
+
circle.setRadius(radius);
|
|
2427
|
+
}
|
|
2428
|
+
}, [circle, radius]);
|
|
2429
|
+
return circle;
|
|
1169
2430
|
}
|
|
1170
|
-
const
|
|
2431
|
+
const Circle = forwardRef((props, ref) => {
|
|
2432
|
+
const circle = useCircle(props);
|
|
2433
|
+
useImperativeHandle(ref, () => circle, [circle]);
|
|
2434
|
+
return React__default.createElement(React__default.Fragment, null);
|
|
2435
|
+
});
|
|
2436
|
+
Circle.displayName = "Circle";
|
|
1171
2437
|
const InfoWindow = (props) => {
|
|
1172
2438
|
const {
|
|
1173
2439
|
// content options
|
|
@@ -1182,32 +2448,33 @@ const InfoWindow = (props) => {
|
|
|
1182
2448
|
// events
|
|
1183
2449
|
onClose,
|
|
1184
2450
|
onCloseClick
|
|
1185
|
-
|
|
1186
|
-
} = props, infoWindowOptions = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
2451
|
+
} = props, volatileInfoWindowOptions = __rest(props, ["children", "headerContent", "style", "className", "pixelOffset", "anchor", "shouldFocus", "onClose", "onCloseClick"]);
|
|
1187
2452
|
const mapsLibrary = useMapsLibrary("maps");
|
|
1188
2453
|
const [infoWindow, setInfoWindow] = useState(null);
|
|
1189
2454
|
const contentContainerRef = useRef(null);
|
|
1190
2455
|
const headerContainerRef = useRef(null);
|
|
2456
|
+
const infoWindowOptions = useMemoized(volatileInfoWindowOptions, deepEqual);
|
|
1191
2457
|
useEffect(
|
|
1192
2458
|
() => {
|
|
1193
|
-
if (!mapsLibrary)
|
|
2459
|
+
if (!mapsLibrary)
|
|
2460
|
+
return;
|
|
1194
2461
|
contentContainerRef.current = document.createElement("div");
|
|
1195
2462
|
headerContainerRef.current = document.createElement("div");
|
|
1196
|
-
const opts = infoWindowOptions;
|
|
2463
|
+
const opts = Object.assign({}, infoWindowOptions);
|
|
1197
2464
|
if (pixelOffset) {
|
|
1198
2465
|
opts.pixelOffset = new google.maps.Size(pixelOffset[0], pixelOffset[1]);
|
|
1199
2466
|
}
|
|
1200
2467
|
if (headerContent) {
|
|
1201
2468
|
opts.headerContent = typeof headerContent === "string" ? headerContent : headerContainerRef.current;
|
|
1202
2469
|
}
|
|
1203
|
-
const infoWindow2 = new google.maps.InfoWindow(
|
|
2470
|
+
const infoWindow2 = new google.maps.InfoWindow(opts);
|
|
1204
2471
|
infoWindow2.setContent(contentContainerRef.current);
|
|
1205
2472
|
setInfoWindow(infoWindow2);
|
|
1206
2473
|
return () => {
|
|
1207
|
-
var
|
|
2474
|
+
var _a, _b;
|
|
1208
2475
|
infoWindow2.setContent(null);
|
|
1209
|
-
(
|
|
1210
|
-
(
|
|
2476
|
+
(_a = contentContainerRef.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
2477
|
+
(_b = headerContainerRef.current) === null || _b === void 0 ? void 0 : _b.remove();
|
|
1211
2478
|
contentContainerRef.current = null;
|
|
1212
2479
|
headerContainerRef.current = null;
|
|
1213
2480
|
setInfoWindow(null);
|
|
@@ -1223,16 +2490,19 @@ const InfoWindow = (props) => {
|
|
|
1223
2490
|
[mapsLibrary]
|
|
1224
2491
|
);
|
|
1225
2492
|
const prevStyleRef = useRef(null);
|
|
1226
|
-
|
|
1227
|
-
if (!infoWindow || !contentContainerRef.current)
|
|
2493
|
+
useLayoutEffect(() => {
|
|
2494
|
+
if (!infoWindow || !contentContainerRef.current)
|
|
2495
|
+
return;
|
|
1228
2496
|
setValueForStyles(contentContainerRef.current, style2 || null, prevStyleRef.current);
|
|
1229
2497
|
prevStyleRef.current = style2 || null;
|
|
1230
|
-
if (className !== contentContainerRef.current.className)
|
|
2498
|
+
if (className !== contentContainerRef.current.className)
|
|
2499
|
+
contentContainerRef.current.className = className || "";
|
|
1231
2500
|
}, [infoWindow, className, style2]);
|
|
1232
|
-
|
|
2501
|
+
useEffect(
|
|
1233
2502
|
() => {
|
|
1234
|
-
if (!infoWindow)
|
|
1235
|
-
|
|
2503
|
+
if (!infoWindow)
|
|
2504
|
+
return;
|
|
2505
|
+
const opts = Object.assign({}, infoWindowOptions);
|
|
1236
2506
|
if (!pixelOffset) {
|
|
1237
2507
|
opts.pixelOffset = null;
|
|
1238
2508
|
} else {
|
|
@@ -1243,7 +2513,7 @@ const InfoWindow = (props) => {
|
|
|
1243
2513
|
} else {
|
|
1244
2514
|
opts.headerContent = typeof headerContent === "string" ? headerContent : headerContainerRef.current;
|
|
1245
2515
|
}
|
|
1246
|
-
infoWindow.setOptions(
|
|
2516
|
+
infoWindow.setOptions(opts);
|
|
1247
2517
|
},
|
|
1248
2518
|
// dependency `infoWindow` isn't needed since options are also passed
|
|
1249
2519
|
// to the constructor when a new infoWindow is created.
|
|
@@ -1253,24 +2523,22 @@ const InfoWindow = (props) => {
|
|
|
1253
2523
|
useMapsEventListener(infoWindow, "close", onClose);
|
|
1254
2524
|
useMapsEventListener(infoWindow, "closeclick", onCloseClick);
|
|
1255
2525
|
const map = useMap();
|
|
1256
|
-
|
|
1257
|
-
|
|
2526
|
+
useEffect(() => {
|
|
2527
|
+
var _a;
|
|
2528
|
+
if (!map || !infoWindow || anchor === null)
|
|
2529
|
+
return;
|
|
1258
2530
|
const isOpenedWithAnchor = !!anchor;
|
|
1259
|
-
const openOptions = {
|
|
1260
|
-
map
|
|
1261
|
-
};
|
|
2531
|
+
const openOptions = { map };
|
|
1262
2532
|
if (anchor) {
|
|
1263
2533
|
openOptions.anchor = anchor;
|
|
1264
2534
|
if (isAdvancedMarker(anchor) && anchor.content instanceof Element) {
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
const
|
|
1270
|
-
const
|
|
1271
|
-
const
|
|
1272
|
-
const anchorOffsetY = contentBcr.y - wrapperBcr.y;
|
|
1273
|
-
const opts = infoWindowOptions;
|
|
2535
|
+
const anchorBcr = anchor === null || anchor === void 0 ? void 0 : anchor.getBoundingClientRect();
|
|
2536
|
+
if (anchorBcr && anchor.dataset.origin === "rgm") {
|
|
2537
|
+
const anchorDomContent = (_a = anchor.content.firstElementChild) === null || _a === void 0 ? void 0 : _a.firstElementChild;
|
|
2538
|
+
const contentBcr = anchorDomContent === null || anchorDomContent === void 0 ? void 0 : anchorDomContent.getBoundingClientRect();
|
|
2539
|
+
const anchorOffsetX = contentBcr.x - anchorBcr.x + (contentBcr.width - anchorBcr.width) / 2;
|
|
2540
|
+
const anchorOffsetY = contentBcr.y - anchorBcr.y;
|
|
2541
|
+
const opts = Object.assign({}, infoWindowOptions);
|
|
1274
2542
|
opts.pixelOffset = new google.maps.Size(pixelOffset ? pixelOffset[0] + anchorOffsetX : anchorOffsetX, pixelOffset ? pixelOffset[1] + anchorOffsetY : anchorOffsetY);
|
|
1275
2543
|
infoWindow.setOptions(opts);
|
|
1276
2544
|
}
|
|
@@ -1281,31 +2549,267 @@ const InfoWindow = (props) => {
|
|
|
1281
2549
|
}
|
|
1282
2550
|
infoWindow.open(openOptions);
|
|
1283
2551
|
return () => {
|
|
1284
|
-
if (isOpenedWithAnchor)
|
|
2552
|
+
if (isOpenedWithAnchor)
|
|
2553
|
+
infoWindow.set("anchor", null);
|
|
1285
2554
|
infoWindow.close();
|
|
1286
2555
|
};
|
|
1287
2556
|
}, [infoWindow, anchor, map, shouldFocus, infoWindowOptions, pixelOffset]);
|
|
1288
|
-
return
|
|
2557
|
+
return React__default.createElement(
|
|
2558
|
+
React__default.Fragment,
|
|
2559
|
+
null,
|
|
2560
|
+
contentContainerRef.current && createPortal(children, contentContainerRef.current),
|
|
2561
|
+
headerContainerRef.current !== null && createPortal(headerContent, headerContainerRef.current)
|
|
2562
|
+
);
|
|
1289
2563
|
};
|
|
1290
|
-
|
|
2564
|
+
function getPathsArray(polygon) {
|
|
2565
|
+
const mvcPaths = polygon.getPaths();
|
|
2566
|
+
const result = [];
|
|
2567
|
+
for (let i = 0; i < mvcPaths.getLength(); i++) {
|
|
2568
|
+
result.push(mvcPaths.getAt(i).getArray());
|
|
2569
|
+
}
|
|
2570
|
+
return result;
|
|
2571
|
+
}
|
|
2572
|
+
function usePolygon(props) {
|
|
2573
|
+
var _a, _b, _c;
|
|
2574
|
+
const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onPathsChanged, polygon: externalPolygon, encodedPaths, paths, defaultPaths } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onPathsChanged", "polygon", "encodedPaths", "paths", "defaultPaths"]);
|
|
2575
|
+
const [polygon, setPolygon] = useState(null);
|
|
2576
|
+
const map = useMap();
|
|
2577
|
+
const geometryLibrary = useMapsLibrary("geometry");
|
|
2578
|
+
const isUpdatingRef = useRef(false);
|
|
2579
|
+
const polygonOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onPathsChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onPathsChanged) }), deepEqual);
|
|
2580
|
+
useEffect(() => {
|
|
2581
|
+
if (!map) {
|
|
2582
|
+
if (map === void 0)
|
|
2583
|
+
console.error("<Polygon> has to be inside a Map component.");
|
|
2584
|
+
return;
|
|
2585
|
+
}
|
|
2586
|
+
let instance;
|
|
2587
|
+
if (externalPolygon) {
|
|
2588
|
+
instance = externalPolygon;
|
|
2589
|
+
const initialPaths = paths !== null && paths !== void 0 ? paths : defaultPaths;
|
|
2590
|
+
if (initialPaths && Array.isArray(initialPaths)) {
|
|
2591
|
+
instance.setPaths(initialPaths);
|
|
2592
|
+
}
|
|
2593
|
+
instance.setOptions(polygonOptions);
|
|
2594
|
+
} else {
|
|
2595
|
+
const initialPaths = paths !== null && paths !== void 0 ? paths : defaultPaths;
|
|
2596
|
+
const polygonOptionsWithPaths = Object.assign({}, polygonOptions);
|
|
2597
|
+
if (initialPaths && Array.isArray(initialPaths)) {
|
|
2598
|
+
polygonOptionsWithPaths.paths = initialPaths;
|
|
2599
|
+
}
|
|
2600
|
+
instance = new google.maps.Polygon(polygonOptionsWithPaths);
|
|
2601
|
+
}
|
|
2602
|
+
setMapObjectOptions(instance, polygonOptions, { alreadyApplied: true });
|
|
2603
|
+
instance.setMap(map);
|
|
2604
|
+
setPolygon(instance);
|
|
2605
|
+
return () => {
|
|
2606
|
+
instance.setMap(null);
|
|
2607
|
+
setPolygon(null);
|
|
2608
|
+
};
|
|
2609
|
+
}, [map, externalPolygon]);
|
|
2610
|
+
useMapsEventListener(polygon, "click", onClick);
|
|
2611
|
+
useMapsEventListener(polygon, "drag", onDrag);
|
|
2612
|
+
useMapsEventListener(polygon, "dragstart", onDragStart);
|
|
2613
|
+
useMapsEventListener(polygon, "mouseover", onMouseOver);
|
|
2614
|
+
useMapsEventListener(polygon, "mouseout", onMouseOut);
|
|
2615
|
+
useMapsEventListener(polygon, "dragend", (e) => {
|
|
2616
|
+
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(e);
|
|
2617
|
+
if (onPathsChanged && polygon && !isUpdatingRef.current) {
|
|
2618
|
+
onPathsChanged(getPathsArray(polygon));
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2621
|
+
useEffect(() => {
|
|
2622
|
+
if (!polygon || !onPathsChanged)
|
|
2623
|
+
return;
|
|
2624
|
+
const listeners2 = [];
|
|
2625
|
+
const mvcPaths = polygon.getPaths();
|
|
2626
|
+
if (typeof mvcPaths.getLength !== "function" || typeof mvcPaths.getAt !== "function") {
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
const handlePathsChange = () => {
|
|
2630
|
+
if (!isUpdatingRef.current) {
|
|
2631
|
+
onPathsChanged(getPathsArray(polygon));
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
const subscribeToInnerPath = (innerPath) => {
|
|
2635
|
+
listeners2.push(google.maps.event.addListener(innerPath, "insert_at", handlePathsChange));
|
|
2636
|
+
listeners2.push(google.maps.event.addListener(innerPath, "remove_at", handlePathsChange));
|
|
2637
|
+
listeners2.push(google.maps.event.addListener(innerPath, "set_at", handlePathsChange));
|
|
2638
|
+
};
|
|
2639
|
+
for (let i = 0; i < mvcPaths.getLength(); i++) {
|
|
2640
|
+
subscribeToInnerPath(mvcPaths.getAt(i));
|
|
2641
|
+
}
|
|
2642
|
+
listeners2.push(google.maps.event.addListener(mvcPaths, "insert_at", (index) => {
|
|
2643
|
+
subscribeToInnerPath(mvcPaths.getAt(index));
|
|
2644
|
+
handlePathsChange();
|
|
2645
|
+
}));
|
|
2646
|
+
listeners2.push(google.maps.event.addListener(mvcPaths, "set_at", (index) => {
|
|
2647
|
+
subscribeToInnerPath(mvcPaths.getAt(index));
|
|
2648
|
+
handlePathsChange();
|
|
2649
|
+
}));
|
|
2650
|
+
listeners2.push(google.maps.event.addListener(mvcPaths, "remove_at", handlePathsChange));
|
|
2651
|
+
return () => {
|
|
2652
|
+
listeners2.forEach((listener) => listener.remove());
|
|
2653
|
+
};
|
|
2654
|
+
}, [
|
|
2655
|
+
polygon,
|
|
2656
|
+
onPathsChanged,
|
|
2657
|
+
paths,
|
|
2658
|
+
encodedPaths,
|
|
2659
|
+
polygonOptions.editable,
|
|
2660
|
+
polygonOptions.draggable
|
|
2661
|
+
]);
|
|
2662
|
+
useEffect(() => {
|
|
2663
|
+
if (!polygon)
|
|
2664
|
+
return;
|
|
2665
|
+
setMapObjectOptions(polygon, polygonOptions);
|
|
2666
|
+
}, [polygon, polygonOptions]);
|
|
2667
|
+
useEffect(() => {
|
|
2668
|
+
if (!polygon || !paths)
|
|
2669
|
+
return;
|
|
2670
|
+
if (!Array.isArray(paths))
|
|
2671
|
+
return;
|
|
2672
|
+
const firstPath = paths[0];
|
|
2673
|
+
const normalizedPaths = Array.isArray(firstPath) ? paths : [paths];
|
|
2674
|
+
const currentPaths = polygon.getPaths();
|
|
2675
|
+
if (!pathsEquals(normalizedPaths, currentPaths)) {
|
|
2676
|
+
isUpdatingRef.current = true;
|
|
2677
|
+
polygon.setPaths(paths);
|
|
2678
|
+
isUpdatingRef.current = false;
|
|
2679
|
+
}
|
|
2680
|
+
}, [polygon, paths]);
|
|
2681
|
+
useEffect(() => {
|
|
2682
|
+
if (!polygon || !encodedPaths || !geometryLibrary)
|
|
2683
|
+
return;
|
|
2684
|
+
isUpdatingRef.current = true;
|
|
2685
|
+
const decodedPaths = encodedPaths.map((encodedPath) => geometryLibrary.encoding.decodePath(encodedPath));
|
|
2686
|
+
polygon.setPaths(decodedPaths);
|
|
2687
|
+
isUpdatingRef.current = false;
|
|
2688
|
+
}, [polygon, encodedPaths, geometryLibrary]);
|
|
2689
|
+
return polygon;
|
|
2690
|
+
}
|
|
2691
|
+
const Polygon = forwardRef((props, ref) => {
|
|
2692
|
+
const polygon = usePolygon(props);
|
|
2693
|
+
useImperativeHandle(ref, () => polygon, [polygon]);
|
|
2694
|
+
return React__default.createElement(React__default.Fragment, null);
|
|
2695
|
+
});
|
|
2696
|
+
Polygon.displayName = "Polygon";
|
|
2697
|
+
function usePolyline(props) {
|
|
2698
|
+
var _a, _b, _c;
|
|
2699
|
+
const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onPathChanged, polyline: externalPolyline, encodedPath, path, defaultPath } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onPathChanged", "polyline", "encodedPath", "path", "defaultPath"]);
|
|
2700
|
+
const [polyline, setPolyline] = useState(null);
|
|
2701
|
+
const map = useMap();
|
|
2702
|
+
const geometryLibrary = useMapsLibrary("geometry");
|
|
2703
|
+
const isUpdatingRef = useRef(false);
|
|
2704
|
+
const polylineOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onPathChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onPathChanged) }), deepEqual);
|
|
2705
|
+
useEffect(() => {
|
|
2706
|
+
if (!map) {
|
|
2707
|
+
if (map === void 0)
|
|
2708
|
+
console.error("<Polyline> has to be inside a Map component.");
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2711
|
+
let instance;
|
|
2712
|
+
if (externalPolyline) {
|
|
2713
|
+
instance = externalPolyline;
|
|
2714
|
+
const initialPath = path !== null && path !== void 0 ? path : defaultPath;
|
|
2715
|
+
if (initialPath && Array.isArray(initialPath)) {
|
|
2716
|
+
instance.setPath(initialPath);
|
|
2717
|
+
}
|
|
2718
|
+
instance.setOptions(polylineOptions);
|
|
2719
|
+
} else {
|
|
2720
|
+
const initialPath = path !== null && path !== void 0 ? path : defaultPath;
|
|
2721
|
+
const polylineOptionsWithPath = Object.assign({}, polylineOptions);
|
|
2722
|
+
if (initialPath && Array.isArray(initialPath)) {
|
|
2723
|
+
polylineOptionsWithPath.path = initialPath;
|
|
2724
|
+
}
|
|
2725
|
+
instance = new google.maps.Polyline(polylineOptionsWithPath);
|
|
2726
|
+
}
|
|
2727
|
+
setMapObjectOptions(instance, polylineOptions, { alreadyApplied: true });
|
|
2728
|
+
instance.setMap(map);
|
|
2729
|
+
setPolyline(instance);
|
|
2730
|
+
return () => {
|
|
2731
|
+
instance.setMap(null);
|
|
2732
|
+
setPolyline(null);
|
|
2733
|
+
};
|
|
2734
|
+
}, [map, externalPolyline]);
|
|
2735
|
+
useMapsEventListener(polyline, "click", onClick);
|
|
2736
|
+
useMapsEventListener(polyline, "drag", onDrag);
|
|
2737
|
+
useMapsEventListener(polyline, "dragstart", onDragStart);
|
|
2738
|
+
useMapsEventListener(polyline, "mouseover", onMouseOver);
|
|
2739
|
+
useMapsEventListener(polyline, "mouseout", onMouseOut);
|
|
2740
|
+
useMapsEventListener(polyline, "dragend", (e) => {
|
|
2741
|
+
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(e);
|
|
2742
|
+
if (onPathChanged && polyline && !isUpdatingRef.current) {
|
|
2743
|
+
onPathChanged(polyline.getPath().getArray());
|
|
2744
|
+
}
|
|
2745
|
+
});
|
|
2746
|
+
useEffect(() => {
|
|
2747
|
+
if (!polyline || !onPathChanged)
|
|
2748
|
+
return;
|
|
2749
|
+
const mvcPath = polyline.getPath();
|
|
2750
|
+
if (!mvcPath)
|
|
2751
|
+
return;
|
|
2752
|
+
const handlePathChange = () => {
|
|
2753
|
+
if (!isUpdatingRef.current) {
|
|
2754
|
+
onPathChanged(mvcPath.getArray());
|
|
2755
|
+
}
|
|
2756
|
+
};
|
|
2757
|
+
const listeners2 = [
|
|
2758
|
+
google.maps.event.addListener(mvcPath, "insert_at", handlePathChange),
|
|
2759
|
+
google.maps.event.addListener(mvcPath, "remove_at", handlePathChange),
|
|
2760
|
+
google.maps.event.addListener(mvcPath, "set_at", handlePathChange)
|
|
2761
|
+
];
|
|
2762
|
+
return () => {
|
|
2763
|
+
listeners2.forEach((listener) => listener.remove());
|
|
2764
|
+
};
|
|
2765
|
+
}, [
|
|
2766
|
+
polyline,
|
|
2767
|
+
onPathChanged,
|
|
2768
|
+
path,
|
|
2769
|
+
encodedPath,
|
|
2770
|
+
polylineOptions.editable,
|
|
2771
|
+
polylineOptions.draggable
|
|
2772
|
+
]);
|
|
2773
|
+
useEffect(() => {
|
|
2774
|
+
if (!polyline)
|
|
2775
|
+
return;
|
|
2776
|
+
setMapObjectOptions(polyline, polylineOptions);
|
|
2777
|
+
}, [polyline, polylineOptions]);
|
|
2778
|
+
useEffect(() => {
|
|
2779
|
+
if (!polyline || !path)
|
|
2780
|
+
return;
|
|
2781
|
+
const currentPath = polyline.getPath();
|
|
2782
|
+
if (!pathEquals(path, currentPath)) {
|
|
2783
|
+
isUpdatingRef.current = true;
|
|
2784
|
+
polyline.setPath(path);
|
|
2785
|
+
isUpdatingRef.current = false;
|
|
2786
|
+
}
|
|
2787
|
+
}, [polyline, path]);
|
|
2788
|
+
useEffect(() => {
|
|
2789
|
+
if (!polyline || !encodedPath || !geometryLibrary)
|
|
2790
|
+
return;
|
|
2791
|
+
isUpdatingRef.current = true;
|
|
2792
|
+
const decodedPath = geometryLibrary.encoding.decodePath(encodedPath);
|
|
2793
|
+
polyline.setPath(decodedPath);
|
|
2794
|
+
isUpdatingRef.current = false;
|
|
2795
|
+
}, [polyline, encodedPath, geometryLibrary]);
|
|
2796
|
+
return polyline;
|
|
2797
|
+
}
|
|
2798
|
+
const Polyline = forwardRef((props, ref) => {
|
|
2799
|
+
const polyline = usePolyline(props);
|
|
2800
|
+
useImperativeHandle(ref, () => polyline, [polyline]);
|
|
2801
|
+
return React__default.createElement(React__default.Fragment, null);
|
|
2802
|
+
});
|
|
2803
|
+
Polyline.displayName = "Polyline";
|
|
1291
2804
|
function useMarker(props) {
|
|
1292
2805
|
const [marker, setMarker] = useState(null);
|
|
1293
2806
|
const map = useMap();
|
|
1294
|
-
const {
|
|
1295
|
-
|
|
1296
|
-
onDrag,
|
|
1297
|
-
onDragStart,
|
|
1298
|
-
onDragEnd,
|
|
1299
|
-
onMouseOver,
|
|
1300
|
-
onMouseOut
|
|
1301
|
-
} = props, markerOptions = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1302
|
-
const {
|
|
1303
|
-
position,
|
|
1304
|
-
draggable
|
|
1305
|
-
} = markerOptions;
|
|
2807
|
+
const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut } = props, markerOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut"]);
|
|
2808
|
+
const { position, draggable } = markerOptions;
|
|
1306
2809
|
useEffect(() => {
|
|
1307
2810
|
if (!map) {
|
|
1308
|
-
if (map === void 0)
|
|
2811
|
+
if (map === void 0)
|
|
2812
|
+
console.error("<Marker> has to be inside a Map component.");
|
|
1309
2813
|
return;
|
|
1310
2814
|
}
|
|
1311
2815
|
const newMarker = new google.maps.Marker(markerOptions);
|
|
@@ -1317,35 +2821,107 @@ function useMarker(props) {
|
|
|
1317
2821
|
};
|
|
1318
2822
|
}, [map]);
|
|
1319
2823
|
useEffect(() => {
|
|
1320
|
-
if (!marker)
|
|
2824
|
+
if (!marker)
|
|
2825
|
+
return;
|
|
1321
2826
|
const m = marker;
|
|
1322
2827
|
const gme = google.maps.event;
|
|
1323
|
-
if (onClick)
|
|
1324
|
-
|
|
1325
|
-
if (
|
|
1326
|
-
|
|
1327
|
-
if (
|
|
1328
|
-
|
|
2828
|
+
if (onClick)
|
|
2829
|
+
gme.addListener(m, "click", onClick);
|
|
2830
|
+
if (onDrag)
|
|
2831
|
+
gme.addListener(m, "drag", onDrag);
|
|
2832
|
+
if (onDragStart)
|
|
2833
|
+
gme.addListener(m, "dragstart", onDragStart);
|
|
2834
|
+
if (onDragEnd)
|
|
2835
|
+
gme.addListener(m, "dragend", onDragEnd);
|
|
2836
|
+
if (onMouseOver)
|
|
2837
|
+
gme.addListener(m, "mouseover", onMouseOver);
|
|
2838
|
+
if (onMouseOut)
|
|
2839
|
+
gme.addListener(m, "mouseout", onMouseOut);
|
|
1329
2840
|
marker.setDraggable(Boolean(draggable));
|
|
1330
2841
|
return () => {
|
|
1331
2842
|
gme.clearInstanceListeners(m);
|
|
1332
2843
|
};
|
|
1333
|
-
}, [
|
|
2844
|
+
}, [
|
|
2845
|
+
marker,
|
|
2846
|
+
draggable,
|
|
2847
|
+
onClick,
|
|
2848
|
+
onDrag,
|
|
2849
|
+
onDragStart,
|
|
2850
|
+
onDragEnd,
|
|
2851
|
+
onMouseOver,
|
|
2852
|
+
onMouseOut
|
|
2853
|
+
]);
|
|
1334
2854
|
useEffect(() => {
|
|
1335
|
-
if (!marker)
|
|
1336
|
-
|
|
2855
|
+
if (!marker)
|
|
2856
|
+
return;
|
|
2857
|
+
if (markerOptions)
|
|
2858
|
+
marker.setOptions(markerOptions);
|
|
1337
2859
|
}, [marker, markerOptions]);
|
|
1338
2860
|
useEffect(() => {
|
|
1339
|
-
if (draggable || !position || !marker)
|
|
2861
|
+
if (draggable || !position || !marker)
|
|
2862
|
+
return;
|
|
1340
2863
|
marker.setPosition(position);
|
|
1341
2864
|
}, [draggable, position, marker]);
|
|
1342
2865
|
return marker;
|
|
1343
2866
|
}
|
|
1344
|
-
forwardRef((props, ref) => {
|
|
2867
|
+
const Marker = forwardRef((props, ref) => {
|
|
1345
2868
|
const marker = useMarker(props);
|
|
1346
2869
|
useImperativeHandle(ref, () => marker, [marker]);
|
|
1347
|
-
return
|
|
2870
|
+
return React__default.createElement(React__default.Fragment, null);
|
|
2871
|
+
});
|
|
2872
|
+
Marker.displayName = "Marker";
|
|
2873
|
+
function useRectangle(props) {
|
|
2874
|
+
var _a, _b, _c;
|
|
2875
|
+
const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onBoundsChanged, bounds, defaultBounds } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onBoundsChanged", "bounds", "defaultBounds"]);
|
|
2876
|
+
const [rectangle, setRectangle] = useState(null);
|
|
2877
|
+
const map = useMap();
|
|
2878
|
+
const rectangleOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onBoundsChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onBoundsChanged) }), deepEqual);
|
|
2879
|
+
useEffect(() => {
|
|
2880
|
+
if (!map) {
|
|
2881
|
+
if (map === void 0)
|
|
2882
|
+
console.error("<Rectangle> has to be inside a Map component.");
|
|
2883
|
+
return;
|
|
2884
|
+
}
|
|
2885
|
+
const newRectangle = new google.maps.Rectangle(Object.assign(Object.assign({}, rectangleOptions), { bounds: bounds !== null && bounds !== void 0 ? bounds : defaultBounds }));
|
|
2886
|
+
setMapObjectOptions(newRectangle, rectangleOptions, { alreadyApplied: true });
|
|
2887
|
+
newRectangle.setMap(map);
|
|
2888
|
+
setRectangle(newRectangle);
|
|
2889
|
+
return () => {
|
|
2890
|
+
newRectangle.setMap(null);
|
|
2891
|
+
setRectangle(null);
|
|
2892
|
+
};
|
|
2893
|
+
}, [map]);
|
|
2894
|
+
useMapsEventListener(rectangle, "click", onClick);
|
|
2895
|
+
useMapsEventListener(rectangle, "drag", onDrag);
|
|
2896
|
+
useMapsEventListener(rectangle, "dragstart", onDragStart);
|
|
2897
|
+
useMapsEventListener(rectangle, "dragend", onDragEnd);
|
|
2898
|
+
useMapsEventListener(rectangle, "mouseover", onMouseOver);
|
|
2899
|
+
useMapsEventListener(rectangle, "mouseout", onMouseOut);
|
|
2900
|
+
useMapsEventListener(rectangle, "bounds_changed", onBoundsChanged ? () => {
|
|
2901
|
+
onBoundsChanged(rectangle === null || rectangle === void 0 ? void 0 : rectangle.getBounds());
|
|
2902
|
+
} : null);
|
|
2903
|
+
useEffect(() => {
|
|
2904
|
+
if (!rectangle)
|
|
2905
|
+
return;
|
|
2906
|
+
setMapObjectOptions(rectangle, rectangleOptions);
|
|
2907
|
+
}, [rectangle, rectangleOptions]);
|
|
2908
|
+
useEffect(() => {
|
|
2909
|
+
if (!rectangle || !bounds)
|
|
2910
|
+
return;
|
|
2911
|
+
if (!boundsEquals(bounds, rectangle.getBounds())) {
|
|
2912
|
+
rectangle.setBounds(bounds);
|
|
2913
|
+
}
|
|
2914
|
+
}, [rectangle, bounds]);
|
|
2915
|
+
return rectangle;
|
|
2916
|
+
}
|
|
2917
|
+
const Rectangle = forwardRef((props, ref) => {
|
|
2918
|
+
const rectangle = useRectangle(props);
|
|
2919
|
+
useImperativeHandle(ref, () => rectangle, [
|
|
2920
|
+
rectangle
|
|
2921
|
+
]);
|
|
2922
|
+
return React__default.createElement(React__default.Fragment, null);
|
|
1348
2923
|
});
|
|
2924
|
+
Rectangle.displayName = "Rectangle";
|
|
1349
2925
|
const title = "title__jE00O";
|
|
1350
2926
|
const description = "description__bjRoW";
|
|
1351
2927
|
const link = "link__AM1ap";
|
|
@@ -1479,7 +3055,7 @@ const GoogleMapMarker = ({
|
|
|
1479
3055
|
InfoWindow,
|
|
1480
3056
|
{
|
|
1481
3057
|
position,
|
|
1482
|
-
pixelOffset:
|
|
3058
|
+
pixelOffset: INFO_WINDOW_PIXEL_OFFSET,
|
|
1483
3059
|
shouldFocus: false,
|
|
1484
3060
|
maxWidth: 300,
|
|
1485
3061
|
minWidth: 228,
|
|
@@ -1491,7 +3067,7 @@ const GoogleMapMarker = ({
|
|
|
1491
3067
|
)
|
|
1492
3068
|
] });
|
|
1493
3069
|
};
|
|
1494
|
-
const GoogleMapMarker$1 = React.memo(GoogleMapMarker
|
|
3070
|
+
const GoogleMapMarker$1 = React.memo(GoogleMapMarker);
|
|
1495
3071
|
const createSdkMethods = (mapRef, updateZoom, updateCenter) => {
|
|
1496
3072
|
return {
|
|
1497
3073
|
setMapCenter: (longitude, latitude) => {
|
|
@@ -1613,7 +3189,6 @@ const GoogleMapReactInner = forwardRef((props, forwardedRef) => {
|
|
|
1613
3189
|
const {
|
|
1614
3190
|
id,
|
|
1615
3191
|
isMobile,
|
|
1616
|
-
disableInfoWindow,
|
|
1617
3192
|
mapData,
|
|
1618
3193
|
translations,
|
|
1619
3194
|
onUpdateCenter,
|
|
@@ -1744,7 +3319,7 @@ const GoogleMapReactInner = forwardRef((props, forwardedRef) => {
|
|
|
1744
3319
|
]
|
|
1745
3320
|
);
|
|
1746
3321
|
return /* @__PURE__ */ jsx(
|
|
1747
|
-
Map,
|
|
3322
|
+
Map$1,
|
|
1748
3323
|
{
|
|
1749
3324
|
onCenterChanged: (e) => handleCenterChanged(e.detail.center),
|
|
1750
3325
|
onZoomChanged: (e) => handleZoomChange(e.detail.zoom),
|
|
@@ -1761,7 +3336,7 @@ const GoogleMapReactInner = forwardRef((props, forwardedRef) => {
|
|
|
1761
3336
|
{
|
|
1762
3337
|
index,
|
|
1763
3338
|
location,
|
|
1764
|
-
infoWindowOpen:
|
|
3339
|
+
infoWindowOpen: openInfoWindowIndex === index && hasMarkerInfoWindowFields(location, mapData),
|
|
1765
3340
|
onMarkerClick: handleMarkerClicked,
|
|
1766
3341
|
onInfoWindowClose: closeInfoWindow,
|
|
1767
3342
|
showDirectionLink: mapData.showDirectionsLink,
|
|
@@ -1925,7 +3500,6 @@ const useGoogleMapProps = (props) => {
|
|
|
1925
3500
|
onMouseLeave: props.onMouseOut,
|
|
1926
3501
|
isConsentPolicyActive: cookieConsent.isConsentPolicyActive,
|
|
1927
3502
|
isMobile: cookieConsent.isMobile,
|
|
1928
|
-
disableInfoWindow: props.disableInfoWindow,
|
|
1929
3503
|
consentPolicy: cookieConsent.consentPolicy,
|
|
1930
3504
|
openSettingModal: cookieConsent.openSettingModal,
|
|
1931
3505
|
hasRequiredConsent: cookieConsent.hasRequiredConsent,
|
|
@@ -1945,7 +3519,6 @@ const useGoogleMapProps = (props) => {
|
|
|
1945
3519
|
cookieConsent.componentConsentPolicy,
|
|
1946
3520
|
cookieConsent.translations,
|
|
1947
3521
|
cookieConsent.isMobile,
|
|
1948
|
-
props.disableInfoWindow,
|
|
1949
3522
|
cookieConsent.openSettingModal
|
|
1950
3523
|
]);
|
|
1951
3524
|
return { componentProps, mapData };
|