create default sketcher layers in viewer constructor

This commit is contained in:
Val Erastov 2019-02-18 22:14:46 -08:00
parent b51361fa3c
commit 85afe6d6fe
2 changed files with 14 additions and 11 deletions

View file

@ -19,15 +19,6 @@ function initializeSketcherApplication() {
app.loadFromLocalStorage();
app.fit();
function addLayer(name, style) {
if (app.viewer.findLayerByName(name) === null) {
app.viewer.layers.push(new Layer(name, style));
}
}
addLayer("sketch", Styles.DEFAULT);
addLayer("_construction_", Styles.CONSTRUCTION);
var actionsWin = new ui.Window($('#actions'), app.winManager);
ui.bindOpening( $('#showActions'), actionsWin );

View file

@ -53,7 +53,10 @@ function Viewer(canvas, IO) {
this.bus = new Bus();
this.ctx = this.canvas.getContext("2d");
this._activeLayer = null;
this.layers = [];
this.layers = [
new Layer("sketch", Styles.DEFAULT),
new Layer("_construction_", Styles.CONSTRUCTION)
];
this.dimLayer = new Layer("_dim", Styles.DIM);
this.dimLayers = [this.dimLayer];
this.bus.defineObservable(this, 'dimScale', 1);
@ -401,12 +404,21 @@ Viewer.prototype.getActiveLayer = function() {
}
}
if (layer == null) {
layer = new Layer("JustALayer", Styles.DEFAULT);
layer = new Layer("sketch", Styles.DEFAULT);
this.layers.push(layer);
}
return layer;
};
Viewer.prototype.setActiveLayerName = function(layerName) {
let layer = this.findLayerByName(layerName);
if (layer) {
this.activeLayer = layer;
} else {
console.warn("layer doesn't exist: " + layerName);
}
};
Viewer.prototype.setActiveLayer = function(layer) {
if (!layer.readOnly) {
this._activeLayer = layer;