Skip to content

Commit

Permalink
fix text scale for point features (#2805) (#2807)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiloSchlemmer authored Jan 10, 2025
1 parent 56de3c2 commit 3490423
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/modules/olMap/services/Mfp3Encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,14 @@ export class BvvMfp3Encoder {

if (textStyle.getFont()) {
const fontValues = textStyle.getFont().split(' ');
const scale = textStyle.getScale() ?? 1;
const [weight, size, ...fontFamilyValues] = fontValues;
// hint: the fontFamily value relates to all installed font on the server.
// If the application use any custom fonts over css-styles which are used
// for labels on the map, these fonts must be available as TrueTypeFonts
// on the MapFishPrint server
encoded.fontFamily = fontFamilyValues.join(' ');
encoded.fontSize = BvvMfp3Encoder.adjustDistance(parseInt(size), dpi);
encoded.fontSize = scale * BvvMfp3Encoder.adjustDistance(parseInt(size), dpi);
encoded.fontWeight = weight;
}

Expand Down
89 changes: 89 additions & 0 deletions test/modules/olMap/formats/Mfp3Encoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,47 @@ describe('BvvMfp3Encoder', () => {
});
});

it('writes a point feature with feature style (text) and scaled font size', () => {
const featureWithScale1 = new Feature({ geometry: new Point([30, 30]) });
const featureWithScale2 = new Feature({ geometry: new Point([40, 40]) });
const stylesScaled1 = getTextStyle();
const stylesScaled2 = getTextStyle();
stylesScaled1[0].getText().setScale(1);
stylesScaled1[0].getImage().setScale(1);
stylesScaled2[0].getText().setScale(2);
stylesScaled2[0].getImage().setScale(2);
featureWithScale1.setStyle(stylesScaled1);
featureWithScale2.setStyle(stylesScaled2);
const vectorSource = new VectorSource({ wrapX: false, features: [featureWithScale1, featureWithScale2] });
const vectorLayer = new VectorLayer({ id: 'foo', source: vectorSource, style: null });
const groupOpacity = 1;
spyOn(vectorLayer, 'getExtent').and.callFake(() => [20, 20, 50, 50]);
const geoResourceMock = getGeoResourceMock();
spyOn(geoResourceServiceMock, 'byId').and.callFake(() => geoResourceMock);
const encoder = setup();
encoder._pageExtent = [20, 20, 50, 50];
const actualSpec = encoder._encodeVector(vectorLayer, groupOpacity);

expect(actualSpec).toEqual({
opacity: 1,
type: 'geojson',
name: 'foo',
geoJson: {
features: jasmine.any(Array),
type: 'FeatureCollection'
},
style: {
version: '2',
'[_gx_style = 0]': {
symbolizers: [jasmine.objectContaining({ type: 'text', fontSize: 16.666666666666668 })]
},
'[_gx_style = 1]': {
symbolizers: [jasmine.objectContaining({ type: 'text', fontSize: 33.333333333333336 })]
}
}
});
});

it('writes a point feature with feature style (text) and alignment (bottom)', () => {
const featureWithStyle = new Feature({ geometry: new Point([30, 30]) });
featureWithStyle.setStyle(getTextStyle('left', 'bottom'));
Expand Down Expand Up @@ -1608,6 +1649,54 @@ describe('BvvMfp3Encoder', () => {
});
});

it('writes a point feature with feature style (text & symbol) with two symbolizers and scaling', () => {
const featureWithScale1 = new Feature({ geometry: new Point([30, 30]) });
const featureWithScale2 = new Feature({ geometry: new Point([40, 40]) });
const stylesScaled1 = getTextAndImageStyle('left', 'top');
const stylesScaled2 = getTextAndImageStyle('left', 'top');
stylesScaled1[0].getText().setScale(1);
stylesScaled1[0].getImage().setScale(1);
stylesScaled2[0].getText().setScale(2);
stylesScaled2[0].getImage().setScale(2);
featureWithScale1.setStyle(stylesScaled1);
featureWithScale2.setStyle(stylesScaled2);

const vectorSource = new VectorSource({ wrapX: false, features: [featureWithScale1, featureWithScale2] });
const vectorLayer = new VectorLayer({ id: 'foo', source: vectorSource, style: null });
const groupOpacity = 1;
spyOn(vectorLayer, 'getExtent').and.callFake(() => [20, 20, 50, 50]);
const geoResourceMock = getGeoResourceMock();
spyOn(geoResourceServiceMock, 'byId').and.callFake(() => geoResourceMock);
const encoder = setup();
encoder._pageExtent = [20, 20, 50, 50];
const actualSpec = encoder._encodeVector(vectorLayer, groupOpacity);

expect(actualSpec).toEqual({
opacity: 1,
type: 'geojson',
name: 'foo',
geoJson: {
features: jasmine.any(Array),
type: 'FeatureCollection'
},
style: {
version: '2',
'[_gx_style = 0]': {
symbolizers: [
jasmine.objectContaining({ type: 'point', graphicHeight: 70 }),
jasmine.objectContaining({ type: 'text', fontSize: 16.666666666666668 })
]
},
'[_gx_style = 1]': {
symbolizers: [
jasmine.objectContaining({ type: 'point', graphicHeight: 140 }),
jasmine.objectContaining({ type: 'text', fontSize: 33.333333333333336 })
]
}
}
});
});

it('writes a point feature with feature style function', () => {
const featureWithStyle = new Feature({ geometry: new Point([30, 30]) });
featureWithStyle.setStyle(() => getStyle());
Expand Down

0 comments on commit 3490423

Please sign in to comment.