all files / lib/ scale-control.directive.js

92.75% Statements 128/138
60.71% Branches 34/56
93.94% Functions 31/33
95.42% Lines 125/131
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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412            18× 18×   18×   25×                                                                           30× 30×           30×           30×           30×           30×           30×           30×           30×           30×           30×           30× 30×   30×   30×   30×   30×   30×   30×                   45× 45× 45× 45×           36× 36× 36× 36×                                                                                                                                                                                                                                                                                                                                                        
"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var leaflet_1 = require("leaflet");
var map_provider_1 = require("./map.provider");
var mouse_event_helper_1 = require("./mouse-event-helper");
/**
 * Angular2 directive for the attribution-control of Leaflet.
 *
 * *You can use this directive in an Angular2 template after importing `YagaModule`.*
 *
 * How to use in a template:
 * ```html
 * <yaga-map>
 *     <yaga-scale-control
 *         [(display)]="..."
 *         [(zIndex)]="..."
 *         [(position)]="..."
 *
 *         [metric]="..."
 *         [imperial]="..."
 *         [maxWidth]="..."
 *
 *         (add)="..."
 *         (remove)="..."
 *         (click)="..."
 *         (dblclick)="..."
 *         (mousedown)="..."
 *         (mouseover)="..."
 *         (mouseout)="..."
 *         >
 *     </yaga-scale-control>
 * </yaga-map>
 * ```
 *
 * @link http://leafletjs.com/reference-1.2.0.html#control-scale Original Leaflet documentation
 * @link https://leaflet-ng2.yagajs.org/1.0.0/browser-test?grep=Scale-Control%20Directive Unit-Test
 * @link https://leaflet-ng2.yagajs.org/1.0.0/coverage/lcov-report/lib/attribution-control.directive.js.html
 * Test coverage
 * @link https://leaflet-ng2.yagajs.org/1.0.0/typedoc/classes/scalecontroldirective.html API documentation
 * @example https://leaflet-ng2.yagajs.org/1.0.0/examples/scale-control-directive/
 */
var ScaleControlDirective = /** @class */ (function (_super) {
    __extends(ScaleControlDirective, _super);
    function ScaleControlDirective(mapProvider) {
        var _this = _super.call(this) || this;
        _this.mapProvider = mapProvider;
        /**
         * Two-Way bound property for the display status of the control.
         * Use it with `<yaga-scale-control [(display)]="someValue">`
         * or `<yaga-scale-control (displayChange)="processEvent($event)">`
         */
        _this.displayChange = new core_1.EventEmitter();
        /**
         * Two-Way bound property for the zIndex of the control.
         * Use it with `<yaga-scale-control [(zIndex)]="someValue">`
         * or `<yaga-scale-control (zIndexChange)="processEvent($event)">`
         */
        _this.zIndexChange = new core_1.EventEmitter();
        /**
         * Two-Way bound property for the position of the control.
         * Use it with `<yaga-scale-control [(position)]="someValue">`
         * or `<yaga-scale-control (positionChange)="processEvent($event)">`
         */
        _this.positionChange = new core_1.EventEmitter();
        /**
         * From leaflet fired add event.
         * Use it with `<yaga-scale-control (add)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-add Original Leaflet documentation
         */
        _this.addEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired remove event.
         * Use it with `<yaga-scale-control (remove)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-remove Original Leaflet documentation
         */
        _this.removeEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired click event.
         * Use it with `<yaga-scale-control (click)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-click Original Leaflet documentation
         */
        _this.clickEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired dblclick event.
         * Use it with `<yaga-scale-control (dblclick)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-dblclick Original Leaflet documentation
         */
        _this.dblclickEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired mousedown event.
         * Use it with `<yaga-scale-control (mousedown)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-mousedown Original Leaflet documentation
         */
        _this.mousedownEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired mouseover event.
         * Use it with `<yaga-scale-control (mouseover)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-mouseover Original Leaflet documentation
         */
        _this.mouseoverEvent = new core_1.EventEmitter();
        /**
         * From leaflet fired mouseout event.
         * Use it with `<yaga-scale-control (mouseout)="processEvent($event)">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-mouseout Original Leaflet documentation
         */
        _this.mouseoutEvent = new core_1.EventEmitter();
        _this.mapProvider.ref.addControl(_this);
        // Events
        _this.getContainer().addEventListener("click", function (event) {
            _this.clickEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, _this._map));
        });
        _this.getContainer().addEventListener("dblclick", function (event) {
            _this.dblclickEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, _this._map));
        });
        _this.getContainer().addEventListener("mousedown", function (event) {
            _this.mousedownEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, _this._map));
        });
        _this.getContainer().addEventListener("mouseover", function (event) {
            _this.mouseoverEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, _this._map));
        });
        _this.getContainer().addEventListener("mouseout", function (event) {
            _this.mouseoutEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, _this._map));
        });
        return _this;
    }
    /**
     * Internal method to provide the removal of the control in Leaflet, when removing it from the Angular template
     */
    ScaleControlDirective.prototype.ngOnDestroy = function () {
        this.mapProvider.ref.removeControl(this);
    };
    /**
     * Derived remove function
     */
    ScaleControlDirective.prototype.remove = function () {
        /* tslint:disable */
        _super.prototype.remove.call(this);
        this.displayChange.emit(false);
        this.removeEvent.emit({ target: this, type: "remove" });
        return this;
    };
    /**
     * Derived addTo function
     */
    ScaleControlDirective.prototype.addTo = function (map) {
        /* tslint:disable */
        _super.prototype.addTo.call(this, map);
        this.displayChange.emit(true);
        this.addEvent.emit({ target: this, type: "add" });
        return this;
    };
    /**
     * Derived method of the original setPosition.
     * @link http://leafletjs.com/reference-1.2.0.html#control-scale-setposition Original Leaflet documentation
     */
    ScaleControlDirective.prototype.setPosition = function (val) {
        _super.prototype.setPosition.call(this, val);
        this.positionChange.emit(val);
        return this;
    };
    Object.defineProperty(ScaleControlDirective.prototype, "opacity", {
        get: function () {
            var val = this.getContainer().style.opacity;
            Eif (typeof val === "string") {
                return parseFloat(val);
            }
        },
        /**
         * Two-Way bound property for the opacity.
         * Use it with `<yaga-scale-control [(opacity)]="someValue">`
         * or `<yaga-scale-control [opacity]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-opacity Original Leaflet documentation
         */
        set: function (val) {
            Eif (typeof val === "number") {
                this.getContainer().style.opacity = val.toString();
                return;
            }
            this.getContainer().style.opacity = null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleControlDirective.prototype, "display", {
        get: function () {
            return !!this._map && this.getContainer().style.display !== "none";
        },
        /**
         * Two-Way bound property for the display state.
         * Use it with `<yaga-scale-control [(display)]="someValue">`
         * or `<yaga-scale-control [display]="someValue">`
         */
        set: function (val) {
            Iif (!this._map) {
                // No map available...
                return;
            }
            if (val) {
                this.getContainer().style.display = "";
                return;
            }
            this.getContainer().style.display = "none";
            return;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleControlDirective.prototype, "position", {
        get: function () {
            return this.getPosition();
        },
        /**
         * Two-Way bound property for the position.
         * Use it with `<yaga-scale-control [(position)]="someValue">`
         * or `<yaga-scale-control [position]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-position Original Leaflet documentation
         */
        set: function (val) {
            this.setPosition(val);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleControlDirective.prototype, "zIndex", {
        get: function () {
            var val = this.getContainer().style.zIndex;
            Eif (typeof val === "string") {
                return parseInt(val, 10);
            }
        },
        /**
         * Two-Way bound property for the zIndex of the control.
         * Use it with `<yaga-scale-control [(zIndex)]="someValue">`
         * or `<yaga-scale-control (zIndexChange)="processEvent($event)">`
         */
        set: function (zIndex) {
            Eif (typeof zIndex === "number") {
                this.getContainer().style.zIndex = zIndex.toString();
                return;
            }
            this.getContainer().style.zIndex = null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleControlDirective.prototype, "maxWidth", {
        get: function () {
            return this.options.maxWidth;
        },
        /**
         * Input for scale max-width.
         * Use it with `<yaga-scale-control [(maxWidth)]="someValue">`
         * or `<yaga-scale-control [maxWidth]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-maxwidth Original Leaflet documentation
         */
        set: function (val) {
            this.options.maxWidth = val;
            this._update();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleControlDirective.prototype, "metric", {
        get: function () {
            return !!this.options.metric;
        },
        /**
         * Input for state of metric-scale state.
         * Use it with `<yaga-scale-control [(metric)]="someValue">`
         * or `<yaga-scale-control [metric]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-metric Original Leaflet documentation
         */
        set: function (val) {
            while (this.getContainer().hasChildNodes()) {
                this.getContainer().removeChild(this.getContainer().lastChild);
            }
            this.options.metric = val;
            this._addScales(this.options, "leaflet-control-scale-line", this.getContainer());
            this._update();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleControlDirective.prototype, "imperial", {
        get: function () {
            return !!this.options.imperial;
        },
        /**
         * Input for state of imperial-scale state.
         * Use it with `<yaga-scale-control [(imperial)]="someValue">`
         * or `<yaga-scale-control [imperial]="someValue">`
         * @link http://leafletjs.com/reference-1.2.0.html#control-scale-imperial Original Leaflet documentation
         */
        set: function (val) {
            while (this.getContainer().hasChildNodes()) {
                this.getContainer().removeChild(this.getContainer().lastChild);
            }
            this.options.imperial = val;
            this._addScales(this.options, "leaflet-control-scale-line", this.getContainer());
            this._update();
        },
        enumerable: true,
        configurable: true
    });
    __decorate([
        core_1.Output(),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "displayChange", void 0);
    __decorate([
        core_1.Output(),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "zIndexChange", void 0);
    __decorate([
        core_1.Output(),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "positionChange", void 0);
    __decorate([
        core_1.Output("add"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "addEvent", void 0);
    __decorate([
        core_1.Output("remove"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "removeEvent", void 0);
    __decorate([
        core_1.Output("click"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "clickEvent", void 0);
    __decorate([
        core_1.Output("dblclick"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "dblclickEvent", void 0);
    __decorate([
        core_1.Output("mousedown"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "mousedownEvent", void 0);
    __decorate([
        core_1.Output("mouseover"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "mouseoverEvent", void 0);
    __decorate([
        core_1.Output("mouseout"),
        __metadata("design:type", core_1.EventEmitter)
    ], ScaleControlDirective.prototype, "mouseoutEvent", void 0);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], ScaleControlDirective.prototype, "opacity", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [Boolean])
    ], ScaleControlDirective.prototype, "display", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], ScaleControlDirective.prototype, "position", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], ScaleControlDirective.prototype, "zIndex", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], ScaleControlDirective.prototype, "maxWidth", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [Boolean])
    ], ScaleControlDirective.prototype, "metric", null);
    __decorate([
        core_1.Input(),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [Boolean])
    ], ScaleControlDirective.prototype, "imperial", null);
    ScaleControlDirective = __decorate([
        core_1.Directive({
            selector: "yaga-scale-control",
        }),
        __metadata("design:paramtypes", [map_provider_1.MapProvider])
    ], ScaleControlDirective);
    return ScaleControlDirective;
}(leaflet_1.Control.Scale));
exports.ScaleControlDirective = ScaleControlDirective;
//# sourceMappingURL=scale-control.directive.js.map