Skip to content

Commit

Permalink
refactor(utils): add type guard to isAdvancedMarker (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored May 23, 2023
1 parent 3c7e86e commit 4c041a3
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/marker-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,26 @@
*/

export class MarkerUtils {
public static isAdvancedMarker(marker: Marker): boolean {
if (
public static isAdvancedMarker(
marker: Marker
): marker is google.maps.marker.AdvancedMarkerElement {
return (
google.maps.marker &&
marker instanceof google.maps.marker.AdvancedMarkerElement
) {
return true;
}
return false;
);
}

public static setMap(marker: Marker, map: google.maps.Map | null) {
if (this.isAdvancedMarker(marker)) {
(marker as google.maps.marker.AdvancedMarkerElement).map = map;
return;
marker.map = map;
} else {
(marker as google.maps.Marker).setMap(map);
}
(marker as google.maps.Marker).setMap(map);
}

public static getPosition(marker: Marker): google.maps.LatLng {
// SuperClusterAlgorithm.calculate expects a LatLng instance so we fake it for Adv Markers
if (this.isAdvancedMarker(marker)) {
marker = marker as google.maps.marker.AdvancedMarkerElement;
if (marker.position) {
if (marker.position instanceof google.maps.LatLng) {
return marker.position;
Expand Down

0 comments on commit 4c041a3

Please sign in to comment.