Last active
October 15, 2023 13:42
-
-
Save jlescalonap/a4a29f30e0d01943952755998d89567d to your computer and use it in GitHub Desktop.
Typescript class example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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