Skip to content

Commit

Permalink
Fix editing scale constraint when edit feature from result
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Nov 21, 2023
1 parent 25dbb83 commit 21cc247
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions services/editingservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,6 @@ proto.editResultLayerFeature = function({
const toolBox = this.getToolBoxById(layer.id);
const { scale } = toolBox.getEditingConstraints(); // get scale constraint from setting layer
const has_geom = feature.geometry && undefined !== scale;

// check map scale after zoom to feature
// if currentScale is more that scale constraint set by layer editing
// need to go to scale setting by layer editing constraint
if (has_geom) {
this._mapService.getMap().once('moveend', () => {
const units = this._mapService.getMapUnits();
const map = this._mapService.getMap();
const currentScale = parseInt(getScaleFromResolution(map.getView().getResolution(), units));
if (currentScale > scale) {
map.getView().setResolution(getResolutionFromScale(scale, units));
}
});
}

// start toolbox (filtered by feature id)
toolBox
.start({ filter: { fids: fid } })
Expand All @@ -459,18 +444,36 @@ proto.editResultLayerFeature = function({
: source.readFeatures()
).find(f => f.getId() == fid);

// skip when ..
// skip when not feature is get from server
if (!feature) {
return;
}

/** @FIXME add description */
/**If feature has geometry, zoom to geometry */
if (feature.getGeometry()) {
this._mapService.zoomToGeometry(feature.getGeometry());
// check map scale after zoom to feature
// if currentScale is more that scale constraint set by layer editing
// need to go to scale setting by layer editing constraint
if (has_geom) {
this._mapService.getMap().once('moveend', () => {
const units = this._mapService.getMapUnits();
const map = this._mapService.getMap();
const currentScale = parseInt(getScaleFromResolution(map.getView().getResolution(), units));
if (currentScale > scale) {
map.getView().setResolution(getResolutionFromScale(scale, units));
}
//set select only here otherwise is show editing constraint
toolBox.setSelected(true);
});
} else {
toolBox.setSelected(true);
}
} else {
//set select toolbox
toolBox.setSelected(true);
}

toolBox.setSelected(true);

const session = toolBox.getSession();

this.setSelectedToolbox(toolBox);
Expand All @@ -483,7 +486,9 @@ proto.editResultLayerFeature = function({
inputs: { layer: _layer, features: [feature] },
context: { session }
})
.then(() => session.save().then(() => this.saveChange()))
.then(() => session
.save()
.then(() => this.saveChange()))
.fail(() => session.rollback());

})
Expand Down

0 comments on commit 21cc247

Please sign in to comment.