Skip to content

Commit

Permalink
Update dynamic adjustements of stepSize based on current scale
Browse files Browse the repository at this point in the history
  • Loading branch information
sholtkamp committed Feb 15, 2023
1 parent fd607e5 commit 85e830a
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,19 @@ export default class CircleSpatialInputAction {

vm.$on("adjustStepSize-changed", adjustStepSize => {
if (adjustStepSize) {
this.#scaleWatcher = reactiveUtils.watch(
() => [view.scale], ([scale]) => {
const adjustedStepSize = this._adjustStepSize(scale, model);
vm.stepSize = adjustedStepSize.stepSize;
}, {
initial: true
}
);
this.#scaleWatcher = this._getScaleWatcher(view, model, vm);
} else {
this.#scaleWatcher.remove();
this.#scaleWatcher = undefined;
vm.stepSize = model.stepSize;
}
});

// handle inital activation adjustStepSize via config
if (model.adjustStepSize) {
this.#scaleWatcher = this._getScaleWatcher(view, model, vm);
}

this.#binding = Binding.for(vm, model)
.syncAllToRight("innerRadius", "outerRadius", "adjustStepSize")
.enable();
Expand Down Expand Up @@ -195,6 +193,17 @@ export default class CircleSpatialInputAction {
this.#highlighter.clear();
}

_getScaleWatcher(view, model, vm) {
return reactiveUtils.watch(
() => [view.scale], ([scale]) => {
const adjustedStepSize = this._adjustStepSize(scale, model);
vm.stepSize = adjustedStepSize.stepSize;
}, {
initial: true
}
);
}

_adjustStepSize(scale, model) {
return model.stepSizeRanges.find(range => range.scaleRange[0] <= scale && range.scaleRange[1] >= scale)
}
Expand Down

0 comments on commit 85e830a

Please sign in to comment.