From 76e6dff721856f2386cb2eca36f3ec7157e91fa4 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 2 Sep 2024 16:44:15 +0200 Subject: [PATCH] PB-878: Use print extent to filter out features to be printed. --- src/api/print.api.js | 10 ++++++---- .../utils/usePrintAreaRenderer.composable.js | 15 +++++++++++++++ src/store/modules/print.store.js | 5 +++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/api/print.api.js b/src/api/print.api.js index cd6a63394..6d6f64ca8 100644 --- a/src/api/print.api.js +++ b/src/api/print.api.js @@ -14,6 +14,7 @@ import { getWmsBaseUrl, } from '@/config/baseUrl.config' import i18n from '@/modules/i18n' +import store from '@/store' import log from '@/utils/logging' import { adjustWidth } from '@/utils/styleUtils' @@ -25,11 +26,12 @@ const MAX_PRINT_SPEC_SIZE = 1 * 1024 * 1024 // 1MB in bytes (should be in sync w class GeoAdminCustomizer extends BaseCustomizer { /** @param {string[]} layerIDsToExclude List of layer names to exclude from the print */ - constructor(layerIDsToExclude, printResolution) { - super() + constructor(printExtent, layerIDsToExclude, printResolution) { + super(printExtent) this.layerIDsToExclude = layerIDsToExclude this.printResolution = printResolution this.layerFilter = this.layerFilter.bind(this) + this.geometryFilter = this.geometryFilter.bind(this) this.line = this.line.bind(this) this.text = this.text.bind(this) this.point = this.point.bind(this) @@ -325,8 +327,8 @@ async function transformOlMapToPrintParams(olMap, config) { if (!dpi) { throw new PrintError('Missing DPI for printing') } - - const customizer = new GeoAdminCustomizer(excludedLayerIDs, dpi) + const printExtent = store.state.print.printExtent + const customizer = new GeoAdminCustomizer(printExtent, excludedLayerIDs, dpi) const attributionsOneLine = attributions.length > 0 ? `© ${attributions.join(', ')}` : '' diff --git a/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js b/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js index 7f6bbd838..c340bfb81 100644 --- a/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js +++ b/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js @@ -118,6 +118,21 @@ export default function usePrintAreaRenderer(map) { const width = size[0] const printRectangle = calculatePageBoundsPixels(selectedScale.value, printLayoutSize.value) + const topLeftCoordinate = map.getCoordinateFromPixel([printRectangle[0], printRectangle[1]]) + const rightBottomCoordinate = map.getCoordinateFromPixel([ + printRectangle[2], + printRectangle[3], + ]) + + store.commit('setPrintExtent', { + printExtent: [ + topLeftCoordinate[0], + rightBottomCoordinate[1], + rightBottomCoordinate[0], + topLeftCoordinate[1], + ], + dispatcher, + }) const minx = printRectangle[0] const miny = printRectangle[1] diff --git a/src/store/modules/print.store.js b/src/store/modules/print.store.js index a959914a1..3ba6e181a 100644 --- a/src/store/modules/print.store.js +++ b/src/store/modules/print.store.js @@ -7,6 +7,7 @@ export default { selectedLayout: null, selectedScale: null, printSectionShown: false, + printExtent: [], }, getters: { printLayoutSize(state) { @@ -44,11 +45,15 @@ export default { setPrintSectionShown({ commit }, { show, dispatcher }) { commit('setPrintSectionShown', { show, dispatcher }) }, + setPrintExtent({ commit }, { printExtent, dispatcher }) { + commit('setPrintExtent', { printExtent, dispatcher }) + }, }, mutations: { setPrintLayouts: (state, { layouts }) => (state.layouts = layouts), setSelectedLayout: (state, { layout }) => (state.selectedLayout = layout), setSelectedScale: (state, { scale }) => (state.selectedScale = scale), setPrintSectionShown: (state, { show }) => (state.printSectionShown = show), + setPrintExtent: (state, { printExtent }) => (state.printExtent = printExtent), }, }