Skip to content

Instantly share code, notes, and snippets.

@jlescalonap
Last active October 15, 2023 13:42
Show Gist options
  • Save jlescalonap/a4a29f30e0d01943952755998d89567d to your computer and use it in GitHub Desktop.
Save jlescalonap/a4a29f30e0d01943952755998d89567d to your computer and use it in GitHub Desktop.
Typescript class example
export interface mappable {
location: {
lat: number;
lng: number;
};
markerContent(): string;
color: string;
}
export class CustomMap {
private googleMap: google.maps.Map;
constructor(divId: string) {
this.googleMap = new google.maps.Map(
document.getElementById(divId) as HTMLElement,
{
zoom: 1,
center: {
lat: 0,
lng: 0,
},
}
);
}
addMarker(mappable: mappable): void {
const marker = new google.maps.Marker({
map: this.googleMap,
position: {
lat: mappable.location.lat,
lng: mappable.location.lng,
},
});
marker.addListener('click', () => {
const infoWindow = new google.maps.InfoWindow({
content: mappable.markerContent(),
});
infoWindow.open(this.googleMap, marker)
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment