Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Instructions to every other class
- // on how they can be an argument to 'addMarker'
- export interface Mappable {
- location: {
- lat: number;
- lng: number;
- };
- markerContent(): string;
- color: string;
- }
- export class CustomMap {
- private readonly googleMap: google.maps.Map;
- // divId it the html element in which we put the map
- constructor(divId: string) {
- this.googleMap = new google.maps.Map(document.getElementById(divId), {
- zoom: 3,
- 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);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement