UNPKG

angular-leaflet

Version:

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

1,091 lines (1,071 loc) 31.7 kB
import { __spread, __assign, __extends } from 'tslib'; import { ContentChildren, Component, ElementRef, Input, NgModule, forwardRef } from '@angular/core'; import { v4 } from 'uuid'; import { CommonModule } from '@angular/common'; import { map, FeatureGroup, imageOverlay, latLngBounds, marker, divIcon, tileLayer, polygon, polyline, rectangle, circle } from 'leaflet'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @template T */ var /** * @template T */ LayerHandler = /** @class */ (function () { function LayerHandler() { this.id = v4(); } /** * @param {?} mapRef * @param {?} layerRef * @return {?} */ LayerHandler.prototype.initialize = /** * @param {?} mapRef * @param {?} layerRef * @return {?} */ function (mapRef, layerRef) { this.mapRef = mapRef; this.layerRef = layerRef; }; return LayerHandler; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @template T */ var BaseLayer = /** @class */ (function () { function BaseLayer() { this.handlerIds = []; this.id = v4(); } /** * @param {?} map * @return {?} */ BaseLayer.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { this.mapRef = map; }; /** * @return {?} */ BaseLayer.prototype.removeFrom = /** * @return {?} */ function () { if (this.layerRef) { ((/** @type {?} */ (this.mapRef))).removeLayer(this.layerRef); } }; /** * @return {?} */ BaseLayer.prototype.ngAfterContentInit = /** * @return {?} */ function () { this.initHandlers(); this.handlerSubscription = this.handlers.changes.subscribe(this.initHandlers.bind(this)); }; /** * @return {?} */ BaseLayer.prototype.initHandlers = /** * @return {?} */ function () { var _this = this; this.handlers.filter((/** * @param {?} handler * @return {?} */ function (handler) { return !_this.handlerIds.includes(handler.id); })).forEach(this.initHandler.bind(this)); }; /** * @param {?} handler * @return {?} */ BaseLayer.prototype.initHandler = /** * @param {?} handler * @return {?} */ function (handler) { handler.initialize(this.layerRef['_map'], this.layerRef); this.handlerIds = __spread(this.handlerIds, [handler.id]); }; /** * @return {?} */ BaseLayer.prototype.ngOnDestroy = /** * @return {?} */ function () { this.handlerSubscription.unsubscribe(); this.removeFrom(); }; BaseLayer.propDecorators = { handlers: [{ type: ContentChildren, args: [LayerHandler,] }] }; return BaseLayer; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var MapHandler = /** @class */ (function () { function MapHandler() { this.id = v4(); } /** * @param {?} mapRef * @return {?} */ MapHandler.prototype.initialize = /** * @param {?} mapRef * @return {?} */ function (mapRef) { this.mapRef = mapRef; }; return MapHandler; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var LeafletComponent = /** @class */ (function () { function LeafletComponent(elementRef) { this.elementRef = elementRef; this.layerIds = []; this.handlerIds = []; } /** * @return {?} */ LeafletComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.map = map(this.elementRef.nativeElement, __assign({}, this.options)); }; /** * @return {?} */ LeafletComponent.prototype.ngAfterContentInit = /** * @return {?} */ function () { this.addLayers(); this.layers.changes.subscribe(this.addLayers.bind(this)); this.addHandlers(); this.handlers.changes.subscribe(this.addHandlers.bind(this)); }; /** * @private * @return {?} */ LeafletComponent.prototype.addLayers = /** * @private * @return {?} */ function () { var _this = this; this.layers.filter((/** * @param {?} layer * @return {?} */ function (layer) { return !_this.layerIds.includes(layer.id); })).forEach(this.addLayer.bind(this)); }; /** * @private * @param {?} layer * @return {?} */ LeafletComponent.prototype.addLayer = /** * @private * @param {?} layer * @return {?} */ function (layer) { layer.addTo(this.map); this.layerIds = __spread(this.layerIds, [layer.id]); }; /** * @private * @return {?} */ LeafletComponent.prototype.addHandlers = /** * @private * @return {?} */ function () { var _this = this; this.handlers.filter((/** * @param {?} handler * @return {?} */ function (handler) { return !_this.handlerIds.includes(handler.id); })).forEach(this.addHandler.bind(this)); }; /** * @private * @param {?} handler * @return {?} */ LeafletComponent.prototype.addHandler = /** * @private * @param {?} handler * @return {?} */ function (handler) { handler.initialize(this.map); this.handlerIds = __spread(this.handlerIds, [handler.id]); }; LeafletComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-leaflet', template: '<ng-content></ng-content>', styles: ["\n :host {\n display: flex;\n flex: 1 1 auto;\n }\n "] }] } ]; /** @nocollapse */ LeafletComponent.ctorParameters = function () { return [ { type: ElementRef } ]; }; LeafletComponent.propDecorators = { options: [{ type: Input }], layers: [{ type: ContentChildren, args: [BaseLayer,] }], handlers: [{ type: ContentChildren, args: [MapHandler, { descendants: true },] }] }; return LeafletComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NglCoreModule = /** @class */ (function () { function NglCoreModule() { } NglCoreModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ LeafletComponent ], exports: [ LeafletComponent ] },] } ]; return NglCoreModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var FeatureGroupComponent = /** @class */ (function (_super) { __extends(FeatureGroupComponent, _super); function FeatureGroupComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.layerIds = []; return _this; } /** * @param {?} map * @return {?} */ FeatureGroupComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); this.layerRef = new FeatureGroup(); this.mapRef.addLayer(this.layerRef); this.addLayers(); this.initHandlers(); this.layers.changes.subscribe(this.addLayers.bind(this)); }; /** * @private * @return {?} */ FeatureGroupComponent.prototype.addLayers = /** * @private * @return {?} */ function () { var _this = this; this.layers .filter((/** * @param {?} layer * @return {?} */ function (layer) { return layer.id !== _this.id; })) .filter((/** * @param {?} layer * @return {?} */ function (layer) { return !_this.layerIds.includes(layer.id); })) .forEach(this.addLayer.bind(this)); }; /** * @private * @param {?} layer * @return {?} */ FeatureGroupComponent.prototype.addLayer = /** * @private * @param {?} layer * @return {?} */ function (layer) { layer.addTo(this.layerRef); this.layerIds = __spread(this.layerIds, [layer.id]); }; FeatureGroupComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-feature-group', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return FeatureGroupComponent; })) }] }] } ]; FeatureGroupComponent.propDecorators = { layers: [{ type: ContentChildren, args: [BaseLayer,] }] }; return FeatureGroupComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NglGroupsModule = /** @class */ (function () { function NglGroupsModule() { } NglGroupsModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ FeatureGroupComponent ], exports: [ FeatureGroupComponent ] },] } ]; return NglGroupsModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ImageOverlayComponent = /** @class */ (function (_super) { __extends(ImageOverlayComponent, _super); function ImageOverlayComponent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(ImageOverlayComponent.prototype, "src", { set: /** * @param {?} value * @return {?} */ function (value) { this._url = value; if (this.layerRef) { this.layerRef.setUrl(value); } else { this.prepareLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(ImageOverlayComponent.prototype, "width", { set: /** * @param {?} value * @return {?} */ function (value) { this._width = value; if (this.layerRef) { this.layerRef.setBounds(this.prepareBounds(this._width, this._height)); } else { this.prepareLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(ImageOverlayComponent.prototype, "height", { set: /** * @param {?} value * @return {?} */ function (value) { this._height = value; if (this.layerRef) { this.layerRef.setBounds(this.prepareBounds(this._width, this._height)); } else { this.prepareLayer(); } }, enumerable: true, configurable: true }); /** * @param {?} map * @return {?} */ ImageOverlayComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); this.prepareLayer(); }; /** * @return {?} */ ImageOverlayComponent.prototype.prepareLayer = /** * @return {?} */ function () { if (this.mapRef && this._url && this._height && this._width) { this.layerRef = imageOverlay(this._url, this.prepareBounds(this._width, this._height)); this.mapRef.addLayer(this.layerRef); this.initHandlers(); } }; /** * @private * @param {?} width * @param {?} height * @return {?} */ ImageOverlayComponent.prototype.prepareBounds = /** * @private * @param {?} width * @param {?} height * @return {?} */ function (width, height) { /** @type {?} */ var southWest = ((/** @type {?} */ (this.mapRef))).unproject([0, height * 2], 1); /** @type {?} */ var northEast = ((/** @type {?} */ (this.mapRef))).unproject([width * 2, 0], 1); return latLngBounds(southWest, northEast); }; ImageOverlayComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-image-overlay', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return ImageOverlayComponent; })) }] }] } ]; ImageOverlayComponent.propDecorators = { src: [{ type: Input }], width: [{ type: Input }], height: [{ type: Input }] }; return ImageOverlayComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NglImageOverlayModule = /** @class */ (function () { function NglImageOverlayModule() { } NglImageOverlayModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ ImageOverlayComponent ], exports: [ ImageOverlayComponent ] },] } ]; return NglImageOverlayModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var MarkerComponent = /** @class */ (function (_super) { __extends(MarkerComponent, _super); function MarkerComponent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(MarkerComponent.prototype, "latLng", { set: /** * @param {?} value * @return {?} */ function (value) { this._latLng = value; this.prepareLayer(); }, enumerable: true, configurable: true }); /** * @private * @return {?} */ MarkerComponent.prototype.prepareLayer = /** * @private * @return {?} */ function () { if (this.mapRef && this._latLng) { if (this.layerRef) { this.layerRef.setLatLng(this._latLng); } else { this.createLayer(); } } }; /** * @private * @return {?} */ MarkerComponent.prototype.createLayer = /** * @private * @return {?} */ function () { this.layerRef = marker(this._latLng, { icon: divIcon() }); this.mapRef.addLayer(this.layerRef); this.initHandlers(); }; /** * @param {?} map * @return {?} */ MarkerComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); this.prepareLayer(); }; MarkerComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-marker', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return MarkerComponent; })) }] }] } ]; MarkerComponent.propDecorators = { latLng: [{ type: Input }] }; return MarkerComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NglMarkerModule = /** @class */ (function () { function NglMarkerModule() { } NglMarkerModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ MarkerComponent ], exports: [ MarkerComponent ] },] } ]; return NglMarkerModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var TileLayerComponent = /** @class */ (function (_super) { __extends(TileLayerComponent, _super); function TileLayerComponent() { return _super !== null && _super.apply(this, arguments) || this; } /** * @param {?} map * @return {?} */ TileLayerComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); if (!this.layerRef) { this.layerRef = tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'); this.mapRef.addLayer(this.layerRef); this.initHandlers(); } }; TileLayerComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-tile-layer', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return TileLayerComponent; })) }] }] } ]; return TileLayerComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NglTileLayerModule = /** @class */ (function () { function NglTileLayerModule() { } NglTileLayerModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ TileLayerComponent ], exports: [ TileLayerComponent ] },] } ]; return NglTileLayerModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PolygonComponent = /** @class */ (function (_super) { __extends(PolygonComponent, _super); function PolygonComponent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(PolygonComponent.prototype, "coordinates", { set: /** * @param {?} value * @return {?} */ function (value) { this._coordinates = value; if (this.layerRef) { this.layerRef.setLatLngs(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(PolygonComponent.prototype, "options", { set: /** * @param {?} value * @return {?} */ function (value) { this._options = value; if (this.layerRef) { this.layerRef.setStyle(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); /** * @return {?} */ PolygonComponent.prototype.createLayer = /** * @return {?} */ function () { if (this.mapRef && this._coordinates) { this.layerRef = polygon(this._coordinates, __assign({}, this._options)); this.mapRef.addLayer(this.layerRef); this.initHandlers(); } }; /** * @param {?} map * @return {?} */ PolygonComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); if (!this.layerRef) { this.createLayer(); } }; PolygonComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-polygon', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return PolygonComponent; })) }] }] } ]; PolygonComponent.propDecorators = { coordinates: [{ type: Input }], options: [{ type: Input }] }; return PolygonComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PolylineComponent = /** @class */ (function (_super) { __extends(PolylineComponent, _super); function PolylineComponent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(PolylineComponent.prototype, "coordinates", { set: /** * @param {?} value * @return {?} */ function (value) { this._coordinates = value; if (this.layerRef) { this.layerRef.setLatLngs(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(PolylineComponent.prototype, "options", { set: /** * @param {?} value * @return {?} */ function (value) { this._options = value; if (this.layerRef) { this.layerRef.setStyle(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); /** * @param {?} map * @return {?} */ PolylineComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); if (!this.layerRef && this._coordinates) { this.createLayer(); } }; /** * @private * @return {?} */ PolylineComponent.prototype.createLayer = /** * @private * @return {?} */ function () { if (this.mapRef && this._coordinates) { this.layerRef = polyline(this._coordinates, __assign({}, this._options)); this.mapRef.addLayer(this.layerRef); this.initHandlers(); } }; PolylineComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-polyline', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return PolylineComponent; })) }] }] } ]; PolylineComponent.propDecorators = { coordinates: [{ type: Input }], options: [{ type: Input }] }; return PolylineComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var RectangleComponent = /** @class */ (function (_super) { __extends(RectangleComponent, _super); function RectangleComponent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(RectangleComponent.prototype, "bounds", { set: /** * @param {?} value * @return {?} */ function (value) { this._bounds = value; if (this.layerRef) { this.layerRef.setBounds(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(RectangleComponent.prototype, "options", { set: /** * @param {?} value * @return {?} */ function (value) { this._options = value; if (this.layerRef) { this.layerRef.setStyle(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); /** * @return {?} */ RectangleComponent.prototype.createLayer = /** * @return {?} */ function () { if (this.mapRef && this._bounds) { this.layerRef = rectangle(this._bounds, __assign({}, this._options)); this.mapRef.addLayer(this.layerRef); this.initHandlers(); } }; /** * @param {?} map * @return {?} */ RectangleComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); if (!this.layerRef) { this.createLayer(); } }; RectangleComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-rectangle', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return RectangleComponent; })) }] }] } ]; RectangleComponent.propDecorators = { bounds: [{ type: Input }], options: [{ type: Input }] }; return RectangleComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var CircleComponent = /** @class */ (function (_super) { __extends(CircleComponent, _super); function CircleComponent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(CircleComponent.prototype, "center", { set: /** * @param {?} value * @return {?} */ function (value) { this._center = value; if (this.layerRef) { this.layerRef.setLatLng(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(CircleComponent.prototype, "radius", { set: /** * @param {?} value * @return {?} */ function (value) { this._radius = value; if (this.layerRef) { this.layerRef.setRadius(value); } else { this.createLayer(); } }, enumerable: true, configurable: true }); Object.defineProperty(CircleComponent.prototype, "options", { set: /** * @param {?} value * @return {?} */ function (value) { this._options = value; if (this.layerRef) { this.layerRef.setStyle(value); } }, enumerable: true, configurable: true }); /** * @param {?} map * @return {?} */ CircleComponent.prototype.addTo = /** * @param {?} map * @return {?} */ function (map) { _super.prototype.addTo.call(this, map); if (!this.layerRef) { this.createLayer(); } }; /** * @private * @return {?} */ CircleComponent.prototype.createLayer = /** * @private * @return {?} */ function () { if (this.mapRef && this._center && this._radius) { this.layerRef = circle(this._center, __assign({}, this._options, { radius: this._radius })); this.mapRef.addLayer(this.layerRef); this.initHandlers(); } }; CircleComponent.decorators = [ { type: Component, args: [{ selector: 'ngl-circle', template: '', providers: [{ provide: BaseLayer, useExisting: forwardRef((/** * @return {?} */ function () { return CircleComponent; })) }] }] } ]; CircleComponent.propDecorators = { center: [{ type: Input }], radius: [{ type: Input }], options: [{ type: Input }] }; return CircleComponent; }(BaseLayer)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NglVectorsModule = /** @class */ (function () { function NglVectorsModule() { } NglVectorsModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ PolygonComponent, PolylineComponent, RectangleComponent, CircleComponent ], exports: [ PolygonComponent, PolylineComponent, RectangleComponent, CircleComponent ] },] } ]; return NglVectorsModule; }()); export { BaseLayer, CircleComponent, FeatureGroupComponent, ImageOverlayComponent, LayerHandler, LeafletComponent, MapHandler, MarkerComponent, NglCoreModule, NglGroupsModule, NglImageOverlayModule, NglMarkerModule, NglTileLayerModule, NglVectorsModule, PolygonComponent, PolylineComponent, RectangleComponent, TileLayerComponent }; //# sourceMappingURL=angular-leaflet.js.map