@boldadmin/angular-google-maps
Version:
Google Maps adapter for Angular Framework
2 lines • 9.76 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@boldadmin/event-publisher"),require("moment"),require("@angular/material"),require("@angular/platform-browser"),require("@angular/forms"),require("load-google-maps-api")):"function"==typeof define&&define.amd?define("@boldadmin/angular-google-maps",["exports","@angular/core","@boldadmin/event-publisher","moment","@angular/material","@angular/platform-browser","@angular/forms","load-google-maps-api"],t):t(((e=e||self).boldadmin=e.boldadmin||{},e.boldadmin["angular-google-maps"]={}),e.ng.core,e.eventPublisher,e.moment,e.ng.material,e.ng.platformBrowser,e.ng.forms,e.GoogleMapsApi)}(this,function(e,t,o,r,n,i,a,s){"use strict";s=s&&s.hasOwnProperty("default")?s.default:s;var c={searchBox:"Search Box"},p=function(e,t){this.latitude=e,this.longitude=t},l=function(e,t){this.coordinates=e,this.radiusInMeters=t},u=function(){function e(){}return e.prototype.getGoogleMaps=function(){return google.maps},e.prototype.createMap=function(e){return new google.maps.Map(document.getElementById("map"),e)},e.prototype.createCircle=function(e){return new google.maps.Circle(e)},e.prototype.createMarker=function(e){return new google.maps.Marker(e)},e.prototype.createPolyline=function(e){return new google.maps.Polyline(e)},e.prototype.createSearchBox=function(){return new google.maps.places.SearchBox(document.getElementById("search-input"))},e.prototype.createLatLng=function(e){return new google.maps.LatLng(e.latitude,e.longitude)},e.prototype.createGeocoder=function(){return new google.maps.Geocoder},e.prototype.getSearchBoxInput=function(){return document.getElementById("search-input")},e.prototype.createSize=function(e,t){return new google.maps.Size(e,t)},e.prototype.createPoint=function(e,t){return new google.maps.Point(e,t)},e.decorators=[{type:t.Injectable}],e}(),d=function(){function e(e){this.googleMaps=e}return e.prototype.geocode=function(e,t){return this.googleMaps.createGeocoder().geocode({address:e},function(e){null!==e&&e[0]?t(new p(e[0].geometry.location.lat(),e[0].geometry.location.lng())):t(new p(59.9139,10.7522))})},e.prototype.reverseGeocode=function(e,t){var o=this.googleMaps.createLatLng(e);this.googleMaps.createGeocoder().geocode({location:o},function(e){null!==e&&e[0]?t(e[0].formatted_address):t(o.toString())})},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:u}]},e}(),g=function(){function e(e,t,o){this.googleMapsFactory=e,this.geocoder=t,this.eventPublisher=o}return e.prototype.createMap=function(e){return this.map=this.googleMapsFactory.createMap(e),this},e.prototype.addCenterMarker=function(e){return this.marker=this.googleMapsFactory.createMarker(e),this.marker.setPosition(this.map.getCenter()),this.marker.setMap(this.map),this.addMarkerListeners(),this},e.prototype.addCircle=function(e){var t=this;return this.circle=this.googleMapsFactory.createCircle(e),this.circle.setMap(this.map),this.circle.addListener("radius_changed",function(){return t.notifyLocationChange()}),this},e.prototype.addPolyline=function(e){return this.googleMapsFactory.createPolyline(e).setMap(this.map),this},e.prototype.addMarker=function(e){return this.googleMapsFactory.createMarker(e).setMap(this.map),this},e.prototype.bindCircleToMarker=function(){return this.circle.bindTo("center",this.marker,"position"),this},e.prototype.hideMarker=function(){return this.marker.setMap(null),this},e.prototype.hideCircle=function(){return this.circle.setMap(null),this},e.prototype.addSearchBox=function(){var e=this,t=this.googleMapsFactory.createSearchBox();return t.addListener("places_changed",function(){var o=t.getPlaces();if(o[0]){e.changeMapLocationAndZoom(o[0].geometry.location),e.changeMarkerLocation(o[0].geometry.location);var r=o[0].geometry.location,n=new p(r.lat(),r.lng());e.eventPublisher.notify("locationChanged",new l(n,e.circle.getRadius()))}}),this},e.prototype.addMarkerListeners=function(){var e=this;this.marker.addListener("dragend",function(){return e.notifyLocationChange()}),this.marker.addListener("dragend",function(t){return e.reverseGeocode(t)}),this.map.addListener("click",function(t){return e.changeMarkerLocation(t.latLng)}),this.map.addListener("click",function(){return e.notifyLocationChange()}),this.map.addListener("click",function(t){return e.reverseGeocode(t)})},e.prototype.notifyLocationChange=function(){this.eventPublisher.notify("locationChanged",new l(this.getCoordinates(),this.getRadius()))},e.prototype.getRadius=function(){var e=0;return void 0!==this.circle&&(e=this.circle.getRadius()),e},e.prototype.getCoordinates=function(){var e=new p(0,0);return void 0!==this.marker&&(e=new p(this.marker.getPosition().lat(),this.marker.getPosition().lng())),e},e.prototype.changeMapLocationAndZoom=function(e){this.map.panTo(e),this.map.setZoom(16)},e.prototype.changeMarkerLocation=function(e){this.circle.setMap(this.map),this.marker.setMap(this.map),this.marker.setPosition(e)},e.prototype.reverseGeocode=function(e){var t=this;this.geocoder.reverseGeocode(new p(e.latLng.lat(),e.latLng.lng()),function(e){return t.eventPublisher.notify("addressReverseGeocoded",e)})},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:u},{type:d},{type:o.EventPublisher}]},e}(),h=function(){function e(e,t){this.iconRegistry=e,this.sanitizer=t}return e.prototype.register=function(e,t){this.iconRegistry.addSvgIcon(e,this.sanitizer.bypassSecurityTrustResourceUrl(t))},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:n.MatIconRegistry},{type:i.DomSanitizer}]},e}(),m=function(){function e(e,t,o,r,n){this.googleMapsFactory=e,this.googleMapsBuilder=t,this.googleMapsGeocoder=o,this.eventPublisher=r,this.iconRegistry=n,this.mapsText=c,this.address="",this.mapOptions={center:{lat:0,lng:0},mapTypeControlOptions:{mapTypeIds:["roadmap","satellite"],position:this.googleMapsFactory.getGoogleMaps().ControlPosition.LEFT_BOTTOM},zoom:16,controlSize:22,fullscreenControl:!1},this.markerOptions={position:{lat:0,lng:0},draggable:!0,animation:this.googleMapsFactory.getGoogleMaps().Animation.DROP},this.circleOptions={strokeColor:"#448aff",strokeOpacity:.8,strokeWeight:2,fillColor:"#448aff",fillOpacity:.35,editable:!0,radius:70},this.previousMarkerIcon={url:"http://cdn.boldadmin.com.s3-website-eu-west-1.amazonaws.com/previous-marker.png"},this.currentMarkerIcon={url:"http://cdn.boldadmin.com.s3-website-eu-west-1.amazonaws.com/current-marker.png"}}return e.prototype.ngOnInit=function(){var e=this;this.eventPublisher.subscribe("addressReverseGeocoded",function(t){return e.address=t}),this.iconRegistry.register("expand","./assets/expand.svg"),this.iconRegistry.register("collapse","./assets/collapse.svg")},e.prototype.ngOnDestroy=function(){this.eventPublisher.unsubscribeAll("addressReverseGeocoded")},e.prototype.createMapByLocation=function(e){var t=this;this.googleMapsGeocoder.reverseGeocode(e.coordinates,function(e){return t.address=e}),this.circleOptions.radius=e.radiusInMeters,this.changeMapCenter(e.coordinates),this.googleMapsBuilder.createMap(this.mapOptions).addCenterMarker(this.markerOptions).addCircle(this.circleOptions).bindCircleToMarker().addSearchBox()},e.prototype.createMapByAddress=function(e){var t=this;this.googleMapsGeocoder.geocode(e,function(e){t.changeMapCenter(e),t.googleMapsBuilder.createMap(t.mapOptions).addCenterMarker(t.markerOptions).addCircle(t.circleOptions).bindCircleToMarker().hideMarker().hideCircle().addSearchBox()})},e.prototype.notifyMapResize=function(){this.eventPublisher.notify("resizeMap")},e.prototype.addTravelPath=function(e,t){var o=this;e.forEach(function(e,n){var i=0===n?o.currentMarkerIcon:o.previousMarkerIcon,a=r.utc(e.timestamp).format("YYYY.MM.DD HH:mm");o.googleMapsBuilder.addMarker({position:o.googleMapsFactory.createLatLng(e.coordinates),title:"Name: "+t+", Time: "+a,icon:i})});var n=e.map(function(e){return o.googleMapsFactory.createLatLng(e.coordinates)});this.addPolyline(n,"#"+Math.random().toString(16).substr(2,6))},e.prototype.addPolyline=function(e,t){this.googleMapsBuilder.addPolyline({geodesic:!0,strokeOpacity:.8,strokeWeight:1,path:e,strokeColor:t})},e.prototype.changeMapCenter=function(e){this.mapOptions.center={lat:e.latitude,lng:e.longitude}},e.decorators=[{type:t.Component,args:[{selector:"google-maps",template:'<input id="search-input" name="searchBox" class="controls" type="text"\n placeholder="{{mapsText.searchBox}}"\n [ngModelOptions]="{standalone: true}"\n [(ngModel)]="address"/>\n<mat-icon id="expand-icon" class="resize-control" svgIcon="expand" (click)="notifyMapResize()"></mat-icon>\n<mat-icon id="collapse-icon" class="resize-control" svgIcon="collapse" (click)="notifyMapResize()"></mat-icon>\n\n<div id="map"></div>\n',providers:[g]}]}],e.ctorParameters=function(){return[{type:u},{type:g},{type:d},{type:o.EventPublisher},{type:h}]},e.propDecorators={mapOptions:[{type:t.Output}],markerOptions:[{type:t.Output}],circleOptions:[{type:t.Output}],previousMarkerIcon:[{type:t.Output}],currentMarkerIcon:[{type:t.Output}]},e}(),y=function(){function e(){}return e.load=function(e){return Promise.resolve(s({key:e,libraries:["places"]}))},e.decorators=[{type:t.Injectable}],e}(),f=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{declarations:[m],imports:[a.FormsModule,n.MatIconModule],exports:[m],providers:[d,y,u,h]}]}],e}(),M=function(e,t){this.coordinates=e,this.timestamp=t};e.AngularGoogleMapsComponent=m,e.AngularGoogleMapsModule=f,e.Coordinates=p,e.GoogleMapsLoader=y,e.Location=l,e.TimestampCoordinates=M,e.ɵa=g,e.ɵb=u,e.ɵc=d,e.ɵd=h,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=boldadmin-angular-google-maps.umd.min.js.map