Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. // Instructions to every other class
  2. // on how they can be an argument to 'addMarker'
  3. export interface Mappable {
  4. location: {
  5. lat: number;
  6. lng: number;
  7. };
  8. markerContent(): string;
  9. color: string;
  10. }
  11.  
  12. export class CustomMap {
  13. private readonly googleMap: google.maps.Map;
  14.  
  15. // divId it the html element in which we put the map
  16. constructor(divId: string) {
  17. this.googleMap = new google.maps.Map(document.getElementById(divId), {
  18. zoom: 3,
  19. center: {
  20. lat: 0,
  21. lng: 0
  22. }
  23. });
  24. }
  25.  
  26. addMarker(mappable: Mappable): void {
  27. const marker = new google.maps.Marker({
  28. map: this.googleMap,
  29. position: {
  30. lat: mappable.location.lat,
  31. lng: mappable.location.lng
  32. }
  33. });
  34.  
  35. marker.addListener('click', () => {
  36. const infoWindow = new google.maps.InfoWindow({
  37. content: mappable.markerContent()
  38. });
  39.  
  40. infoWindow.open(this.googleMap, marker);
  41. });
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement