medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
117 lines • 5.06 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as MedsurfDraw from "../../public-api";
import { BaseGenerator } from "../../bases/generators/BaseGenerator";
import { LineGeneratorModel } from "./LineGenerator";
var PolygonGeneratorModel = (function (_super) {
__extends(PolygonGeneratorModel, _super);
function PolygonGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PolygonGeneratorModel;
}(LineGeneratorModel));
export { PolygonGeneratorModel };
var PolygonGenerator = (function (_super) {
__extends(PolygonGenerator, _super);
function PolygonGenerator(model) {
var _this = _super.call(this, model) || this;
_this.target.modeInteraction.setModeItem("drawing");
_this._lineGenerator = new MedsurfDraw.LineGenerator(_this.data);
_this._lineGenerator.once("startGenerator", _this.start, _this);
_this._lineGenerator.once("endGenerator", _this.endLineGenerator, _this);
_this._lineGenerator.once("abortGenerator", _this.abortLineGenerator, _this);
return _this;
}
PolygonGenerator.prototype.end = function () {
if (this._lineGenerator) {
this._lineGenerator.removeAllListeners();
}
_super.prototype.end.call(this);
};
PolygonGenerator.prototype.destroy = function (options) {
this.end();
if (this._lineGenerator) {
this._lineGenerator.destroy();
}
};
PolygonGenerator.prototype.endGenerator = function () {
_super.prototype.endGenerator.call(this);
this.target.sortChildren();
this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode);
};
PolygonGenerator.prototype.abortGenerator = function () {
_super.prototype.abortGenerator.call(this);
this.target.getImageObjects()
.filter(function (imageObject) { return imageObject.modeInteraction.lastMode.startsWith('draw_') && imageObject.modeInteraction.lastMode.endsWith('_new'); })
.forEach(function (imageObject) {
imageObject.modeInteraction.setMode("delete_draw");
});
this.target.sortChildren();
this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode);
};
PolygonGenerator.prototype._setupGenerator = function (positionPoint) {
this._lineGenerator = new MedsurfDraw.LineGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
bezierCourve: this.bezierCourve,
stickMode: this.stickMode,
startElement: positionPoint
});
this._lineGenerator.once("endGenerator", this.endLineGenerator, this);
this._lineGenerator.once("abortGenerator", this.abortLineGenerator, this);
};
PolygonGenerator.prototype.endLineGenerator = function () {
this._lineGenerator.startPositionPointElement.modeInteraction.setMode("draw_select");
this._lineGenerator.endPositionPointElement.modeInteraction.setMode("draw_select");
this._lineGenerator.lineElement.modeInteraction.setMode("draw_select");
this._setupGenerator(this._lineGenerator.endPositionPointElement);
};
PolygonGenerator.prototype.abortLineGenerator = function () {
this.emit("abortGenerator");
this.destroy();
};
Object.defineProperty(PolygonGenerator.prototype, "drawInteraction", {
get: function () {
return this._lineGenerator.drawInteraction;
},
enumerable: false,
configurable: true
});
Object.defineProperty(PolygonGenerator.prototype, "bezierCourve", {
get: function () {
return this.data.bezierCourve;
},
set: function (value) {
this.data.bezierCourve = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(PolygonGenerator.prototype, "stickMode", {
get: function () {
return this.data.stickMode;
},
set: function (value) {
this.data.stickMode = value;
},
enumerable: false,
configurable: true
});
return PolygonGenerator;
}(BaseGenerator));
export { PolygonGenerator };
//# sourceMappingURL=PolygonGenerator.js.map