diff --git a/src/main/js/apps/sample/app.json b/src/main/js/apps/sample/app.json index 6e23203..ef65a78 100644 --- a/src/main/js/apps/sample/app.json +++ b/src/main/js/apps/sample/app.json @@ -52,7 +52,7 @@ }, "visibleUiElements": { "layoutTab": true, - "mapOnlyTab": false, + "mapOnlyTab": true, "title": true, "fileName": true, "author": true, diff --git a/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidget.vue b/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidget.vue index a28195e..89ac525 100644 --- a/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidget.vue +++ b/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidget.vue @@ -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: { diff --git a/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidgetFactory.js b/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidgetFactory.js index aff23c3..d31795e 100644 --- a/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidgetFactory.js +++ b/src/main/js/bundles/dn_printingenhanced/PrintingEnhancedWidgetFactory.js @@ -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 = { @@ -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; @@ -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) { diff --git a/src/main/js/bundles/dn_printingenhanced/PrintingPreviewController.js b/src/main/js/bundles/dn_printingenhanced/PrintingPreviewController.js index 718556b..c5b28ce 100644 --- a/src/main/js/bundles/dn_printingenhanced/PrintingPreviewController.js +++ b/src/main/js/bundles/dn_printingenhanced/PrintingPreviewController.js @@ -152,6 +152,7 @@ export default declare({ }); connect.connect(tool, "onDeactivate", () => { this._printingPreviewDrawer.removeGraphicFromGraphicsLayer(); + this._printingPreviewDrawer.resetGraphic(); this[_lastPopupState]?.reset(); }); }, @@ -165,6 +166,7 @@ export default declare({ }); connect.connect(tool, "onDeactivate", () => { this._printingPreviewDrawer.removeGraphicFromGraphicsLayer(); + this._printingPreviewDrawer.resetGraphic(); this[_lastPopupState]?.reset(); }); }, diff --git a/src/main/js/bundles/dn_printingenhanced/PrintingPreviewDrawer.js b/src/main/js/bundles/dn_printingenhanced/PrintingPreviewDrawer.js index a3f0674..0e95e76 100644 --- a/src/main/js/bundles/dn_printingenhanced/PrintingPreviewDrawer.js +++ b/src/main/js/bundles/dn_printingenhanced/PrintingPreviewDrawer.js @@ -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); }); } @@ -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; @@ -156,7 +154,6 @@ export default class PrintingPreviewDrawer { rings: rings, spatialReference: view.spatialReference }); - return geometryEngine.rotate(polygon, geometryParams.rotation); } @@ -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); }); } @@ -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 }); } }); } @@ -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; } } @@ -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(); diff --git a/src/main/js/bundles/dn_printingenhanced/manifest.json b/src/main/js/bundles/dn_printingenhanced/manifest.json index e63625e..75acefd 100644 --- a/src/main/js/bundles/dn_printingenhanced/manifest.json +++ b/src/main/js/bundles/dn_printingenhanced/manifest.json @@ -309,7 +309,8 @@ { "name": "PrintingEnhancedWidgetFactory", "provides": [ - "dijit.Widget" + "dijit.Widget", + "dn_printingenhanced.Widget" ], "instanceFactory": true, "properties": { @@ -351,8 +352,16 @@ "togglable": true, "rules": { "noGroup": true + }, + "activateHandler": "activateTool", + "deactivateHandler": "deactivateTool" + }, + "references": [ + { + "name": "handlerScope", + "providing": "dn_printingenhanced.Widget" } - } + ] }, { "name": "PrintingToggleToolHandler",