@vis.gl/react-google-maps
Advanced tools
@@ -9,8 +9,10 @@ /// <reference types="google.maps" /> | ||
} | ||
/** | ||
* API Provider context | ||
*/ | ||
type ImportLibraryFunction = typeof google.maps.importLibrary; | ||
type GoogleMapsLibrary = Awaited<ReturnType<ImportLibraryFunction>>; | ||
type LoadedLibraries = { | ||
[name: string]: GoogleMapsLibrary; | ||
}; | ||
export interface APIProviderContextValue { | ||
status: APILoadingStatus; | ||
loadedLibraries: Set<string>; | ||
loadedLibraries: LoadedLibraries; | ||
importLibrary: typeof google.maps.importLibrary; | ||
@@ -66,1 +68,2 @@ mapInstances: Record<string, google.maps.Map>; | ||
export declare const APIProvider: (props: PropsWithChildren<APIProviderProps>) => ReactElement | null; | ||
export {}; |
@@ -7,13 +7,9 @@ export * from './components/advanced-marker'; | ||
export * from './components/pin'; | ||
export * from './hooks/api-loading-status'; | ||
export * from './hooks/autocomplete-service'; | ||
export * from './hooks/use-api-loading-status'; | ||
export * from './hooks/use-api-is-loaded'; | ||
export * from './hooks/use-maps-library'; | ||
export * from './hooks/use-map'; | ||
export * from './hooks/autocomplete'; | ||
export * from './hooks/directions-service'; | ||
export * from './hooks/distance-matrix-service'; | ||
export * from './hooks/elevation-service'; | ||
export * from './hooks/geocoding-service'; | ||
export * from './hooks/map-instance'; | ||
export * from './hooks/max-zoom-service'; | ||
export * from './hooks/places-service'; | ||
export * from './hooks/street-view-panorama'; | ||
export { limitTiltRange } from './libraries/limit-tilt-range'; |
@@ -36,33 +36,2 @@ (function (global, factory) { | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (it) return (it = it.call(o)).next.bind(it); | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _toPrimitive(input, hint) { | ||
@@ -83,6 +52,6 @@ if (typeof input !== "object" || input === null) return input; | ||
var _iteratorSymbol = typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator"; | ||
function _settle(pact, state, value) { | ||
var _iteratorSymbol$1 = typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator"; | ||
function _settle$1(pact, state, value) { | ||
if (!pact.s) { | ||
if (value instanceof _Pact) { | ||
if (value instanceof _Pact$1) { | ||
if (value.s) { | ||
@@ -94,3 +63,3 @@ if (state & 1) { | ||
} else { | ||
value.o = _settle.bind(null, pact, state); | ||
value.o = _settle$1.bind(null, pact, state); | ||
return; | ||
@@ -100,3 +69,3 @@ } | ||
if (value && value.then) { | ||
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2)); | ||
value.then(_settle$1.bind(null, pact, state), _settle$1.bind(null, pact, 2)); | ||
return; | ||
@@ -112,3 +81,3 @@ } | ||
} | ||
var _Pact = /*#__PURE__*/function () { | ||
var _Pact$1 = /*#__PURE__*/function () { | ||
function _Pact() {} | ||
@@ -122,5 +91,5 @@ _Pact.prototype.then = function (onFulfilled, onRejected) { | ||
try { | ||
_settle(result, 1, callback(this.v)); | ||
_settle$1(result, 1, callback(this.v)); | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
_settle$1(result, 2, e); | ||
} | ||
@@ -136,10 +105,10 @@ return result; | ||
if (_this.s & 1) { | ||
_settle(result, 1, onFulfilled ? onFulfilled(value) : value); | ||
_settle$1(result, 1, onFulfilled ? onFulfilled(value) : value); | ||
} else if (onRejected) { | ||
_settle(result, 1, onRejected(value)); | ||
_settle$1(result, 1, onRejected(value)); | ||
} else { | ||
_settle(result, 2, value); | ||
_settle$1(result, 2, value); | ||
} | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
_settle$1(result, 2, e); | ||
} | ||
@@ -151,6 +120,6 @@ }; | ||
}(); | ||
function _isSettledPact(thenable) { | ||
return thenable instanceof _Pact && thenable.s & 1; | ||
function _isSettledPact$1(thenable) { | ||
return thenable instanceof _Pact$1 && thenable.s & 1; | ||
} | ||
function _forTo(array, body, check) { | ||
function _forTo$1(array, body, check) { | ||
var i = -1, | ||
@@ -164,6 +133,6 @@ pact, | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
if (_isSettledPact$1(result)) { | ||
result = result.v; | ||
} else { | ||
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2))); | ||
result.then(_cycle, reject || (reject = _settle$1.bind(null, pact = new _Pact$1(), 2))); | ||
return; | ||
@@ -174,3 +143,3 @@ } | ||
if (pact) { | ||
_settle(pact, 1, result); | ||
_settle$1(pact, 1, result); | ||
} else { | ||
@@ -180,3 +149,3 @@ pact = result; | ||
} catch (e) { | ||
_settle(pact || (pact = new _Pact()), 2, e); | ||
_settle$1(pact || (pact = new _Pact$1()), 2, e); | ||
} | ||
@@ -194,5 +163,5 @@ } | ||
*/ | ||
function _forOf(target, body, check) { | ||
if (typeof target[_iteratorSymbol] === "function") { | ||
var iterator = target[_iteratorSymbol](), | ||
function _forOf$1(target, body, check) { | ||
if (typeof target[_iteratorSymbol$1] === "function") { | ||
var iterator = target[_iteratorSymbol$1](), | ||
step, | ||
@@ -206,6 +175,6 @@ pact, | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
if (_isSettledPact$1(result)) { | ||
result = result.v; | ||
} else { | ||
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2))); | ||
result.then(_cycle, reject || (reject = _settle$1.bind(null, pact = new _Pact$1(), 2))); | ||
return; | ||
@@ -216,3 +185,3 @@ } | ||
if (pact) { | ||
_settle(pact, 1, result); | ||
_settle$1(pact, 1, result); | ||
} else { | ||
@@ -222,3 +191,3 @@ pact = result; | ||
} catch (e) { | ||
_settle(pact || (pact = new _Pact()), 2, e); | ||
_settle$1(pact || (pact = new _Pact$1()), 2, e); | ||
} | ||
@@ -254,3 +223,3 @@ } | ||
} | ||
return _forTo(values, function (i) { | ||
return _forTo$1(values, function (i) { | ||
return body(values[i]); | ||
@@ -284,3 +253,3 @@ }, check); | ||
} | ||
var _temp = _forOf(['maps'].concat(libraries), function (lib) { | ||
var _temp = _forOf$1(['maps'].concat(libraries), function (lib) { | ||
return Promise.resolve(google.maps.importLibrary(lib)).then(function () {}); | ||
@@ -342,4 +311,158 @@ }); | ||
var _iteratorSymbol = typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator"; | ||
function _settle(pact, state, value) { | ||
if (!pact.s) { | ||
if (value instanceof _Pact) { | ||
if (value.s) { | ||
if (state & 1) { | ||
state = value.s; | ||
} | ||
value = value.v; | ||
} else { | ||
value.o = _settle.bind(null, pact, state); | ||
return; | ||
} | ||
} | ||
if (value && value.then) { | ||
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2)); | ||
return; | ||
} | ||
pact.s = state; | ||
pact.v = value; | ||
var observer = pact.o; | ||
if (observer) { | ||
observer(pact); | ||
} | ||
} | ||
} | ||
var _Pact = /*#__PURE__*/function () { | ||
function _Pact() {} | ||
_Pact.prototype.then = function (onFulfilled, onRejected) { | ||
var result = new _Pact(); | ||
var state = this.s; | ||
if (state) { | ||
var callback = state & 1 ? onFulfilled : onRejected; | ||
if (callback) { | ||
try { | ||
_settle(result, 1, callback(this.v)); | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
return result; | ||
} else { | ||
return this; | ||
} | ||
} | ||
this.o = function (_this) { | ||
try { | ||
var value = _this.v; | ||
if (_this.s & 1) { | ||
_settle(result, 1, onFulfilled ? onFulfilled(value) : value); | ||
} else if (onRejected) { | ||
_settle(result, 1, onRejected(value)); | ||
} else { | ||
_settle(result, 2, value); | ||
} | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
}; | ||
return result; | ||
}; | ||
return _Pact; | ||
}(); | ||
function _isSettledPact(thenable) { | ||
return thenable instanceof _Pact && thenable.s & 1; | ||
} | ||
function _forTo(array, body, check) { | ||
var i = -1, | ||
pact, | ||
reject; | ||
function _cycle(result) { | ||
try { | ||
while (++i < array.length && (!check || !check())) { | ||
result = body(i); | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
result = result.v; | ||
} else { | ||
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2))); | ||
return; | ||
} | ||
} | ||
} | ||
if (pact) { | ||
_settle(pact, 1, result); | ||
} else { | ||
pact = result; | ||
} | ||
} catch (e) { | ||
_settle(pact || (pact = new _Pact()), 2, e); | ||
} | ||
} | ||
_cycle(); | ||
return pact; | ||
} | ||
var _excluded$3 = ["onLoad", "apiKey", "libraries"], | ||
_excluded2$1 = ["children"]; | ||
function _forOf(target, body, check) { | ||
if (typeof target[_iteratorSymbol] === "function") { | ||
var iterator = target[_iteratorSymbol](), | ||
step, | ||
pact, | ||
reject; | ||
function _cycle(result) { | ||
try { | ||
while (!(step = iterator.next()).done && (!check || !check())) { | ||
result = body(step.value); | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
result = result.v; | ||
} else { | ||
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2))); | ||
return; | ||
} | ||
} | ||
} | ||
if (pact) { | ||
_settle(pact, 1, result); | ||
} else { | ||
pact = result; | ||
} | ||
} catch (e) { | ||
_settle(pact || (pact = new _Pact()), 2, e); | ||
} | ||
} | ||
_cycle(); | ||
if (iterator.return) { | ||
var _fixup = function (value) { | ||
try { | ||
if (!step.done) { | ||
iterator.return(); | ||
} | ||
} catch (e) {} | ||
return value; | ||
}; | ||
if (pact && pact.then) { | ||
return pact.then(_fixup, function (e) { | ||
throw _fixup(e); | ||
}); | ||
} | ||
_fixup(); | ||
} | ||
return pact; | ||
} | ||
// No support for Symbol.iterator | ||
if (!("length" in target)) { | ||
throw new TypeError("Object is not iterable"); | ||
} | ||
// Handle live collections properly | ||
var values = []; | ||
for (var i = 0; i < target.length; i++) { | ||
values.push(target[i]); | ||
} | ||
return _forTo(values, function (i) { | ||
return body(values[i]); | ||
}, check); | ||
} | ||
function _catch(body, recover) { | ||
@@ -418,5 +541,8 @@ try { | ||
setStatus = _useState2[1]; | ||
var _useState3 = React.useState(new Set()), | ||
loadedLibraries = _useState3[0], | ||
setLoadedLibraries = _useState3[1]; | ||
var _useReducer = React.useReducer(function (loadedLibraries, action) { | ||
var _extends3; | ||
return _extends({}, loadedLibraries, (_extends3 = {}, _extends3[action.name] = action.value, _extends3)); | ||
}, {}), | ||
loadedLibraries = _useReducer[0], | ||
addLoadedLibrary = _useReducer[1]; | ||
var librariesString = React.useMemo(function () { | ||
@@ -428,2 +554,22 @@ return libraries == null ? void 0 : libraries.join(','); | ||
}, [otherApiParams]); | ||
var importLibrary = React.useCallback(function (name) { | ||
try { | ||
var _google; | ||
if (loadedLibraries[name]) { | ||
return Promise.resolve(loadedLibraries[name]); | ||
} | ||
if (!((_google = google) != null && (_google = _google.maps) != null && _google.importLibrary)) { | ||
throw new Error('[api-provider-internal] importLibrary was called before ' + 'google.maps.importLibrary was defined.'); | ||
} | ||
return Promise.resolve(window.google.maps.importLibrary(name)).then(function (res) { | ||
addLoadedLibrary({ | ||
name: name, | ||
value: res | ||
}); | ||
return res; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}, []); | ||
React.useEffect(function () { | ||
@@ -433,3 +579,3 @@ setStatus(LOADING); | ||
try { | ||
var _temp = _catch(function () { | ||
var _temp3 = _catch(function () { | ||
return Promise.resolve(GoogleMapsApiLoader.load(_extends({ | ||
@@ -439,7 +585,12 @@ key: apiKey, | ||
}, otherApiParams))).then(function () { | ||
function _temp2() { | ||
if (onLoad) { | ||
onLoad(); | ||
} | ||
} | ||
setStatus(LOADED); | ||
setLoadedLibraries(new Set(['maps'].concat(libraries))); | ||
if (onLoad) { | ||
onLoad(); | ||
} | ||
var _temp = _forOf(['core', 'maps'].concat(libraries), function (name) { | ||
return Promise.resolve(importLibrary(name)).then(function () {}); | ||
}); | ||
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp); | ||
}); | ||
@@ -450,3 +601,3 @@ }, function (error) { | ||
}); | ||
return _temp && _temp.then ? _temp.then(function () {}) : void 0; | ||
return _temp3 && _temp3.then ? _temp3.then(function () {}) : void 0; | ||
} catch (e) { | ||
@@ -459,16 +610,2 @@ Promise.reject(e); | ||
[apiKey, librariesString, serializedParams]); | ||
var importLibrary = React.useCallback(function (name) { | ||
try { | ||
var _google; | ||
if (!((_google = google) != null && (_google = _google.maps) != null && _google.importLibrary)) { | ||
throw new Error('importLibrary was called before google.maps.importLibrary was defined'); | ||
} | ||
return Promise.resolve(window.google.maps.importLibrary(name)).then(function (res) { | ||
setLoadedLibraries(new Set([].concat(loadedLibraries, [name]))); | ||
return res; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}, []); | ||
return { | ||
@@ -508,2 +645,7 @@ status: status, | ||
function useApiLoadingStatus() { | ||
var _useContext; | ||
return ((_useContext = React.useContext(APIProviderContext)) == null ? void 0 : _useContext.status) || exports.APILoadingStatus.NOT_LOADED; | ||
} | ||
/** | ||
@@ -516,23 +658,2 @@ * Hook to check if the Google Maps API is loaded | ||
} | ||
function useApiLoadingStatus() { | ||
var _useContext; | ||
return ((_useContext = React.useContext(APIProviderContext)) == null ? void 0 : _useContext.status) || exports.APILoadingStatus.NOT_LOADED; | ||
} | ||
function useMapsLibrary() { | ||
var names = [].slice.call(arguments); | ||
var apiIsLoaded = useApiIsLoaded(); | ||
var ctx = React.useContext(APIProviderContext); | ||
React.useEffect(function () { | ||
if (!apiIsLoaded || !ctx) return; | ||
// trigger loading the libraries via our proxy-method, which will update the | ||
// loadedLibraries list in the context, triggering a re-render. | ||
for (var _iterator = _createForOfIteratorHelperLoose(names), _step; !(_step = _iterator()).done;) { | ||
var name = _step.value; | ||
if (!ctx.loadedLibraries.has(name)) void ctx.importLibrary(name); | ||
} | ||
}, [apiIsLoaded, ctx == null ? void 0 : ctx.importLibrary]); | ||
return names.every(function (name) { | ||
return (ctx == null ? void 0 : ctx.loadedLibraries.has(name)) || false; | ||
}); | ||
} | ||
@@ -721,2 +842,15 @@ var shownMessages = new Set(); | ||
function useMapsLibrary(name) { | ||
var apiIsLoaded = useApiIsLoaded(); | ||
var ctx = React.useContext(APIProviderContext); | ||
React.useEffect(function () { | ||
if (!apiIsLoaded || !ctx) return; | ||
// Trigger loading the libraries via our proxy-method. | ||
// The returned promise is ignored, since importLibrary will update loadedLibraries | ||
// list in the context, triggering a re-render. | ||
void ctx.importLibrary(name); | ||
}, [apiIsLoaded, ctx == null ? void 0 : ctx.importLibrary]); | ||
return (ctx == null ? void 0 : ctx.loadedLibraries[name]) || null; | ||
} | ||
/* eslint-disable complexity */ | ||
@@ -964,16 +1098,21 @@ var AdvancedMarkerContext = React__default["default"].createContext(null); | ||
/** | ||
* Hook to get Google Maps Autocomplete Service instance | ||
* Retrieves a map-instance from the context. This is either an instance | ||
* identified by id or the parent map instance if no id is specified. | ||
* Returns null if neither can be found. | ||
*/ | ||
var useAutocompleteService = function useAutocompleteService() { | ||
var googleMapsAPIISLoaded = useApiIsLoaded(); | ||
return React.useMemo(function () { | ||
if (!googleMapsAPIISLoaded) { | ||
return null; | ||
} | ||
if (!google.maps.places) { | ||
console.error('Google Maps Places library is missing. ' + 'Please add the places library to the props of the <ApiProvider> ' + 'component.'); | ||
return null; | ||
} | ||
return new google.maps.places.AutocompleteService(); | ||
}, [googleMapsAPIISLoaded]); | ||
var useMap = function useMap(id) { | ||
if (id === void 0) { | ||
id = null; | ||
} | ||
var _ref = React.useContext(APIProviderContext) || {}, | ||
_ref$mapInstances = _ref.mapInstances, | ||
mapInstances = _ref$mapInstances === void 0 ? {} : _ref$mapInstances; | ||
var _ref2 = React.useContext(GoogleMapsContext) || {}, | ||
map = _ref2.map; | ||
// if an if is specified, the corresponding map or null is returned | ||
if (id !== null) return mapInstances[id] || null; | ||
// otherwise, return the closest ancestor | ||
if (map) return map; | ||
// finally, return the default map instance | ||
return mapInstances['default'] || null; | ||
}; | ||
@@ -1022,24 +1161,2 @@ | ||
/** | ||
* Retrieves a map-instance from the context. This is either an instance | ||
* identified by id or the parent map instance if no id is specified. | ||
* Returns null if neither can be found. | ||
*/ | ||
var useMap = function useMap(id) { | ||
if (id === void 0) { | ||
id = null; | ||
} | ||
var _ref = React.useContext(APIProviderContext) || {}, | ||
_ref$mapInstances = _ref.mapInstances, | ||
mapInstances = _ref$mapInstances === void 0 ? {} : _ref$mapInstances; | ||
var _ref2 = React.useContext(GoogleMapsContext) || {}, | ||
map = _ref2.map; | ||
// if an if is specified, the corresponding map or null is returned | ||
if (id !== null) return mapInstances[id] || null; | ||
// otherwise, return the closest ancestor | ||
if (map) return map; | ||
// finally, return the default map instance | ||
return mapInstances['default'] || null; | ||
}; | ||
/** | ||
* A typescript assertion function used in cases where typescript has to be | ||
@@ -1132,96 +1249,2 @@ * convinced that the object in question can not be null. | ||
/** | ||
* Hook to get Distance Matrix Service instance | ||
*/ | ||
var useDistanceMatrixService = function useDistanceMatrixService() { | ||
var isApiLoaded = useApiIsLoaded(); | ||
// Creates a Distance Matrix Service instance | ||
return React.useMemo(function () { | ||
if (!isApiLoaded) { | ||
return null; | ||
} | ||
if (!google.maps.DistanceMatrixService) { | ||
console.error('Google Maps Distance Matrix library is missing.'); | ||
return null; | ||
} | ||
return new google.maps.DistanceMatrixService(); | ||
}, [isApiLoaded]); | ||
}; | ||
/** | ||
* Hook to get Elevation Service instance | ||
*/ | ||
var useElevationService = function useElevationService() { | ||
var googleMapsAPIIsLoaded = useApiIsLoaded(); | ||
// Creates an Elevation Service instance | ||
return React.useMemo(function () { | ||
if (!googleMapsAPIIsLoaded) { | ||
return null; | ||
} | ||
return new google.maps.ElevationService(); | ||
}, [googleMapsAPIIsLoaded]); | ||
}; | ||
/** | ||
* Hook to get Google Maps Geocoder instance | ||
*/ | ||
var useGeocodingService = function useGeocodingService() { | ||
var googleMapsAPIIsLoaded = useApiIsLoaded(); | ||
return React.useMemo(function () { | ||
if (!googleMapsAPIIsLoaded) { | ||
return null; | ||
} | ||
return new google.maps.Geocoder(); | ||
}, [googleMapsAPIIsLoaded]); | ||
}; | ||
/** | ||
* Hook to get Max Zoom Service instance | ||
*/ | ||
var useMaxZoomService = function useMaxZoomService() { | ||
var googleMapsAPIIsLoaded = useApiIsLoaded(); | ||
// Creates a Max Zoom Service instance | ||
return React.useMemo(function () { | ||
if (!googleMapsAPIIsLoaded) { | ||
return null; | ||
} | ||
return new google.maps.MaxZoomService(); | ||
}, [googleMapsAPIIsLoaded]); | ||
}; | ||
/** | ||
* Hook to get Google Maps Places Service instance | ||
*/ | ||
var usePlacesService = function usePlacesService(props) { | ||
if (props === void 0) { | ||
props = {}; | ||
} | ||
var _props = props, | ||
mapId = _props.mapId, | ||
attributionContainer = _props.attributionContainer; | ||
var isApiLoaded = useApiIsLoaded(); | ||
var map = useMap(mapId); | ||
var _useState = React.useState(null), | ||
placesService = _useState[0], | ||
setPlacesService = _useState[1]; | ||
// Creates a Places Service instance | ||
React.useEffect(function () { | ||
if (!isApiLoaded) return; | ||
if (!google.maps.places) { | ||
console.error('Google Maps Places library is missing. ' + 'Please add the places library to the props of the <ApiProvider> ' + 'component.'); | ||
return; | ||
} | ||
// when attributionContainer isn't specified, we use the map | ||
if (props.attributionContainer === undefined) { | ||
// wait for map to be ready | ||
if (!map) return; | ||
setPlacesService(new google.maps.places.PlacesService(map)); | ||
} else { | ||
if (!attributionContainer) return; | ||
setPlacesService(new google.maps.places.PlacesService(attributionContainer)); | ||
} | ||
}, [isApiLoaded, map, attributionContainer]); | ||
return placesService; | ||
}; | ||
/* eslint-disable complexity */ | ||
@@ -1317,12 +1340,6 @@ /** | ||
exports.useAutocomplete = useAutocomplete; | ||
exports.useAutocompleteService = useAutocompleteService; | ||
exports.useDirectionsService = useDirectionsService; | ||
exports.useDistanceMatrixService = useDistanceMatrixService; | ||
exports.useElevationService = useElevationService; | ||
exports.useGeocodingService = useGeocodingService; | ||
exports.useMap = useMap; | ||
exports.useMapsLibrary = useMapsLibrary; | ||
exports.useMarkerRef = useMarkerRef; | ||
exports.useMaxZoomService = useMaxZoomService; | ||
exports.usePlacesService = usePlacesService; | ||
exports.useStreetViewPanorama = useStreetViewPanorama; | ||
@@ -1329,0 +1346,0 @@ |
{ | ||
"name": "@vis.gl/react-google-maps", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "React components and hooks for Google Maps.", | ||
@@ -25,3 +25,3 @@ "source": "src/index.ts", | ||
"test:linter": "eslint 'src/**/*.{ts,tsx}'", | ||
"test:tsc": "tsc --project tsconfig.json --noEmit", | ||
"test:tsc": "tsc --project tsconfig.test.json --noEmit", | ||
"test:prettier": "prettier --check ./src ./examples", | ||
@@ -28,0 +28,0 @@ "test:unit": "jest", |
import {useState, useRef, useEffect} from 'react'; | ||
import {useApiIsLoaded} from './api-loading-status'; | ||
import {useApiIsLoaded} from './use-api-is-loaded'; | ||
@@ -5,0 +5,0 @@ export interface AutocompleteProps { |
import {useMemo, useEffect, useCallback} from 'react'; | ||
import {useApiIsLoaded} from './api-loading-status'; | ||
import {useMap} from './map-instance'; | ||
import {useApiIsLoaded} from './use-api-is-loaded'; | ||
import {useMap} from './use-map'; | ||
import {assertNotNull} from '../libraries/assert-not-null'; | ||
@@ -6,0 +6,0 @@ |
/* eslint-disable complexity */ | ||
import {useEffect, useState} from 'react'; | ||
import {useApiIsLoaded} from './api-loading-status'; | ||
import {useMap} from './map-instance'; | ||
import {useApiIsLoaded} from './use-api-is-loaded'; | ||
import {useMap} from './use-map'; | ||
@@ -6,0 +6,0 @@ export interface StreetViewPanoramaProps { |
@@ -7,13 +7,10 @@ export * from './components/advanced-marker'; | ||
export * from './components/pin'; | ||
export * from './hooks/api-loading-status'; | ||
export * from './hooks/autocomplete-service'; | ||
export * from './hooks/use-api-loading-status'; | ||
export * from './hooks/use-api-is-loaded'; | ||
export * from './hooks/use-maps-library'; | ||
export * from './hooks/use-map'; | ||
export * from './hooks/autocomplete'; | ||
export * from './hooks/directions-service'; | ||
export * from './hooks/distance-matrix-service'; | ||
export * from './hooks/elevation-service'; | ||
export * from './hooks/geocoding-service'; | ||
export * from './hooks/map-instance'; | ||
export * from './hooks/max-zoom-service'; | ||
export * from './hooks/places-service'; | ||
export * from './hooks/street-view-panorama'; | ||
export {limitTiltRange} from './libraries/limit-tilt-range'; |
import type {GoogleMapsApiLoader as ActualLoader} from '../google-maps-api-loader'; | ||
// FIXME: this should no longer be needed with the next version of @googlemaps/jest-mocks | ||
import {importLibraryMock} from './lib/import-library-mock'; | ||
export class GoogleMapsApiLoader { | ||
static load: typeof ActualLoader.load = jest.fn(() => Promise.resolve()); | ||
static load: typeof ActualLoader.load = jest.fn(() => { | ||
google.maps.importLibrary = importLibraryMock; | ||
return Promise.resolve(); | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
330105
-6.09%64
-20%4686
-3.26%