Angular2 - Wie richte ich eine google.maps.OverlayView ein? (JS-Prototyp in Typescript übersetzen)

Ich möchte eine Google Map-Komponente erstellen, die so funktioniert:https: //jsfiddle.net/gvvy5vxz/2

Es basiert auf diesem:https: //developers.google.com/maps/documentation/javascript/examples/overlay-simpl

Ich bin neu in der Typoskription und bin mit der Implementierung des Prototyps beschäftigt, insbesondere mit diesem JS-Snippet:

USGSOverlay.prototype = new google.maps.OverlayView();

USGSOverlay(bounds, image, map) {

    // Initialize all properties.
    this.bounds_ = bounds;
    this.image_ = image;
    this.map_ = map;

    // Define a property to hold the image's div. We'll
    // actually create this div upon receipt of the onAdd()
    // method so we'll leave it null for now.
    this.div_ = null;

    // Explicitly call setMap on this overlay.
    this.setMap(map);
  }

Ich habe keine Ahnung, wie man das maschinenschriftlich übersetzt und wie man die Dinge richtig deklariert.

Ich denke, ich sollte eine Klasse USGSOverlay erstellen, die google.maps.OverlayView erweitert, aber es funktioniert nicht.

class USGSOverlay extends google.maps.OverlayView{

  bounds_;
  image_;
  map_;
  div_;

  constructor(bounds, image, map){
    // Initialize all properties.
    this.bounds_ = bounds;
    this.image_ = image;
    this.map_ = map;

    // Define a property to hold the image's div. We'll
    // actually create this div upon receipt of the onAdd()
    // method so we'll leave it null for now.
    this.div_ = null;

    // Explicitly call setMap on this overlay.
    this.setMap(map);
  }
}

Dies ist meine funktionierende Basiskomponente. Es erstellt eine einfache Map in #map:

import { Component } from '@angular/core';
declare const google: any;
/*
/*  Component Map
*/
@Component({
  selector: 'map',
  template: `
    <div id="map"></div>
  `,
  styles: [
    `#map{ width:100%; height:100%; position: absolute; width:100%; height:100%; top:0; left:0;}`
  ],
})
export class MapComponent {

  ngOnInit(){
    google.maps.event.addDomListener(window, 'load', this.initMap);
  }

  initMap() {

    const map = new google.maps.Map(document.getElementById('map'), {
      zoom: 11,
      center: {lat: 62.323907, lng: -150.109291},
      mapTypeId: google.maps.MapTypeId.SATELLITE
    });

    const bounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(62.281819, -150.287132),
        new google.maps.LatLng(62.400471, -150.005608));
  }
}

Antworten auf die Frage(8)

Ihre Antwort auf die Frage