Skip to content

Commit

Permalink
feat: throw error when maps-api isn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulthink committed Nov 18, 2022
1 parent 8e52d45 commit 6d95f0a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ export class Marker<TUserData extends object = Record<any, any>> {
constructor(options: MarkerOptions<TUserData> = {}, data?: TUserData) {
const {map, ...attributes} = options;

if (!google?.maps) {
console.error(
`Google Maps API couldn't be found. Please make sure ` +
`to wait for the Google Maps API to load before creating markers.`
);
throw new Error('Google Maps API not found.');
}

if (google.maps && !google.maps.marker) {
console.error(
`Google Maps API was loaded without the required marker-library. ` +
`To load it, add the '&libraries=marker' parameter to the API url.`
);
throw new Error('Google Maps Marker Library not found.');
}

this.data_ = data || null;
this.pinView_ = new google.maps.marker.PinView();
this.markerView_ = new google.maps.marker.AdvancedMarkerView();
Expand Down

0 comments on commit 6d95f0a

Please sign in to comment.