Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing enhanced window start position #25

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/js/apps/sample/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"visibleUiElements": {
"layoutTab": true,
"mapOnlyTab": false,
"mapOnlyTab": true,
"title": true,
"fileName": true,
"author": true,
Expand Down
80 changes: 16 additions & 64 deletions src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,70 +163,22 @@
},
data() {
return {
attributionEnabled: {
type: Boolean,
default: true
},
author: {
type: String,
default: ""
},
copyright: {
type: String,
default: ""
},
dpi: {
type: Number,
default: 96
},
fileName: {
type: String,
default: ""
},
format: {
type: String,
default: "pdf"
},
height: {
type: Number,
default: 1100
},
layout: {
type: String,
default: "a3-portrait"
},
legendEnabled: {
type: Boolean,
default: true
},
scale: {
type: Number,
default: 0
},
scaleEnabled: {
type: Boolean,
default: false
},
title: {
type: String,
default: ""
},
width: {
type: Number,
default: 800
},
enablePrintPreview: {
type: Boolean,
default: true
},
printPreviewInitallyVisible:{
type: Boolean,
default: null
},
activeTab: {
type: Number,
default: 0
}
attributionEnabled: true,
author: "",
copyright: "",
dpi: 96,
fileName: "",
format: "pdf",
height: 1100,
layout: "a3-portrait",
legendEnabled: true,
scale: 0,
scaleEnabled: false,
title: "",
width: 800,
enablePrintPreview: true,
printPreviewInitallyVisible: null,
activeTab: 0
};
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,95 @@ export default class PrintingEnhancedWidgetFactory {
}

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

const printingPreviewController = this._printingPreviewController;
const printWidget = this._printingWidget;
const esriPrintWidget = printWidget._esriWidget;
const templateOptions = esriPrintWidget.templateOptions;

this.printingPreviewControllerBinding =
this._createPrintingPreviewControllerBinding(vm, printingPreviewController);
this.templateOptionsBinding = this._createTemplateBinding(vm, templateOptions);

widget.activateTool = () => {
this.exportedLinksWatcher = esriPrintWidget.exportedLinks.on("after-add", function (event) {
const item = event.item;
const exportedItem = {
id: item.count,
name: item.formattedName,
loading: true,
error: false,
url: ""
};
vm.exportedLinks.push(exportedItem);
const stateWatcher = event.item.watch("state", (state) => {
stateWatcher.remove();
if (state === "ready") {
exportedItem.loading = false;
exportedItem.url = apprt_request.getProxiedUrl(item.url);
} else if (state === "error") {
exportedItem.loading = false;
exportedItem.url = null;
exportedItem.error = true;
}
});
});

// listen to view model methods
vm.$on('print', () => {
esriPrintWidget._handlePrintMap();
});
vm.$on('resetScale', () => {
esriPrintWidget._resetToCurrentScale();
});

this.printingPreviewControllerBinding.enable()
.syncToLeftNow();

this.templateOptionsBinding.enable()
.syncToLeftNow();
};
widget.deactivateTool = () => {
this.vm.$off();
this.printingPreviewControllerBinding.disable();
this.templateOptionsBinding.disable();
this.exportedLinksWatcher.remove();
};

widget.own({
remove() {
this.printingPreviewControllerBinding.unbind();
this.printingPreviewControllerBinding = undefined;
this.templateOptionsBinding.unbind();
this.templateOptionsBinding = undefined;
this.vm.$off();
this.printingPreviewController.resetGraphic();
}
});

return widget;
}

_initComponent() {
const properties = this._printingEnhancedProperties;
const vm = this.vm = new Vue(PrintingEnhancedWidget);
const printWidget = this._printingWidget;
const printingPreviewController = this._printingPreviewController;
const esriPrintWidget = printWidget._esriWidget;
const printViewModel = esriPrintWidget.viewModel;
const templateOptions = esriPrintWidget.templateOptions;

if (printViewModel.templatesInfo) {
this._setTemplatesInfos(printViewModel.templatesInfo);
} else {
console.warn("templatesInfo not yet available. Did you configure the property 'printtask.service.url` in map.apps' application.properties file? Still waiting for templatesInfo to get available...");
console.info("templatesInfo not yet available. Did you configure the property 'printtask.service.url` in map.apps' application.properties file? Still waiting for templatesInfo to get available...");
const watcher = printViewModel.watch("templatesInfo", (templatesInfo) => {
console.warn("templatesInfo now available.");
console.info("templatesInfo now available.");
this._setTemplatesInfos(templatesInfo);
watcher.remove();
});
}

esriPrintWidget.exportedLinks.on("after-add", function (event) {
const item = event.item;
const exportedItem = {
id: item.count,
name: item.formattedName,
loading: true,
error: false,
url: ""
};
vm.exportedLinks.push(exportedItem);
event.item.watch("state", (state) => {
if (state === "ready") {
exportedItem.loading = false;
exportedItem.url = apprt_request.getProxiedUrl(item.url);
} else if (state === "error") {
exportedItem.loading = false;
exportedItem.url = null;
exportedItem.error = true;
}
});
});

vm.i18n = this._i18n.get().ui;
vm.exportedItems = [];
const defaultVisibleUiElements = {
Expand All @@ -94,15 +138,10 @@ export default class PrintingEnhancedWidgetFactory {
vm.dpiValues = properties.dpiValues;
vm.scaleValues = properties.scaleValues;
vm.enablePrintPreview = properties.enablePrintPreview;
// listen to view model methods
vm.$on('print', () => {
esriPrintWidget._handlePrintMap();
});
vm.$on('resetScale', () => {
esriPrintWidget._resetToCurrentScale();
});
}

Binding.for(vm, printingPreviewController)
_createPrintingPreviewControllerBinding(vm, printingPreviewController) {
return Binding.for(vm, printingPreviewController)
.syncToRight("enablePrintPreview", "drawPrintPreview", (enablePrintPreview) => {
if (enablePrintPreview && vm.scaleEnabled) {
return true;
Expand All @@ -116,15 +155,13 @@ export default class PrintingEnhancedWidgetFactory {
} else {
return false;
}
})
.enable()
.syncToLeftNow();
});
}

Binding.for(vm, templateOptions)
_createTemplateBinding(vm, templateOptions) {
return Binding.for(vm, templateOptions)
.syncAll("attributionEnabled", "author", "copyright", "dpi", "fileName", "forceFeatureAttributes",
"format", "height", "layout", "legendEnabled", "scale", "scaleEnabled", "title", "width")
.enable()
.syncToLeftNow();
"format", "height", "layout", "legendEnabled", "scale", "scaleEnabled", "title", "width");
}

_setTemplatesInfos(templatesInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default declare({
});
connect.connect(tool, "onDeactivate", () => {
this._printingPreviewDrawer.removeGraphicFromGraphicsLayer();
this._printingPreviewDrawer.resetGraphic();
this[_lastPopupState]?.reset();
});
},
Expand All @@ -165,6 +166,7 @@ export default declare({
});
connect.connect(tool, "onDeactivate", () => {
this._printingPreviewDrawer.removeGraphicFromGraphicsLayer();
this._printingPreviewDrawer.resetGraphic();
this[_lastPopupState]?.reset();
});
},
Expand Down
39 changes: 21 additions & 18 deletions src/main/js/bundles/dn_printingenhanced/PrintingPreviewDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class PrintingPreviewDrawer {
if (mapWidgetModel.map) {
this._addGraphicsLayerToMap(mapWidgetModel.map);
} else {
mapWidgetModel.watch("map", ({value: map}) => {
mapWidgetModel.watch("map", ({ value: map }) => {
this._addGraphicsLayerToMap(map);
});
}
Expand Down Expand Up @@ -131,16 +131,14 @@ export default class PrintingPreviewDrawer {
_getMainFrameGeometry(geometryParams) {
const mapWidgetModel = this._mapWidgetModel;
const view = mapWidgetModel.view;

let x;
let y;
let centerPoint = mapWidgetModel.center;
if (this[_graphic]) {
x = this[_graphic].geometry.centroid.x;
y = this[_graphic].geometry.centroid.y;
} else {
x = mapWidgetModel.center.x;
y = mapWidgetModel.center.y;
centerPoint = this[_graphic].geometry.centroid;
}

const x = centerPoint.x;
const y = centerPoint.y;

const halfWidth = geometryParams.width / 2;
const halfHeight = geometryParams.height / 2;

Expand All @@ -156,7 +154,6 @@ export default class PrintingPreviewDrawer {
rings: rings,
spatialReference: view.spatialReference
});

return geometryEngine.rotate(polygon, geometryParams.rotation);
}

Expand All @@ -176,7 +173,7 @@ export default class PrintingPreviewDrawer {
if (mapWidgetModel.view) {
this._createSketchViewModel(graphicsLayer, mapWidgetModel.view);
} else {
mapWidgetModel.watch("view", ({value: view}) => {
mapWidgetModel.watch("view", ({ value: view }) => {
this._createSketchViewModel(graphicsLayer, view);
});
}
Expand Down Expand Up @@ -204,7 +201,7 @@ export default class PrintingPreviewDrawer {
const graphic = graphics[0];
const geometry = graphic.geometry;
this[_geometry] = geometry;
this._eventService.postEvent("dn_printingenhanced/PRINTSETTINGS", {geometry: geometry});
this._eventService.postEvent("dn_printingenhanced/PRINTSETTINGS", { geometry: geometry });
}
});
}
Expand All @@ -218,7 +215,18 @@ export default class PrintingPreviewDrawer {
});
this[_graphicsLayer].add(graphic);
if (properties.enablePrintPreviewMovement) {
this._eventService.postEvent("dn_printingenhanced/PRINTSETTINGS", {geometry: graphic.geometry});
this._eventService.postEvent("dn_printingenhanced/PRINTSETTINGS", { geometry: graphic.geometry });
}
}

_completeSketching() {
const sketchViewModel = this[_sketchViewModel];
sketchViewModel && sketchViewModel.complete();
}

resetGraphic() {
if (this[_graphic]) {
this[_graphic] = null;
}
}

Expand All @@ -229,11 +237,6 @@ export default class PrintingPreviewDrawer {
this._completeSketching();
}

_completeSketching() {
const sketchViewModel = this[_sketchViewModel];
sketchViewModel && sketchViewModel.complete();
}

showGraphicsLayer(value) {
this[_graphicsLayer].visible = value;
this._completeSketching();
Expand Down
13 changes: 11 additions & 2 deletions src/main/js/bundles/dn_printingenhanced/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@
{
"name": "PrintingEnhancedWidgetFactory",
"provides": [
"dijit.Widget"
"dijit.Widget",
"dn_printingenhanced.Widget"
],
"instanceFactory": true,
"properties": {
Expand Down Expand Up @@ -351,8 +352,16 @@
"togglable": true,
"rules": {
"noGroup": true
},
"activateHandler": "activateTool",
"deactivateHandler": "deactivateTool"
},
"references": [
{
"name": "handlerScope",
"providing": "dn_printingenhanced.Widget"
}
}
]
},
{
"name": "PrintingToggleToolHandler",
Expand Down
Loading