text: "use strict";
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  var __metadata = (this && this.__metadata) || function (k, v) {
      if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var core_1 = require("@angular/core");
  var core_2 = require("@agm/core");
  var AgmOverlay = (function () {
      function AgmOverlay(_mapsWrapper, _markerManager) {
          this._mapsWrapper = _mapsWrapper;
          this._markerManager = _markerManager;
          this.visible = true;
          this.zIndex = 1;
          this.markerClick = new core_1.EventEmitter();
          this.openInfoWindow = true;
          this.infoWindow = new core_1.QueryList();
          this.draggable = false;
          this._observableSubscriptions = [];
      }
      AgmOverlay.prototype.ngAfterViewInit = function () {
          var _this = this;
          var iWins = this.template.nativeElement.getElementsByTagName('agm-info-window');
          for (var x = iWins.length - 1; x >= 0; --x) {
              iWins[x].parentNode.removeChild(iWins[x]);
          }
          this.load().then(function () {
              _this.onChanges = _this.onChangesOverride;
          });
      };
      AgmOverlay.prototype.ngAfterContentInit = function () {
          var _this = this;
          this.infoWindow.changes.subscribe(function () { return _this.handleInfoWindowUpdate(); });
      };
      AgmOverlay.prototype.ngOnChanges = function (changes) {
          this.onChanges(changes);
      };
      AgmOverlay.prototype.onChanges = function (changes) { };
      AgmOverlay.prototype.onChangesOverride = function (changes) {
          var _this = this;
          if (changes.latitude || changes.longitude || changes.zIndex) {
              this.overlayView.latitude = this.latitude;
              this.overlayView.longitude = this.longitude;
              this.overlayView.zIndex = this.zIndex;
              this.destroy().then(function () { return _this.load(); });
          }
      };
      AgmOverlay.prototype.ngOnDestroy = function () {
          this.destroy();
      };
      AgmOverlay.prototype.destroy = function () {
          this.destroyed = true;
          var promise = this._markerManager.deleteMarker(this.overlayView);
          if (this.overlayView) {
              if (this.overlayView.div) {
                  this.overlayView.remove();
              }
              this.overlayView.setMap(null);
          }
          this._observableSubscriptions.forEach(function (s) { return s.unsubscribe(); });
          delete this.overlayView;
          return promise;
      };
      AgmOverlay.prototype.handleInfoWindowUpdate = function () {
          var _this = this;
          if (this.infoWindow.length > 1) {
              throw new Error('Expected no more than one info window.');
          }
          this.infoWindow.forEach(function (iWin) {
              iWin.hostMarker = _this.overlayView;
          });
      };
      AgmOverlay.prototype.load = function () {
          var _this = this;
          return this._mapsWrapper.getNativeMap()
              .then(function (map) {
              var overlay = _this.getOverlay(map);
              _this._markerManager.addMarker(overlay);
              _this._addEventListeners();
              return _this._markerManager.getNativeMarker(overlay);
          })
              .then(function (nativeMarker) {
              var setMap = nativeMarker.setMap;
              if (nativeMarker['map']) {
                  _this.overlayView.setMap(nativeMarker['map']);
              }
              nativeMarker.setMap = function (map) {
                  setMap.call(nativeMarker, map);
                  if (_this.overlayView) {
                      _this.overlayView.setMap(map);
                  }
              };
          });
      };
      AgmOverlay.prototype.getOverlay = function (map) {
          var _this = this;
          this.overlayView = this.overlayView || new google.maps.OverlayView();
          this.overlayView.iconUrl = " ";
          this.overlayView.latitude = this.latitude;
          this.overlayView.longitude = this.longitude;
          this.overlayView.visible = false;
          if (this.bounds) {
              this.overlayView.bounds_ = new google.maps.LatLngBounds(new google.maps.LatLng(this.latitude + this.bounds.x.latitude, this.longitude + this.bounds.x.longitude), new google.maps.LatLng(this.latitude + this.bounds.y.latitude, this.longitude + this.bounds.y.longitude));
          }
          var elm = this.template.nativeElement.children[0];
          var restore = function (div) {
              _this.template.nativeElement.appendChild(div);
          };
          this.overlayView.remove = function () {
              if (!this.div)
                  return;
              this.div.parentNode.removeChild(this.div);
              restore(this.div);
              delete this.div;
          };
          this.overlayView.getDiv = function () {
              return this.div;
          };
          this.overlayView.draw = function () {
              if (!this.div) {
                  this.div = elm;
                  var panes = this.getPanes();
                  if (!panes || !panes.overlayImage)
                      return;
                  panes.overlayImage.appendChild(elm);
              }
              var latlng = new google.maps.LatLng(this.latitude, this.longitude);
              var proj = this.getProjection();
              if (!proj)
                  return;
              var point = proj.fromLatLngToDivPixel(latlng);
              if (point) {
                  elm.style.left = (point.x - 10) + 'px';
                  elm.style.top = (point.y - 20) + 'px';
              }
              if (this.bounds_) {
                  var proj_1 = this.getProjection();
                  var sw = proj_1.fromLatLngToDivPixel(this.bounds_.getSouthWest());
                  var ne = proj_1.fromLatLngToDivPixel(this.bounds_.getNorthEast());
                  this.div.style.left = sw.x + 'px';
                  this.div.style.top = ne.y + 'px';
                  this.div.children[0].style.width = ne.x - sw.x + 'px';
                  this.div.children[0].style.height = sw.y - ne.y + 'px';
              }
          };
          elm.addEventListener("click", function (event) {
              _this.handleTap();
              event.stopPropagation();
          });
          this.handleInfoWindowUpdate();
          return this.overlayView;
      };
      AgmOverlay.prototype.handleTap = function () {
          if (this.openInfoWindow) {
              this.infoWindow.forEach(function (infoWindow) {
                  infoWindow.open();
              });
          }
          this.markerClick.emit(null);
      };
      AgmOverlay.prototype._addEventListeners = function () {
          var _this = this;
          var eo = this._markerManager.createEventObservable('click', this.overlayView);
          var cs = eo.subscribe(function () { return _this.handleTap(); });
          this._observableSubscriptions.push(cs);
      };
      __decorate([
          core_1.Input(),
          __metadata("design:type", Number)
      ], AgmOverlay.prototype, "latitude", void 0);
      __decorate([
          core_1.Input(),
          __metadata("design:type", Number)
      ], AgmOverlay.prototype, "longitude", void 0);
      __decorate([
          core_1.Input(),
          __metadata("design:type", Boolean)
      ], AgmOverlay.prototype, "visible", void 0);
      __decorate([
          core_1.Input(),
          __metadata("design:type", Number)
      ], AgmOverlay.prototype, "zIndex", void 0);
      __decorate([
          core_1.Input(),
          __metadata("design:type", Object)
      ], AgmOverlay.prototype, "bounds", void 0);
      __decorate([
          core_1.Output(),
          __metadata("design:type", core_1.EventEmitter)
      ], AgmOverlay.prototype, "markerClick", void 0);
      __decorate([
          core_1.Input(),
          __metadata("design:type", Boolean)
      ], AgmOverlay.prototype, "openInfoWindow", void 0);
      __decorate([
          core_1.ContentChildren(core_2.AgmInfoWindow),
          __metadata("design:type", core_1.QueryList)
      ], AgmOverlay.prototype, "infoWindow", void 0);
      __decorate([
          core_1.Input('markerDraggable'),
          __metadata("design:type", Boolean)
      ], AgmOverlay.prototype, "draggable", void 0);
      __decorate([
          core_1.ViewChild('content', { read: core_1.ElementRef }),
          __metadata("design:type", core_1.ElementRef)
      ], AgmOverlay.prototype, "template", void 0);
      AgmOverlay = __decorate([
          core_1.Component({
              selector: "agm-overlay",
              template: '<div #content><div style="position:absolute"><ng-content></ng-content></div></div>'
          }),
          __metadata("design:paramtypes", [core_2.GoogleMapsAPIWrapper,
              core_2.MarkerManager])
      ], AgmOverlay);
      return AgmOverlay;
  }());
  exports.AgmOverlay = AgmOverlay;
  