@jmarcelof/leaflet-ng2
Version:
Angular2 module for Leaflet
299 lines • 13.2 kB
JavaScript
;
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;
if (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) {
if (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/latest/browser-test?grep=Feature-Group%20Directive Unit-Test
* @link https://leaflet-ng2.yagajs.org/latest/coverage/lcov-report/lib/feature-group.directive.js.html Test coverage
* @link https://leaflet-ng2.yagajs.org/latest/typedoc/classes/featuregroupdirective.html API documentation
* @example https://leaflet-ng2.yagajs.org/latest/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) {
if (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