Skip to content

Commit

Permalink
WIP - use print extent
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Sep 2, 2024
1 parent c2dc9cc commit 3f4f219
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
17 changes: 13 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,14 +26,17 @@ 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)

console.log('printExtent', this.printExtent)
}

/**
Expand All @@ -50,6 +54,11 @@ class GeoAdminCustomizer extends BaseCustomizer {
return super.layerFilter(layerState)
}

geometryFilter(geometry) {
console.log('geometryFilter', geometry)
return true
}

/**
* Manipulate the symbolizer of a line feature before printing it. In this case replace the
* strokeDashstyle to dash instead of 8 (measurement line style in the mapfishprint3 backend)
Expand Down Expand Up @@ -325,8 +334,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
@@ -1,4 +1,5 @@
import * as olHas from 'ol/has'
import { transform } from 'ol/proj'
import { getRenderPixel } from 'ol/render'
import { computed, watch } from 'vue'
import { useStore } from 'vuex'
Expand Down Expand Up @@ -118,6 +119,49 @@ 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],
])

const projection = map.getView().getProjection().getCode()

// Convert coordinates to WGS 84
const topLeftCoordWGS84 = transform(topLeftCoordinate, projection, 'EPSG:4326')
const rightBottomWGS84 = transform(rightBottomCoordinate, projection, 'EPSG:4326')

console.log('printRectangle', printRectangle)
console.log(
'topLeftCoordinate, rightBottomCoordinate',
topLeftCoordinate,
rightBottomCoordinate
)
console.log('topLeftCoordWGS84, rightBottomWGS84', topLeftCoordWGS84, rightBottomWGS84)
console.log(
'extent',
topLeftCoordinate[0],
rightBottomCoordinate[1],
rightBottomCoordinate[0],
topLeftCoordinate[1]
)
console.log(
'extentWGS84',
topLeftCoordWGS84[0],
rightBottomWGS84[1],
rightBottomWGS84[0],
topLeftCoordWGS84[1]
)

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 3f4f219

Please sign in to comment.