all files / lib/ feature-group.directive.js

89.72% Statements 96/107
67.27% Branches 37/55
80% Functions 24/30
92.93% Lines 92/99
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299            13× 13×   13×   16×                                                                           14× 14×           14×           14×           14×           14×           14×           14×           14×           14×           14× 14× 14× 14×   14× 17×   14×   14×     14×     14×   14×   14×   14×   14×   14×   14×                                                                                                                                                                                                                
"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    }
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var leaflet_1 = require("leaflet");
var layer_group_provider_1 = require("./layer-group.provider");
var layer_provider_1 = require("./layer.provider");
/**
 * Angular2 directive for Leaflet layer-groups.
 *
 * *You can use this directive in an Angular2 template after importing `YagaModule`.*
 *
 * How to use in a template:
 * ```html
 * <yaga-map>
 *     <yaga-feature-group
 *         [(display)]="..."
 *
 *         (add)="..."
 *         (remove)="..."
 *         (popupopen)="..."
 *         (popupclose)="..."
 *         (tooltipopen)="..."
 *         (tooltipclose)="..."
 *
 *         [attribution]="...">
 *         <!-- place other layers here... -->
 *     </yaga-feature-group>
 * </yaga-map>
 * ```
 *
 * @link http://leafletjs.com/reference-1.2.0.html#featuregroup Original Leaflet documentation
 * @link https://leaflet-ng2.yagajs.org/1.0.0/browser-test?grep=Feature-Group%20Directive Unit-Test
 * @link https://leaflet-ng2.yagajs.org/1.0.0/coverage/lcov-report/lib/feature-group.directive.js.html Test coverage
 * @link https://leaflet-ng2.yagajs.org/1.0.0/typedoc/classes/featuregroupdirective.html API documentation
 * @example https://leaflet-ng2.yagajs.org/1.0.0/examples/feature-group-directive
 */
var FeatureGroupDirective = /** @class */ (function (_super) {
    __extends(FeatureGroupDirective, _super);
    /**
     * From leaflet fired click event.
     * Use it with `<yaga-feature-group (click)="processEvent($event)">`
     * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-click Original Leaflet documentation
     */
    function FeatureGroupDirective(parentLayerGroupProvider, layerGroupProvider, layerProvider) {
        var _this = _super.call(this) || this;
        _this.parentLayerGroupProvider = parentLayerGroupProvider;
        /**
         * Two-Way bound property for the display status of the layer.
         * Use it with `<yaga-feature-group [(display)]="someValue">`
         * or `<yaga-feature-group (displayChange)="processEvent($event)">`
         */
        _this.displayChange = new core_1.EventEmitter();
        /**
         * From leaflet fired add event.
         * Use it with `<yaga-feature-group (layeradd)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-add Original Leaflet documentation
         */
        _this.layeraddEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired remove event.
         * Use it with `<yaga-feature-group (layerremove)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-remove Original Leaflet documentation
         */
        _this.layerremoveEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired add event.
         * Use it with `<yaga-feature-group (add)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-add Original Leaflet documentation
         */
        _this.addEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired remove event.
         * Use it with `<yaga-feature-group (remove)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-remove Original Leaflet documentation
         */
        _this.removeEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired popupopen event.
         * Use it with `<yaga-feature-group (popupopen)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-popupopen Original Leaflet documentation
         */
        _this.popupopenEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired popupclose event.
         * Use it with `<yaga-feature-group (popupclose)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-popupclose Original Leaflet documentation
         */
        _this.popupcloseEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired tooltipopen event.
         * Use it with `<yaga-feature-group (tooltipopen)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-tooltipopen Original Leaflet documentation
         */
        _this.tooltipopenEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired tooltipclose event.
         * Use it with `<yaga-feature-group (tooltipclose)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-tooltipclose Original Leaflet documentation
         */
        _this.tooltipcloseEvent = new core_1.EventEmitter();
        layerProvider.ref = _this;
        layerGroupProvider.ref = _this;
        _this.on("remove", function () {
            _this._map = null; // This seems to fix a bug in Leaflet
            _this.displayChange.emit(false);
        });
        _this.on("add", function () {
            _this.displayChange.emit(true);
        });
        _this.addTo(_this.parentLayerGroupProvider.ref);
        // Events
        _this.on("layeradd", function (event) {
            _this.layeraddEvent.emit(event);
        });
        _this.on("layerremove", function (event) {
            _this.layerremoveEvent.emit(event);
        });
        _this.on("add", function (event) {
            _this.addEvent.emit(event);
        });
        _this.on("remove", function (event) {
            _this.removeEvent.emit(event);
        });
        _this.on("popupopen", function (event) {
            _this.popupopenEvent.emit(event);
        });
        _this.on("popupclose", function (event) {
            _this.popupcloseEvent.emit(event);
        });
        _this.on("tooltipopen", function (event) {
            _this.tooltipopenEvent.emit(event);
        });
        _this.on("tooltipclose", function (event) {
            _this.tooltipcloseEvent.emit(event);
        });
        return _this;
    }
    /**
     * This function gets called from Angular on destroy of the html-component.
     * @link https://angular.io/docs/ts/latest/api/core/index/OnDestroy-class.html
     */
    FeatureGroupDirective.prototype.ngOnDestroy = function () {
        this.removeFrom(this.parentLayerGroupProvider.ref);
    };
    Object.defineProperty(FeatureGroupDirective.prototype, "display", {
        /**
         * Two-Way bound property for the display status of the layer.
         * Use it with `<yaga-feature-group [(display)]="someValue">` or `<yaga-feature-group [display]="someValue">`
         */
        get: function () {
            return !!(this._map);
        },
        /**
         * Two-Way bound property for the display status of the layer.
         * Use it with `<yaga-feature-group [(display)]="someValue">` or `<yaga-feature-group [display]="someValue">`
         */
        set: function (val) {
            if (val) {
                this.addTo(this.parentLayerGroupProvider.ref);
                return;
            }
            // TODO: proof and maybe enhance typedefinition
            this.parentLayerGroupProvider.ref.removeLayer(this);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FeatureGroupDirective.prototype, "attribution", {
        get: function () {
            return this.getAttribution() || "";
        },
        /**
         * Input for the attribution.
         * Use it with `<yaga-feature-group [attribution]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-attribution Original Leaflet documentation
         */
        set: function (val) {
            Eif (this._map && this._map.attributionControl) {
                if (this.getAttribution()) {
                    this._map.attributionControl
                        .removeAttribution(this.getAttribution());
                }
                this._map.attributionControl.addAttribution(val);
            }
            // TODO: add options to the official type definition
            this.options.attribution = val;
        },
        enumerable: true,
        configurable: true
    });
    FeatureGroupDirective.prototype.removeFrom = function (map) {
        this.displayChange.emit(false);
        return _super.prototype.removeFrom.call(this, map);
    };
    Object.defineProperty(FeatureGroupDirective.prototype, "style", {
        get: function () {
            return {};
        },
        /**
         * Input for the style.
         * Use it with `<yaga-feature-group [style]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#featuregroup-setstyle Original Leaflet documentation
         */
        set: function (val) {
            this.setStyle(val);
        },
        enumerable: true,
        configurable: true
    });
    __decorate([
        core_1.Output(),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "displayChange", void 0);
    __decorate([
        core_1.Output("layeradd"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "layeraddEvent", void 0);
    __decorate([
        core_1.Output("layerremove"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "layerremoveEvent", void 0);
    __decorate([
        core_1.Output("add"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "addEvent", void 0);
    __decorate([
        core_1.Output("remove"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "removeEvent", void 0);
    __decorate([
        core_1.Output("popupopen"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "popupopenEvent", void 0);
    __decorate([
        core_1.Output("popupclose"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "popupcloseEvent", void 0);
    __decorate([
        core_1.Output("tooltipopen"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "tooltipopenEvent", void 0);
    __decorate([
        core_1.Output("tooltipclose"),
        __metadata("design:type", core_1.EventEmitter)
    ], FeatureGroupDirective.prototype, "tooltipcloseEvent", void 0);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [Boolean])
    ], FeatureGroupDirective.prototype, "display", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], FeatureGroupDirective.prototype, "attribution", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], FeatureGroupDirective.prototype, "style", null);
    FeatureGroupDirective = __decorate([
        core_1.Directive({
            providers: [layer_group_provider_1.LayerGroupProvider, layer_provider_1.LayerProvider],
            selector: "yaga-feature-group",
        }),
        __param(0, core_1.SkipSelf()),
        __metadata("design:paramtypes", [layer_group_provider_1.LayerGroupProvider,
            layer_group_provider_1.LayerGroupProvider,
            layer_provider_1.LayerProvider])
    ], FeatureGroupDirective);
    return FeatureGroupDirective;
}(leaflet_1.FeatureGroup));
exports.FeatureGroupDirective = FeatureGroupDirective;
//# sourceMappingURL=feature-group.directive.js.map