UNPKG

angular-leaflet

Version:

Collection of angular components to build map views faster and with minimal configuration using the most popular library **LeafletJS**.

2 lines 12.3 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("uuid"),require("@angular/common"),require("leaflet")):"function"==typeof define&&define.amd?define("angular-leaflet",["exports","@angular/core","uuid","@angular/common","leaflet"],t):t((e=e||self)["angular-leaflet"]={},e.ng.core,e.uuid,e.ng.common,e.leaflet)}(this,function(e,t,r,n,o){"use strict";var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function s(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var a=function(){return(a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function p(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(a){o={error:a}}finally{try{n&&!n.done&&(r=i["return"])&&r.call(i)}finally{if(o)throw o.error}}return s}function l(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(p(arguments[t]));return e}var u=function(){function e(){this.id=r.v4()}return e.prototype.initialize=function(e,t){this.mapRef=e,this.layerRef=t},e}(),d=function(){function e(){this.handlerIds=[],this.id=r.v4()}return e.prototype.addTo=function(e){this.mapRef=e},e.prototype.removeFrom=function(){this.layerRef&&this.mapRef.removeLayer(this.layerRef)},e.prototype.ngAfterContentInit=function(){this.initHandlers(),this.handlerSubscription=this.handlers.changes.subscribe(this.initHandlers.bind(this))},e.prototype.initHandlers=function(){var e=this;this.handlers.filter(function(t){return!e.handlerIds.includes(t.id)}).forEach(this.initHandler.bind(this))},e.prototype.initHandler=function(e){e.initialize(this.layerRef._map,this.layerRef),this.handlerIds=l(this.handlerIds,[e.id])},e.prototype.ngOnDestroy=function(){this.handlerSubscription.unsubscribe(),this.removeFrom()},e.propDecorators={handlers:[{type:t.ContentChildren,args:[u]}]},e}(),h=function(){function e(){this.id=r.v4()}return e.prototype.initialize=function(e){this.mapRef=e},e}(),c=function(){function e(e){this.elementRef=e,this.layerIds=[],this.handlerIds=[]}return e.prototype.ngOnInit=function(){this.map=o.map(this.elementRef.nativeElement,a({},this.options))},e.prototype.ngAfterContentInit=function(){this.addLayers(),this.layers.changes.subscribe(this.addLayers.bind(this)),this.addHandlers(),this.handlers.changes.subscribe(this.addHandlers.bind(this))},e.prototype.addLayers=function(){var e=this;this.layers.filter(function(t){return!e.layerIds.includes(t.id)}).forEach(this.addLayer.bind(this))},e.prototype.addLayer=function(e){e.addTo(this.map),this.layerIds=l(this.layerIds,[e.id])},e.prototype.addHandlers=function(){var e=this;this.handlers.filter(function(t){return!e.handlerIds.includes(t.id)}).forEach(this.addHandler.bind(this))},e.prototype.addHandler=function(e){e.initialize(this.map),this.handlerIds=l(this.handlerIds,[e.id])},e.decorators=[{type:t.Component,args:[{selector:"ngl-leaflet",template:"<ng-content></ng-content>",styles:["\n :host {\n display: flex;\n flex: 1 1 auto;\n }\n "]}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={options:[{type:t.Input}],layers:[{type:t.ContentChildren,args:[d]}],handlers:[{type:t.ContentChildren,args:[h,{descendants:!0}]}]},e}(),f=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[c],exports:[c]}]}],e}(),y=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.layerIds=[],t}return s(r,e),r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.layerRef=new o.FeatureGroup,this.mapRef.addLayer(this.layerRef),this.addLayers(),this.initHandlers(),this.layers.changes.subscribe(this.addLayers.bind(this))},r.prototype.addLayers=function(){var e=this;this.layers.filter(function(t){return t.id!==e.id}).filter(function(t){return!e.layerIds.includes(t.id)}).forEach(this.addLayer.bind(this))},r.prototype.addLayer=function(e){e.addTo(this.layerRef),this.layerIds=l(this.layerIds,[e.id])},r.decorators=[{type:t.Component,args:[{selector:"ngl-feature-group",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={layers:[{type:t.ContentChildren,args:[d]}]},r}(d),g=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[y],exports:[y]}]}],e}(),m=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),Object.defineProperty(r.prototype,"src",{set:function(e){this._url=e,this.layerRef?this.layerRef.setUrl(e):this.prepareLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"width",{set:function(e){this._width=e,this.layerRef?this.layerRef.setBounds(this.prepareBounds(this._width,this._height)):this.prepareLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"height",{set:function(e){this._height=e,this.layerRef?this.layerRef.setBounds(this.prepareBounds(this._width,this._height)):this.prepareLayer()},enumerable:!0,configurable:!0}),r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.prepareLayer()},r.prototype.prepareLayer=function(){this.mapRef&&this._url&&this._height&&this._width&&(this.layerRef=o.imageOverlay(this._url,this.prepareBounds(this._width,this._height)),this.mapRef.addLayer(this.layerRef),this.initHandlers())},r.prototype.prepareBounds=function(e,t){var r=this.mapRef.unproject([0,2*t],1),n=this.mapRef.unproject([2*e,0],1);return o.latLngBounds(r,n)},r.decorators=[{type:t.Component,args:[{selector:"ngl-image-overlay",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={src:[{type:t.Input}],width:[{type:t.Input}],height:[{type:t.Input}]},r}(d),R=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[m],exports:[m]}]}],e}(),b=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),Object.defineProperty(r.prototype,"latLng",{set:function(e){this._latLng=e,this.prepareLayer()},enumerable:!0,configurable:!0}),r.prototype.prepareLayer=function(){this.mapRef&&this._latLng&&(this.layerRef?this.layerRef.setLatLng(this._latLng):this.createLayer())},r.prototype.createLayer=function(){this.layerRef=o.marker(this._latLng,{icon:o.divIcon()}),this.mapRef.addLayer(this.layerRef),this.initHandlers()},r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.prepareLayer()},r.decorators=[{type:t.Component,args:[{selector:"ngl-marker",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={latLng:[{type:t.Input}]},r}(d),L=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[b],exports:[b]}]}],e}(),_=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.layerRef||(this.layerRef=o.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"),this.mapRef.addLayer(this.layerRef),this.initHandlers())},r.decorators=[{type:t.Component,args:[{selector:"ngl-tile-layer",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r}(d),v=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[_],exports:[_]}]}],e}(),C=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),Object.defineProperty(r.prototype,"coordinates",{set:function(e){this._coordinates=e,this.layerRef?this.layerRef.setLatLngs(e):this.createLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"options",{set:function(e){this._options=e,this.layerRef?this.layerRef.setStyle(e):this.createLayer()},enumerable:!0,configurable:!0}),r.prototype.createLayer=function(){this.mapRef&&this._coordinates&&(this.layerRef=o.polygon(this._coordinates,a({},this._options)),this.mapRef.addLayer(this.layerRef),this.initHandlers())},r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.layerRef||this.createLayer()},r.decorators=[{type:t.Component,args:[{selector:"ngl-polygon",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={coordinates:[{type:t.Input}],options:[{type:t.Input}]},r}(d),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),Object.defineProperty(r.prototype,"coordinates",{set:function(e){this._coordinates=e,this.layerRef?this.layerRef.setLatLngs(e):this.createLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"options",{set:function(e){this._options=e,this.layerRef?this.layerRef.setStyle(e):this.createLayer()},enumerable:!0,configurable:!0}),r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),!this.layerRef&&this._coordinates&&this.createLayer()},r.prototype.createLayer=function(){this.mapRef&&this._coordinates&&(this.layerRef=o.polyline(this._coordinates,a({},this._options)),this.mapRef.addLayer(this.layerRef),this.initHandlers())},r.decorators=[{type:t.Component,args:[{selector:"ngl-polyline",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={coordinates:[{type:t.Input}],options:[{type:t.Input}]},r}(d),O=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),Object.defineProperty(r.prototype,"bounds",{set:function(e){this._bounds=e,this.layerRef?this.layerRef.setBounds(e):this.createLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"options",{set:function(e){this._options=e,this.layerRef?this.layerRef.setStyle(e):this.createLayer()},enumerable:!0,configurable:!0}),r.prototype.createLayer=function(){this.mapRef&&this._bounds&&(this.layerRef=o.rectangle(this._bounds,a({},this._options)),this.mapRef.addLayer(this.layerRef),this.initHandlers())},r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.layerRef||this.createLayer()},r.decorators=[{type:t.Component,args:[{selector:"ngl-rectangle",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={bounds:[{type:t.Input}],options:[{type:t.Input}]},r}(d),M=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return s(r,e),Object.defineProperty(r.prototype,"center",{set:function(e){this._center=e,this.layerRef?this.layerRef.setLatLng(e):this.createLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"radius",{set:function(e){this._radius=e,this.layerRef?this.layerRef.setRadius(e):this.createLayer()},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"options",{set:function(e){this._options=e,this.layerRef&&this.layerRef.setStyle(e)},enumerable:!0,configurable:!0}),r.prototype.addTo=function(t){e.prototype.addTo.call(this,t),this.layerRef||this.createLayer()},r.prototype.createLayer=function(){this.mapRef&&this._center&&this._radius&&(this.layerRef=o.circle(this._center,a({},this._options,{radius:this._radius})),this.mapRef.addLayer(this.layerRef),this.initHandlers())},r.decorators=[{type:t.Component,args:[{selector:"ngl-circle",template:"",providers:[{provide:d,useExisting:t.forwardRef(function(){return r})}]}]}],r.propDecorators={center:[{type:t.Input}],radius:[{type:t.Input}],options:[{type:t.Input}]},r}(d),j=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[C,I,O,M],exports:[C,I,O,M]}]}],e}();e.BaseLayer=d,e.CircleComponent=M,e.FeatureGroupComponent=y,e.ImageOverlayComponent=m,e.LayerHandler=u,e.LeafletComponent=c,e.MapHandler=h,e.MarkerComponent=b,e.NglCoreModule=f,e.NglGroupsModule=g,e.NglImageOverlayModule=R,e.NglMarkerModule=L,e.NglTileLayerModule=v,e.NglVectorsModule=j,e.PolygonComponent=C,e.PolylineComponent=I,e.RectangleComponent=O,e.TileLayerComponent=_,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=angular-leaflet.umd.min.js.map