Skip to content

Commit

Permalink
PB-878: Use print extent to filter out features to be printed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Sep 4, 2024
1 parent c2dc9cc commit 76e6dff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/api/print.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand Down Expand Up @@ -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(', ')}` : ''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions src/store/modules/print.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
selectedLayout: null,
selectedScale: null,
printSectionShown: false,
printExtent: [],
},
getters: {
printLayoutSize(state) {
Expand Down Expand Up @@ -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),
},
}

0 comments on commit 76e6dff

Please sign in to comment.