@asymmetrik/ngx-leaflet-draw
Version:
Angular.io component for the draw plugin for Leaflet
223 lines (217 loc) • 12.3 kB
JavaScript
/*! @asymmetrik/ngx-leaflet-draw - 5.0.1 - Copyright Asymmetrik, Ltd. 2007-2019 - All Rights Reserved. + */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@asymmetrik/ngx-leaflet'), require('leaflet'), require('leaflet-draw')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@asymmetrik/ngx-leaflet', 'leaflet', 'leaflet-draw'], factory) :
(global = global || self, factory(global.ngxLeafletDraw = {}, global.ng.core, global.ngxLeaflet, global.L));
}(this, function (exports, core, ngxLeaflet, L) { 'use strict';
var __decorate = (undefined && undefined.__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 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var LeafletDrawDirective = /** @class */ (function () {
function LeafletDrawDirective(leafletDirective, zone) {
this.zone = zone;
this.drawOptions = null;
// Configure callback function for the map
this.drawReady = new core.EventEmitter();
// Draw Events
this.onDrawCreated = new core.EventEmitter();
this.onDrawEdited = new core.EventEmitter();
this.onDrawDeleted = new core.EventEmitter();
this.onDrawStart = new core.EventEmitter();
this.onDrawStop = new core.EventEmitter();
this.onDrawVertex = new core.EventEmitter();
this.onDrawEditStart = new core.EventEmitter();
this.onDrawEditMove = new core.EventEmitter();
this.onDrawEditResize = new core.EventEmitter();
this.onDrawEditVertex = new core.EventEmitter();
this.onDrawEditStop = new core.EventEmitter();
this.onDrawDeleteStart = new core.EventEmitter();
this.onDrawDeleteStop = new core.EventEmitter();
this.onDrawToolbarOpened = new core.EventEmitter();
this.onDrawToolbarClosed = new core.EventEmitter();
this.onDrawMarkerContext = new core.EventEmitter();
this.leafletDirective = new ngxLeaflet.LeafletDirectiveWrapper(leafletDirective);
}
LeafletDrawDirective.prototype.ngOnInit = function () {
var _this = this;
this.leafletDirective.init();
// Initialize the draw options (in case they weren't provided)
this.drawOptions = this.initializeDrawOptions(this.drawOptions);
// Create the control
this.drawControl = new L.Control.Draw(this.drawOptions);
// Pull out the feature group for convenience
this.featureGroup = this.drawOptions.edit.featureGroup;
// Add the control to the map
this.leafletDirective.getMap().addControl(this.drawControl);
// Register the main handler for events coming from the draw plugin
var map = this.leafletDirective.getMap();
map.on(L.Draw.Event.CREATED, function (e) {
var layer = e.layer;
_this.featureGroup.addLayer(layer);
ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawCreated, e);
});
// add draw event pass throughs
map.on(L.Draw.Event.EDITED, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawEdited, e); });
map.on(L.Draw.Event.DELETED, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawDeleted, e); });
map.on(L.Draw.Event.DRAWSTART, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawStart, e); });
map.on(L.Draw.Event.DRAWSTOP, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawStop, e); });
map.on(L.Draw.Event.EDITSTART, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawEditStart, e); });
map.on(L.Draw.Event.EDITMOVE, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawEditMove, e); });
map.on(L.Draw.Event.EDITRESIZE, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawEditResize, e); });
map.on(L.Draw.Event.EDITVERTEX, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawEditVertex, e); });
map.on(L.Draw.Event.EDITSTOP, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawEditStop, e); });
map.on(L.Draw.Event.DELETESTART, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawDeleteStart, e); });
map.on(L.Draw.Event.DELETESTOP, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawDeleteStop, e); });
map.on(L.Draw.Event.TOOLBAROPENED, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawToolbarOpened, e); });
map.on(L.Draw.Event.TOOLBARCLOSED, function (e) { return ngxLeaflet.LeafletUtil.handleEvent(_this.zone, _this.onDrawToolbarClosed, e); });
// Notify others that the draw control has been created
this.drawReady.emit(this.drawControl);
};
LeafletDrawDirective.prototype.ngOnDestroy = function () {
this.leafletDirective.getMap().removeControl(this.drawControl);
};
LeafletDrawDirective.prototype.ngOnChanges = function (changes) {
// No changes being handled currently
};
LeafletDrawDirective.prototype.getDrawControl = function () {
return this.drawControl;
};
LeafletDrawDirective.prototype.initializeDrawOptions = function (options) {
// Ensure the options have a featureGroup
if (null == options) {
options = {
edit: null
};
}
if (null == options.edit) {
options.edit = {
featureGroup: null
};
}
if (null == options.edit.featureGroup) {
// No feature group was provided, so we're going to add it ourselves
options.edit.featureGroup = L.featureGroup();
this.leafletDirective.getMap().addLayer(options.edit.featureGroup);
}
return options;
};
__decorate([
core.Input('leafletDrawOptions'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "drawOptions", void 0);
__decorate([
core.Output('leafletDrawReady'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "drawReady", void 0);
__decorate([
core.Output('leafletDrawCreated'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawCreated", void 0);
__decorate([
core.Output('leafletDrawEdited'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawEdited", void 0);
__decorate([
core.Output('leafletDrawDeleted'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawDeleted", void 0);
__decorate([
core.Output('leafletDrawStart'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawStart", void 0);
__decorate([
core.Output('leafletDrawStop'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawStop", void 0);
__decorate([
core.Output('leafletDrawVertex'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawVertex", void 0);
__decorate([
core.Output('leafletDrawEditStart'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawEditStart", void 0);
__decorate([
core.Output('leafletDrawEditMove'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawEditMove", void 0);
__decorate([
core.Output('leafletDrawEditResize'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawEditResize", void 0);
__decorate([
core.Output('leafletDrawEditVertex'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawEditVertex", void 0);
__decorate([
core.Output('leafletDrawEditStop'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawEditStop", void 0);
__decorate([
core.Output('leafletDrawDeleteStart'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawDeleteStart", void 0);
__decorate([
core.Output('leafletDrawDeleteStop'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawDeleteStop", void 0);
__decorate([
core.Output('leafletDrawToolbarOpened'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawToolbarOpened", void 0);
__decorate([
core.Output('leafletDrawToolbarClosed'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawToolbarClosed", void 0);
__decorate([
core.Output('leafletDrawMarkerContext'),
__metadata("design:type", Object)
], LeafletDrawDirective.prototype, "onDrawMarkerContext", void 0);
LeafletDrawDirective = __decorate([
core.Directive({
selector: '[leafletDraw]'
}),
__metadata("design:paramtypes", [ngxLeaflet.LeafletDirective, core.NgZone])
], LeafletDrawDirective);
return LeafletDrawDirective;
}());
var __decorate$1 = (undefined && undefined.__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 LeafletDrawModule = /** @class */ (function () {
function LeafletDrawModule() {
}
LeafletDrawModule_1 = LeafletDrawModule;
LeafletDrawModule.forRoot = function () {
return { ngModule: LeafletDrawModule_1, providers: [] };
};
var LeafletDrawModule_1;
LeafletDrawModule = LeafletDrawModule_1 = __decorate$1([
core.NgModule({
imports: [
ngxLeaflet.LeafletModule
],
exports: [
LeafletDrawDirective
],
declarations: [
LeafletDrawDirective
]
})
], LeafletDrawModule);
return LeafletDrawModule;
}());
exports.LeafletDrawDirective = LeafletDrawDirective;
exports.LeafletDrawModule = LeafletDrawModule;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=ngx-leaflet-draw.js.map