Skip to content

Commit d2bd3ef

Browse files
committed
add more export options for kepler map export
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
1 parent efb072e commit d2bd3ef

2 files changed

Lines changed: 64 additions & 3 deletions

File tree

src/components/src/plot-container.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ const CLASS_FILTER = [
3939
const DOM_FILTER_FUNC = node => !CLASS_FILTER.includes(node.className);
4040
const OUT_OF_SCREEN_POSITION = -9999;
4141

42+
/**
43+
* Linearly remaps the export scale range [1..4] to a reduced legend scale [1..3].
44+
* Prevents the legend from scaling as aggressively as the exported image.
45+
* @param linearScale - scale factor (e.g., 1, 2, 3, 4, 5)
46+
* @returns remapped scale factor
47+
*/
48+
function calculateLogarithmicLegendScale(scale: number): number {
49+
const max = 4;
50+
const t = (scale - 1) / (max - 1);
51+
return 1 + t * 2;
52+
}
53+
4254
PlotContainerFactory.deps = [MapContainerFactory, MapsLayoutFactory];
4355

4456
// Remove mapbox logo in exported map, because it contains non-ascii characters
@@ -57,6 +69,11 @@ const StyledPlotContainer = styled.div`
5769
position: absolute;
5870
top: ${OUT_OF_SCREEN_POSITION}px;
5971
left: ${OUT_OF_SCREEN_POSITION}px;
72+
73+
/* Apply logarithmic zoom to legend panel */
74+
.map-control-panel {
75+
zoom: var(--legend-scale, 1) !important;
76+
}
6077
`;
6178

6279
interface StyledMapContainerProps {
@@ -312,7 +329,12 @@ export default function PlotContainerFactory(
312329
);
313330

314331
return (
315-
<StyledPlotContainer className="export-map-instance">
332+
<StyledPlotContainer
333+
className="export-map-instance"
334+
style={{
335+
'--legend-scale': calculateLogarithmicLegendScale(scale)
336+
} as React.CSSProperties}
337+
>
316338
<StyledMapContainer ref={plottingAreaRef} width={size.width} height={size.height}>
317339
<MapViewStateContextProvider mapState={newMapState}>
318340
{mapContainers}

src/constants/src/default-settings.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,10 @@ export const MAX_DEFAULT_TOOLTIPS = 5;
973973

974974
export const RESOLUTIONS = keyMirror({
975975
ONE_X: null,
976-
TWO_X: null
976+
TWO_X: null,
977+
THREE_X: null,
978+
FOUR_X: null,
979+
FIVE_X: null
977980
});
978981

979982
export const EXPORT_IMG_RATIOS = keyMirror({
@@ -1055,9 +1058,45 @@ export const TwoXResolutionOption: ImageResolutionOption = {
10551058
})
10561059
};
10571060

1061+
export const ThreeXResolutionOption: ImageResolutionOption = {
1062+
id: RESOLUTIONS.THREE_X,
1063+
label: '3x',
1064+
available: true,
1065+
scale: 3,
1066+
getSize: (screenW, screenH) => ({
1067+
width: screenW * 3,
1068+
height: screenH * 3
1069+
})
1070+
};
1071+
1072+
export const FourXResolutionOption: ImageResolutionOption = {
1073+
id: RESOLUTIONS.FOUR_X,
1074+
label: '4x',
1075+
available: true,
1076+
scale: 4,
1077+
getSize: (screenW, screenH) => ({
1078+
width: screenW * 4,
1079+
height: screenH * 4
1080+
})
1081+
};
1082+
1083+
export const FiveXResolutionOption: ImageResolutionOption = {
1084+
id: RESOLUTIONS.FIVE_X,
1085+
label: '5x',
1086+
available: true,
1087+
scale: 5,
1088+
getSize: (screenW, screenH) => ({
1089+
width: screenW * 5,
1090+
height: screenH * 5
1091+
})
1092+
};
1093+
10581094
export const EXPORT_IMG_RESOLUTION_OPTIONS: ReadonlyArray<ImageResolutionOption> = [
10591095
OneXResolutionOption,
1060-
TwoXResolutionOption
1096+
TwoXResolutionOption,
1097+
ThreeXResolutionOption,
1098+
FourXResolutionOption,
1099+
FiveXResolutionOption
10611100
];
10621101

10631102
export const EXPORT_DATA_TYPE = keyMirror({

0 commit comments

Comments
 (0)