all files / lib/ base-layer.directive.js

84.85% Statements 28/33
61.29% Branches 19/31
85.71% Functions 6/7
89.66% Lines 26/29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80                                                                                                           
"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;
    Eif (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) {
    Eif (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 layer_provider_1 = require("./layer.provider");
var layers_control_provider_1 = require("./layers-control.provider");
/**
 * Angular2 directive for adding layers to the layers-control of Leaflet as base-layer.
 *
 * *You can use this directive in an Angular2 template after importing `YagaModule`.*
 *
 * How to use in a template:
 * ```html
 * <yaga-map>
 *     <yaga-layers-control>
 *         <!-- This can be any other layer... -->
 *         <yaga-tile-layer yaga-base-layer [caption]="'OSM'"></yaga-tile-layer>
 *     </yaga-attribution-control>
 * </yaga-map>
 * ```
 *
 * @link http://leafletjs.com/reference-1.2.0.html#control-layers-addbaselayer Original Leaflet documentation
 * @link https://leaflet-ng2.yagajs.org/1.0.0/browser-test?grep=Base-Layer%20Directive Unit-Test
 * @link https://leaflet-ng2.yagajs.org/1.0.0/coverage/lcov-report/lib/base-layer.directive.js.html
 * Test coverage
 * @link https://leaflet-ng2.yagajs.org/1.0.0/typedoc/classes/baselayerdirective.html API documentation
 * @example https://leaflet-ng2.yagajs.org/1.0.0/examples/layers-control-directive/
 */
var BaseLayerDirective = /** @class */ (function () {
    function BaseLayerDirective(layer, layersControlProvider) {
        this.layer = layer;
        this.layersControlProvider = layersControlProvider;
    }
    Object.defineProperty(BaseLayerDirective.prototype, "caption", {
        get: function () {
            for (var _i = 0, _a = this.layersControlProvider.ref._layers; _i < _a.length; _i++) {
                var layer = _a[_i];
                Eif (layer.layer === this.layer.ref) {
                    return layer.name;
                }
            }
            return "";
        },
        set: function (value) {
            this.layersControlProvider.ref.removeLayer(this.layer.ref);
            this.layersControlProvider.ref.addBaseLayer(this.layer.ref, value);
        },
        enumerable: true,
        configurable: true
    });
    /**
     * Internal method to provide the removal from the control in Leaflet, when removing it from the Angular template
     */
    BaseLayerDirective.prototype.ngOnDestroy = function () {
        this.layersControlProvider.ref.removeLayer(this.layer.ref);
    };
    __decorate([
        core_1.Input(),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], BaseLayerDirective.prototype, "caption", null);
    BaseLayerDirective = __decorate([
        core_1.Directive({
            selector: "[yaga-base-layer]",
        }),
        __metadata("design:paramtypes", [layer_provider_1.LayerProvider,
            layers_control_provider_1.LayersControlProvider])
    ], BaseLayerDirective);
    return BaseLayerDirective;
}());
exports.BaseLayerDirective = BaseLayerDirective;
//# sourceMappingURL=base-layer.directive.js.map