Skip to content

Commit

Permalink
Reformat scaleEnabled watcher code
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasstein committed Feb 21, 2024
1 parent 820f03d commit e0d7937
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
12 changes: 0 additions & 12 deletions src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,6 @@
}
this.layout = "MAP_ONLY";
}
},
scaleEnabled: function(scaleEnabled) {
if (scaleEnabled === false) {
this.printPreviewInitallyVisible = this.enablePrintPreview;
this.enablePrintPreview = false;
this.$emit('resetPrintGeometry');
}
if (scaleEnabled && !this.visibleUiElements.printPreviewCheckbox) {
if (this.printPreviewInitallyVisible === true) {
this.enablePrintPreview = this.printPreviewInitallyVisible;
}
}
}
},
mounted: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class PrintingEnhancedWidgetFactory {
}

createInstance() {
return new VueDijit(this.vm, {class: "printing-enhanced-widget"});
return new VueDijit(this.vm, { class: "printing-enhanced-widget" });
}

_initComponent() {
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class PrintingEnhancedWidgetFactory {
"legendEnabled": false,
"attributionEnabled": false
};
vm.visibleUiElements = {...defaultVisibleUiElements, ...properties.visibleUiElements};
vm.visibleUiElements = { ...defaultVisibleUiElements, ...properties.visibleUiElements };
vm.dpiValues = properties.dpiValues;
vm.scaleValues = properties.scaleValues;
// listen to view model methods
Expand All @@ -98,13 +98,22 @@ export default class PrintingEnhancedWidgetFactory {
vm.$on('resetScale', () => {
esriPrintWidget._resetToCurrentScale();
});
vm.$on('resetPrintGeometry', () => {
esriPrintWidget._resetToCurrentScale();
this._eventService.postEvent("dn_printingenhanced/RESETPRINTGEOMETRY");
});

Binding.for(vm, printingPreviewController)
.syncAll("enablePrintPreview")
.syncToRight("enablePrintPreview", "drawPrintPreview", (enablePrintPreview) => {
if (enablePrintPreview && vm.scaleEnabled) {
return true;
} else {
return false;
}
})
.syncToRight("scaleEnabled", "drawPrintPreview", (scaleEnabled) => {
if (scaleEnabled && vm.enablePrintPreview) {
return true;
} else {
return false;
}
})
.enable()
.syncToLeftNow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const _view = Symbol("_view");

export default declare({

enablePrintPreview: false,
drawPrintPreview: false,

activate() {
const printWidget = this._printingWidget;
const esriPrintWidget = printWidget._esriWidget;
const printViewModel = esriPrintWidget.viewModel;
const properties = this._printingEnhancedProperties._properties;
this.enablePrintPreview = properties.enablePrintPreview;
this.drawPrintPreview = properties.enablePrintPreview && properties.scaleEnabled;

// get print infos
const url = this[_printServiceUrl] = esriPrintWidget.printServiceUrl;
Expand Down Expand Up @@ -81,20 +81,22 @@ export default declare({
}
}
// set sketching properties to view
const view = printViewModel.view;
this._oldRotation = null;
this._oldScale = view.scale;
if (properties.enablePrintPreviewMovement) {
if (this._printExtent) {
view.extent = this._printExtent;
this._oldRotation = view.rotation;
view.rotation = this._printRotation;
} else {
this._oldRotation = view.rotation;
view.rotation = 0;
if(printTemplate.scalePreserved) {
const view = printViewModel.view;
this._oldRotation = null;
this._oldScale = view.scale;
if (properties.enablePrintPreviewMovement) {
if (this._printExtent) {
view.extent = this._printExtent;
this._oldRotation = view.rotation;
view.rotation = this._printRotation;
} else {
this._oldRotation = view.rotation;
view.rotation = 0;
}
}
view.scale = printTemplate.outScale;
}
view.scale = printTemplate.outScale;
});

d_aspect.after(printViewModel, "print", (promise) => {
Expand All @@ -112,7 +114,7 @@ export default declare({
return promise;
});

this.watch("enablePrintPreview", (args) => {
this.watch("drawPrintPreview", (args) => {
this._handleDrawTemplateDimensions();
});
},
Expand Down Expand Up @@ -142,11 +144,6 @@ export default declare({
this._printRotation = this._computeAngle(geometry.rings[0][0], geometry.rings[0][1]);
},

resetPrintGeometry() {
this._printExtent = null;
this._printRotation = null;
},

setPrintingToggleTool(tool) {
this._printingToggleTool = tool;
const connect = this[_connect] = new Connect();
Expand Down Expand Up @@ -226,7 +223,7 @@ export default declare({
const properties = this._printingEnhancedProperties._properties;
async(() => {
if (((this._printingToggleTool && this._printingToggleTool.active) ||
this._printingEnhancedToggleTool.active) && this.enablePrintPreview) {
this._printingEnhancedToggleTool.active) && this.drawPrintPreview) {
const geometry = this._printingPreviewDrawer
.drawTemplateDimensions(this[_printInfos], this[_templateOptions], properties.defaultPageUnit);
if (geometry && zoomTo && this[_templateOptions].scaleEnabled) {
Expand Down Expand Up @@ -256,7 +253,7 @@ export default declare({

_disablePopups() {
const properties = this._printingEnhancedProperties._properties;
if (!this[_view] || !properties.enablePrintPreview) {
if (!this[_view] || !properties.drawPrintPreview) {
return;
}
const view = this[_view];
Expand Down
8 changes: 0 additions & 8 deletions src/main/js/bundles/dn_printingenhanced/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@
{
"topic": "dn_printingenhanced/PRINTSETTINGS",
"method": "setPrintSettings"
},
{
"topic": "dn_printingenhanced/RESETPRINTGEOMETRY",
"method": "resetPrintGeometry"
}
]
},
Expand Down Expand Up @@ -333,10 +329,6 @@
{
"name": "_printingEnhancedProperties",
"providing": "dn_printingenhanced.PrintingEnhancedProperties"
},
{
"name": "_eventService",
"providing": "ct.framework.api.EventService"
}
]
},
Expand Down

0 comments on commit e0d7937

Please sign in to comment.