agm-overlays
Version:
Custom marker overlay for the @agm/core package
16 lines (14 loc) • 6.37 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@agm/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("agm-overlays",["exports","@angular/core","@agm/core","@angular/common"],t):t((e=e||self)["agm-overlays"]={},e.ng.core,e.core$1,e.ng.common)}(this,(function(e,t,i,o){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function n(e,t,i,o){var n,r=arguments.length,a=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,o);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(r<3?n(a):r>3?n(t,i,a):n(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}var r=function(){function e(e,i){this._mapsWrapper=e,this._markerManager=i,this.visible=!0,this.zIndex=1,this.markerClick=new t.EventEmitter,this.openInfoWindow=!0,this.infoWindow=new t.QueryList,this.draggable=!1,this._observableSubscriptions=[]}return e.prototype.ngAfterViewInit=function(){for(var e=this,t=this.template.nativeElement.getElementsByTagName("agm-info-window"),i=t.length-1;i>=0;--i)t[i].parentNode.removeChild(t[i]);this.load().then((function(){e.onChanges=e.onChangesOverride}))},e.prototype.ngAfterContentInit=function(){var e=this;this.infoWindow.changes.subscribe((function(){return e.handleInfoWindowUpdate()}))},e.prototype.ngOnChanges=function(e){this.onChanges(e)},e.prototype.onChanges=function(e){},e.prototype.onChangesOverride=function(e){var t=this;(e.latitude||e.longitude||e.zIndex)&&(this.overlayView.latitude=this.latitude,this.overlayView.longitude=this.longitude,this.overlayView.zIndex=this.zIndex,this.destroy().then((function(){return t.load()})))},e.prototype.ngOnDestroy=function(){this.destroy()},e.prototype.destroy=function(){this.destroyed=!0;var e=this._markerManager.deleteMarker(this.overlayView);return this.overlayView&&(this.overlayView.div&&this.overlayView.remove(),this.overlayView.setMap(null)),this._observableSubscriptions.forEach((function(e){return e.unsubscribe()})),delete this.overlayView,e},e.prototype.handleInfoWindowUpdate=function(){var e=this;if(this.infoWindow.length>1)throw new Error("Expected no more than one info window.");this.infoWindow.forEach((function(t){t.hostMarker=e.overlayView}))},e.prototype.load=function(){var e=this;return this._mapsWrapper.getNativeMap().then((function(t){var i=e.getOverlay(t);return e._markerManager.addMarker(i),e._addEventListeners(),e._markerManager.getNativeMarker(i)})).then((function(t){var i=t.setMap;t.map&&e.overlayView.setMap(t.map),t.setMap=function(o){i.call(t,o),e.overlayView&&e.overlayView.setMap(o)}}))},e.prototype.getOverlay=function(e){var t=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=!1,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 i=this.template.nativeElement.children[0];return this.overlayView.remove=function(){var e;this.div&&(this.div.parentNode.removeChild(this.div),e=this.div,t.template.nativeElement.appendChild(e),delete this.div)},this.overlayView.getDiv=function(){return this.div},this.overlayView.draw=function(){if(!this.div){this.div=i;var e=this.getPanes();if(!e||!e.overlayImage)return;e.overlayImage.appendChild(i)}var t=new google.maps.LatLng(this.latitude,this.longitude),o=this.getProjection();if(o){var n=o.fromLatLngToDivPixel(t);if(n&&(i.style.left=n.x-10+"px",i.style.top=n.y-20+"px"),this.bounds_){var r=this.getProjection(),a=r.fromLatLngToDivPixel(this.bounds_.getSouthWest()),s=r.fromLatLngToDivPixel(this.bounds_.getNorthEast());this.div.style.left=a.x+"px",this.div.style.top=s.y+"px",this.div.children[0].style.width=s.x-a.x+"px",this.div.children[0].style.height=a.y-s.y+"px"}}},i.addEventListener("click",(function(e){t.handleTap(),e.stopPropagation()})),this.handleInfoWindowUpdate(),this.overlayView},e.prototype.handleTap=function(){this.openInfoWindow&&this.infoWindow.forEach((function(e){e.open()})),this.markerClick.emit(null)},e.prototype._addEventListeners=function(){var e=this,t=this._markerManager.createEventObservable("click",this.overlayView).subscribe((function(){return e.handleTap()}));this._observableSubscriptions.push(t)},e.ctorParameters=function(){return[{type:i.GoogleMapsAPIWrapper},{type:i.MarkerManager}]},n([t.Input()],e.prototype,"latitude",void 0),n([t.Input()],e.prototype,"longitude",void 0),n([t.Input()],e.prototype,"visible",void 0),n([t.Input()],e.prototype,"zIndex",void 0),n([t.Input()],e.prototype,"bounds",void 0),n([t.Output()],e.prototype,"markerClick",void 0),n([t.Input()],e.prototype,"openInfoWindow",void 0),n([t.ContentChildren(i.AgmInfoWindow)],e.prototype,"infoWindow",void 0),n([t.Input("markerDraggable")],e.prototype,"draggable",void 0),n([t.ViewChild("content",{read:t.ElementRef})],e.prototype,"template",void 0),e=n([t.Component({selector:"agm-overlay",template:'<div #content><div style="position:absolute"><ng-content></ng-content></div></div>'})],e)}(),a=function(){function e(){}return e=n([t.NgModule({imports:[o.CommonModule],declarations:[r],exports:[r]})],e)}();e.AgmOverlay=r,e.AgmOverlays=a,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=agm-overlays.umd.min.js.map