@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
92 lines • 3.29 kB
JavaScript
import { Collection } from "@aurigma/design-atoms-model/Collection";
import { itemBelongsCollection } from "@aurigma/design-atoms-model/Utils/Exceptions";
import { ArgumentException } from "@aurigma/design-atoms-model/Exception";
export class LayerCollection extends Collection {
constructor(_canvas) {
super();
this._canvas = _canvas;
}
getLayerById(id) {
for (var i = 0, imax = this.length; i < imax; i++) {
var layer = this.getItem(i);
if (layer.uniqueId == id) {
return layer;
}
}
return null;
}
getLayerByContainerId(id) {
for (var i = 0, imax = this.length; i < imax; i++) {
var layer = this.getItem(i);
if (layer.container.id == id) {
return layer;
}
}
return null;
}
getLayersByName(name) {
/// <summary>Search layers with the specified name.</summary>
/// <param name="name" type="String">The name to search layers.</param>
/// <returns type="Array">An array of layers contained in this collection and match the specified name.</returns>
/// <remarks><para>This method corresponds to <see cref="M:Aurigma.GraphicsMill.AjaxControls.VectorObjects.LayerCollection.GetLayersByName(System.String)">LayerCollection.GetLayersByName(String)</see> server-side member.</para></remarks>
var ll = [];
for (var i = 0; i < this.length; i++) {
if (this.getItem(i).name == name) {
ll.push(this.getItem(i));
}
}
return ll;
}
getItemHandlersByName(name) {
var ol = [];
for (var i = 0; i < this.length; i++) {
var l = this.getItem(i);
for (var j = 0; j < l.itemHandlers.length; j++) {
if (l.itemHandlers.getItem(j).name === name) {
ol.push(l.itemHandlers.getItem(j));
}
}
}
return ol;
}
removeRange(from, to) {
var removeHandler = function (args) {
this._onLayerRemoved(args.item, args.index);
}.bind(this);
try {
this.add_itemRemoved(removeHandler);
return super.removeRange(from, to);
}
finally {
this.remove_itemRemoved(removeHandler);
}
}
insertAt(index, items) {
if (!Array.isArray(items))
items = [items];
for (let layer of items)
if (this.contains(layer))
throw new ArgumentException(itemBelongsCollection);
super.insertAt(index, items);
for (var i = 0; i < items.length; i++) {
var layer = items[i];
this._onLayerAdded(layer);
}
}
move(oldIndex, newIndex) {
const item = super.move(oldIndex, newIndex);
return item;
}
clear() {
for (let removingLayer of this)
removingLayer.dispose();
super.clear();
}
_onLayerAdded(layer) {
if (this._canvas) {
layer.canvas = this._canvas;
layer.onLayerAdded();
}
}
}
//# sourceMappingURL=LayerCollection.js.map