Skip to content

Commit

Permalink
add a geoResource fake for highlight-layer to enable export for highl…
Browse files Browse the repository at this point in the history
…ight-feature
  • Loading branch information
thiloSchlemmer committed Dec 13, 2024
1 parent 54d5273 commit 8bf2080
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/modules/olMap/services/Mfp3Encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { BaOverlay, OVERLAY_STYLE_CLASS } from '../components/BaOverlay';
import { findAllBySelector } from '../../../utils/markup';
import { setQueryParams } from '../../../utils/urlUtils';
import { QueryParameters } from '../../../domain/queryParameters';
import { OlHighlightLayerHandler } from '../handler/highlight/OlHighlightLayerHandler';

Check failure on line 24 in src/modules/olMap/services/Mfp3Encoder.js

View workflow job for this annotation

GitHub Actions / build

'OlHighlightLayerHandler' is defined but never used
import { HIGHLIGHT_LAYER_ID } from '../../../plugins/HighlightPlugin';

const UnitsRatio = 39.37; //inches per meter
const PointsPerInch = 72; // PostScript points 1/72"
Expand Down Expand Up @@ -147,12 +149,18 @@ export class BvvMfp3Encoder {
return layerExtent ? extentIntersects(layer.getExtent(), this._pageExtent) && layer.getVisible() : layer.getVisible();
});

console.log(

Check failure on line 152 in src/modules/olMap/services/Mfp3Encoder.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'encodableLayers',
encodableLayers.map((l) => l.get('id'))
);

const errors = [];
const collectErrors = (label, errorType) => {
errors.push({ label: label, type: errorType });
};

const encodedLayers = encodableLayers.flatMap((l) => this._encode(l, collectErrors));

const copyRights = this._getCopyrights(olMap, encodableLayers);
const encodedOverlays = this._encodeOverlays(olMap.getOverlays().getArray());
const encodedGridLayer = this._mfpProperties.showGrid ? this._encodeGridLayer(this._mfpProperties.scale) : {};
Expand Down Expand Up @@ -241,7 +249,10 @@ export class BvvMfp3Encoder {
* - WMTS/XYZ layers are defined for a specific projection. If the application projection and the print projection differs, the layer must be replaced.
*/
const encodableLayer = this._getSubstitutionLayerOptional(layer);
const geoResource = this._geoResourceService.byId(encodableLayer.get('geoResourceId'));
const geoResource =
layer.get('id') === HIGHLIGHT_LAYER_ID
? { exportable: true, getType: () => GeoResourceTypes.VECTOR }
: this._geoResourceService.byId(encodableLayer.get('geoResourceId'));

if (!geoResource) {
encodingErrorCallback(`[${layer.get('id')}]`, MFP_ENCODING_ERROR_TYPE.MISSING_GEORESOURCE);
Expand Down
20 changes: 20 additions & 0 deletions test/modules/olMap/formats/Mfp3Encoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import TileGrid from 'ol/tilegrid/TileGrid';
import { AdvWmtsTileGrid } from '../../../../src/modules/olMap/ol/tileGrid/AdvWmtsTileGrid';
import { BaOverlayTypes } from '../../../../src/modules/olMap/components/BaOverlay';
import { QueryParameters } from '../../../../src/domain/queryParameters';
import { HIGHLIGHT_LAYER_ID } from '../../../../src/plugins/HighlightPlugin';

describe('BvvMfp3Encoder', () => {
const viewMock = { getCenter: () => [50, 50], calculateExtent: () => [0, 0, 100, 100], getResolution: () => 10, getZoomForResolution: () => 21 };
Expand Down Expand Up @@ -445,6 +446,25 @@ describe('BvvMfp3Encoder', () => {
expect(errorSpy).toHaveBeenCalledWith('[foo]', MFP_ENCODING_ERROR_TYPE.MISSING_GEORESOURCE);
});

it('encodes the highlight layer as vector layer', () => {
spyOn(geoResourceServiceMock, 'byId')
.withArgs(HIGHLIGHT_LAYER_ID)
.and.callFake(() => null);
const encoder = new BvvMfp3Encoder();
const encodingResult = {};
const layerMock = { get: () => HIGHLIGHT_LAYER_ID };
const encodingSpy = spyOn(encoder, '_encodeVector').and.callFake(() => {
return encodingResult;
});
const errorSpy = jasmine.createSpy();

const actualEncoded = encoder._encode(layerMock, errorSpy);

expect(actualEncoded).toBe(encodingResult);
expect(encodingSpy).toHaveBeenCalled();
expect(errorSpy).not.toHaveBeenCalled();
});

it('does NOT encode a layer, if a geoResource is not exportable', () => {
const notExportableGeoResource = new TestGeoResource('something', 'foo label', false);

Expand Down

0 comments on commit 8bf2080

Please sign in to comment.