UNPKG

@asymmetrik/ngx-leaflet-draw

Version:

Angular.io component for the draw plugin for Leaflet

183 lines 9.26 kB
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); }; import { Directive, EventEmitter, Input, NgZone, Output } from '@angular/core'; import * as L from 'leaflet'; import 'leaflet-draw'; import { LeafletDirective, LeafletDirectiveWrapper, LeafletUtil } from '@asymmetrik/ngx-leaflet'; var LeafletDrawDirective = /** @class */ (function () { function LeafletDrawDirective(leafletDirective, zone) { this.zone = zone; this.drawOptions = null; // Configure callback function for the map this.drawReady = new EventEmitter(); // Draw Events this.onDrawCreated = new EventEmitter(); this.onDrawEdited = new EventEmitter(); this.onDrawDeleted = new EventEmitter(); this.onDrawStart = new EventEmitter(); this.onDrawStop = new EventEmitter(); this.onDrawVertex = new EventEmitter(); this.onDrawEditStart = new EventEmitter(); this.onDrawEditMove = new EventEmitter(); this.onDrawEditResize = new EventEmitter(); this.onDrawEditVertex = new EventEmitter(); this.onDrawEditStop = new EventEmitter(); this.onDrawDeleteStart = new EventEmitter(); this.onDrawDeleteStop = new EventEmitter(); this.onDrawToolbarOpened = new EventEmitter(); this.onDrawToolbarClosed = new EventEmitter(); this.onDrawMarkerContext = new EventEmitter(); this.leafletDirective = new 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); LeafletUtil.handleEvent(_this.zone, _this.onDrawCreated, e); }); // add draw event pass throughs map.on(L.Draw.Event.EDITED, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawEdited, e); }); map.on(L.Draw.Event.DELETED, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawDeleted, e); }); map.on(L.Draw.Event.DRAWSTART, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawStart, e); }); map.on(L.Draw.Event.DRAWSTOP, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawStop, e); }); map.on(L.Draw.Event.EDITSTART, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawEditStart, e); }); map.on(L.Draw.Event.EDITMOVE, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawEditMove, e); }); map.on(L.Draw.Event.EDITRESIZE, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawEditResize, e); }); map.on(L.Draw.Event.EDITVERTEX, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawEditVertex, e); }); map.on(L.Draw.Event.EDITSTOP, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawEditStop, e); }); map.on(L.Draw.Event.DELETESTART, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawDeleteStart, e); }); map.on(L.Draw.Event.DELETESTOP, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawDeleteStop, e); }); map.on(L.Draw.Event.TOOLBAROPENED, function (e) { return LeafletUtil.handleEvent(_this.zone, _this.onDrawToolbarOpened, e); }); map.on(L.Draw.Event.TOOLBARCLOSED, function (e) { return 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([ Input('leafletDrawOptions'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "drawOptions", void 0); __decorate([ Output('leafletDrawReady'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "drawReady", void 0); __decorate([ Output('leafletDrawCreated'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawCreated", void 0); __decorate([ Output('leafletDrawEdited'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawEdited", void 0); __decorate([ Output('leafletDrawDeleted'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawDeleted", void 0); __decorate([ Output('leafletDrawStart'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawStart", void 0); __decorate([ Output('leafletDrawStop'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawStop", void 0); __decorate([ Output('leafletDrawVertex'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawVertex", void 0); __decorate([ Output('leafletDrawEditStart'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawEditStart", void 0); __decorate([ Output('leafletDrawEditMove'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawEditMove", void 0); __decorate([ Output('leafletDrawEditResize'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawEditResize", void 0); __decorate([ Output('leafletDrawEditVertex'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawEditVertex", void 0); __decorate([ Output('leafletDrawEditStop'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawEditStop", void 0); __decorate([ Output('leafletDrawDeleteStart'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawDeleteStart", void 0); __decorate([ Output('leafletDrawDeleteStop'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawDeleteStop", void 0); __decorate([ Output('leafletDrawToolbarOpened'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawToolbarOpened", void 0); __decorate([ Output('leafletDrawToolbarClosed'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawToolbarClosed", void 0); __decorate([ Output('leafletDrawMarkerContext'), __metadata("design:type", Object) ], LeafletDrawDirective.prototype, "onDrawMarkerContext", void 0); LeafletDrawDirective = __decorate([ Directive({ selector: '[leafletDraw]' }), __metadata("design:paramtypes", [LeafletDirective, NgZone]) ], LeafletDrawDirective); return LeafletDrawDirective; }()); export { LeafletDrawDirective }; //# sourceMappingURL=leaflet-draw.directive.js.map