UNPKG

@yaga/leaflet-ng2

Version:
364 lines 14.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AttributionControlDirective = void 0; const core_1 = require("@angular/core"); const leaflet_1 = require("leaflet"); const consts_1 = require("./consts"); const map_provider_1 = require("./map.provider"); const mouse_event_helper_1 = require("./mouse-event-helper"); const i0 = require("@angular/core"); const i1 = require("./map.provider"); /** * 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-attribution-control * [(display)]="..." * [(zIndex)]="..." * [(position)]="..." * [(prefix)]="..." * [(attributions)]="..." * * (add)="..." * (remove)="..." * (click)="..." * (dblclick)="..." * (mousedown)="..." * (mouseover)="..." * (mouseout)="..." * > * </yaga-attribution-control> * </yaga-map> * ``` * * @link http://leafletjs.com/reference-1.2.0.html#control-attribution Original Leaflet documentation * @link https://leaflet-ng2.yagajs.org/latest/browser-test?grep=Attribution-Control%20Directive Unit-Test * @link https://leaflet-ng2.yagajs.org/latest/coverage/lcov-report/lib/attribution-control.directive.js.html * Test coverage * @link https://leaflet-ng2.yagajs.org/latest/typedoc/classes/attributioncontroldirective.html API documentation * @example https://leaflet-ng2.yagajs.org/latest/examples/attribution-control-directive/ */ class AttributionControlDirective extends leaflet_1.Control.Attribution { constructor(mapProvider) { super({ prefix: consts_1.ATTRIBUTION_PREFIX }); this.mapProvider = mapProvider; /** * Two-Way bound property for the display status of the control. * Use it with `<yaga-attribution-control [(display)]="someValue">` * or `<yaga-attribution-control (displayChange)="processEvent($event)">` */ this.displayChange = new core_1.EventEmitter(); /** * Two-Way bound property for the position of the control. * Use it with `<yaga-attribution-control [(position)]="someValue">` * or `<yaga-attribution-control (positionChange)="processEvent($event)">` */ this.positionChange = new core_1.EventEmitter(); /** * Two-Way bound property for the prefix of the control. * Use it with `<yaga-attribution-control [(prefix)]="someValue">` * or `<yaga-attribution-control (prefixChange)="processEvent($event)">` */ this.prefixChange = new core_1.EventEmitter(); /** * Two-Way bound property for the list of attributions of the control. * Use it with `<yaga-attribution-control [(attributions)]="someValue">` * or `<yaga-attribution-control (attributionsChange)="processEvent($event)">` */ this.attributionsChange = new core_1.EventEmitter(); /** * From leaflet fired add event. * Use it with `<yaga-attribution-control (add)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-add Original Leaflet documentation */ this.addEvent = new core_1.EventEmitter(); /** * From leaflet fired remove event. * Use it with `<yaga-attribution-control (remove)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-remove Original Leaflet documentation */ this.removeEvent = new core_1.EventEmitter(); /** * From leaflet fired click event. * Use it with `<yaga-attribution-control (click)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-click Original Leaflet documentation */ this.clickEvent = new core_1.EventEmitter(); /** * From leaflet fired dblclick event. * Use it with `<yaga-attribution-control (dblclick)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-dblclick Original Leaflet documentation */ this.dblclickEvent = new core_1.EventEmitter(); /** * From leaflet fired mousedown event. * Use it with `<yaga-attribution-control (mousedown)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-mousedown Original Leaflet documentation */ this.mousedownEvent = new core_1.EventEmitter(); /** * From leaflet fired mouseover event. * Use it with `<yaga-attribution-control (mouseover)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-mouseover Original Leaflet documentation */ this.mouseoverEvent = new core_1.EventEmitter(); /** * From leaflet fired mouseout event. * Use it with `<yaga-attribution-control (mouseout)="processEvent($event)">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-mouseout Original Leaflet documentation */ this.mouseoutEvent = new core_1.EventEmitter(); mapProvider.ref.addControl(this); // Events this.getContainer().addEventListener("click", (event) => { this.clickEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, this._map)); }); this.getContainer().addEventListener("dblclick", (event) => { this.dblclickEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, this._map)); }); this.getContainer().addEventListener("mousedown", (event) => { this.mousedownEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, this._map)); }); this.getContainer().addEventListener("mouseover", (event) => { this.mouseoverEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, this._map)); }); this.getContainer().addEventListener("mouseout", (event) => { this.mouseoutEvent.emit(mouse_event_helper_1.enhanceMouseEvent(event, this._map)); }); } /** * Internal method to provide the removal of the control in Leaflet, when removing it from the Angular template */ ngOnDestroy() { this.mapProvider.ref.removeControl(this); } /** * Derived remove function */ remove() { /* tslint:disable */ super.remove(); this.displayChange.emit(false); this.removeEvent.emit({ target: this, type: "remove" }); return this; } /** * Derived addTo function */ addTo(map) { /* tslint:disable */ super.addTo(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-attribution-setposition Original Leaflet documentation */ setPosition(val) { super.setPosition(val); this.positionChange.emit(val); return this; } /** * Two-Way bound property for the opacity. * Use it with `<yaga-attribution-control [(opacity)]="someValue">` * or `<yaga-attribution-control [opacity]="someValue">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-opacity Original Leaflet documentation */ set opacity(val) { if (typeof val === "number") { this.getContainer().style.opacity = val.toString(); return; } this.getContainer().style.opacity = ""; } get opacity() { if (this.getContainer().style.opacity !== undefined && this.getContainer().style.opacity !== null) { return parseFloat(this.getContainer().style.opacity); } return; } /** * Two-Way bound property for the display state. * Use it with `<yaga-attribution-control [(display)]="someValue">` * or `<yaga-attribution-control [display]="someValue">` */ set display(val) { if (!this._map) { // No map available... return; } if (val) { this.getContainer().style.display = ""; return; } this.getContainer().style.display = "none"; return; } get display() { return !!this._map && this.getContainer().style.display !== "none"; } /** * Two-Way bound property for the position. * Use it with `<yaga-attribution-control [(position)]="someValue">` * or `<yaga-attribution-control [position]="someValue">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-position Original Leaflet documentation */ set position(val) { this.setPosition(val); } get position() { return this.getPosition(); } /** * Input for the zIndex of the control. * Use it with `<yaga-attribution-control [zIndex]="someValue">` */ set zIndex(zIndex) { if (typeof zIndex === "number") { this.getContainer().style.zIndex = zIndex.toString(); return; } this.getContainer().style.zIndex = ""; } get zIndex() { if (this.getContainer().style.zIndex !== undefined && this.getContainer().style.zIndex !== null) { return parseInt(this.getContainer().style.zIndex, 10); } return undefined; } /** * Derived method of the original setPrefix. * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-setprefix Original Leaflet documentation */ setPrefix(prefix) { super.setPrefix(prefix); this.prefixChange.emit(prefix); return this; } /** * Two-Way bound property for the prefix. * Use it with `<yaga-attribution-control [(prefix)]="someValue">` * or `<yaga-attribution-control [prefix]="someValue">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-prefix Original Leaflet documentation */ set prefix(val) { this.setPrefix(val); } get prefix() { return this.options.prefix; } /** * Derived method of the original addAttribution. * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-addattribution Original Leaflet documentation */ addAttribution(val) { super.addAttribution(val); this.attributionsChange.emit(this.attributions); return this; } /** * Derived method of the original removeAttribution. * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-removeattribution * Original Leaflet documentation */ removeAttribution(val) { super.removeAttribution(val); this.attributionsChange.emit(this.attributions); return this; } /** * Two-Way bound property for the attributions. * Use it with `<yaga-attribution-control [(attributions)]="someValue">` * or `<yaga-attribution-control [attributions]="someValue">` * @link http://leafletjs.com/reference-1.2.0.html#control-attribution-attributions Original Leaflet documentation */ set attributions(val) { this.removeAllAttributions(true); for (const attr of val) { super.addAttribution(attr); } this.attributionsChange.emit(this.attributions); } get attributions() { const keys = Object.keys(this._attributions); const arr = []; for (const key of keys) { if (this._attributions[key] === 1) { arr.push(key); } } return arr; } /** * Self written method to provide the removal of all attributions in a single step */ removeAllAttributions(silent) { const keys = Object.keys(this._attributions); for (const key of keys) { super.removeAttribution(key); } if (silent) { return this; } this.attributionsChange.emit([]); return this; } } exports.AttributionControlDirective = AttributionControlDirective; AttributionControlDirective.ɵfac = function AttributionControlDirective_Factory(t) { return new (t || AttributionControlDirective)(i0.ɵɵdirectiveInject(i1.MapProvider)); }; AttributionControlDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: AttributionControlDirective, selectors: [["yaga-attribution-control"]], inputs: { opacity: "opacity", display: "display", position: "position", zIndex: "zIndex", prefix: "prefix", attributions: "attributions" }, outputs: { displayChange: "displayChange", positionChange: "positionChange", prefixChange: "prefixChange", attributionsChange: "attributionsChange", addEvent: "add", removeEvent: "remove", clickEvent: "click", dblclickEvent: "dblclick", mousedownEvent: "mousedown", mouseoverEvent: "mouseover", mouseoutEvent: "mouseout" }, features: [i0.ɵɵInheritDefinitionFeature] }); (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AttributionControlDirective, [{ type: core_1.Directive, args: [{ selector: "yaga-attribution-control", }] }], function () { return [{ type: i1.MapProvider }]; }, { displayChange: [{ type: core_1.Output }], positionChange: [{ type: core_1.Output }], prefixChange: [{ type: core_1.Output }], attributionsChange: [{ type: core_1.Output }], addEvent: [{ type: core_1.Output, args: ["add"] }], removeEvent: [{ type: core_1.Output, args: ["remove"] }], clickEvent: [{ type: core_1.Output, args: ["click"] }], dblclickEvent: [{ type: core_1.Output, args: ["dblclick"] }], mousedownEvent: [{ type: core_1.Output, args: ["mousedown"] }], mouseoverEvent: [{ type: core_1.Output, args: ["mouseover"] }], mouseoutEvent: [{ type: core_1.Output, args: ["mouseout"] }], opacity: [{ type: core_1.Input }], display: [{ type: core_1.Input }], position: [{ type: core_1.Input }], zIndex: [{ type: core_1.Input }], prefix: [{ type: core_1.Input }], attributions: [{ type: core_1.Input }] }); })(); //# sourceMappingURL=attribution-control.directive.js.map