Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix(export): align read-only map scale (#3852)

Igor Dykhta43923ce2fe2b
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 7b8865eb4..6227430fa 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -1843,7 +1843,7 @@ export default function MapContainerFactory(
{!isExport && getApplicationConfig().enableMapScale ? (
<StyledMapScaleContainer
$left={
- primary && activeSidePanel
+ primary && activeSidePanel && !this.props.readOnly
? (sidePanelWidth || 0) + (theme?.sidePanel?.margin?.left ?? 9)
: theme?.sidePanel?.margin?.left ?? 9
}
diff --git a/test/browser/components/map/map-control-test.js b/test/browser/components/map/map-control-test.js
index 0b8d9505e..60356dad1 100644
--- a/test/browser/components/map/map-control-test.js
+++ b/test/browser/components/map/map-control-test.js
@@ -26,6 +26,7 @@ import {toggleMapControl} from '@kepler.gl/actions';
import {keplerGlReducerCore} from '@kepler.gl/reducers';
import {IntlWrapper, mountWithTheme} from '../../../helpers/component-utils';
+import {renderWithTheme as renderWithThemeRTL} from '../../../helpers/rtl-utils';
import {
mockKeplerProps,
mockKeplerPropsWithState,
@@ -243,6 +244,40 @@ test('MapControlFactory - display options', t => {
t.end();
});
+test('MapContainerFactory - map scale ignores hidden read-only side panel', t => {
+ const getScaleLeft = readOnly => {
+ const props = {
+ ...initialProps,
+ activeSidePanel: 'layer',
+ sidePanelWidth: 300,
+ readOnly,
+ mapStyle: {
+ bottomMapStyle: {layers: [], name: 'foo'},
+ visibleLayerGroups: {}
+ },
+ mapboxApiAccessToken: 'pyx-11'
+ };
+ const store = mockStore({uiState: StateWSplitMaps.uiState});
+ const {container, unmount} = renderWithThemeRTL(
+ <Provider store={store}>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={props.mapState}>
+ <MapContainer {...props} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
+ </Provider>
+ );
+ const scale = container.querySelector('.map-scale');
+ const left = window.getComputedStyle(scale.parentElement).left;
+ unmount();
+ return left;
+ };
+
+ t.equal(getScaleLeft(true), '12px', 'read-only scale uses the map margin');
+ t.equal(getScaleLeft(false), '312px', 'editable scale retains the panel offset');
+ t.end();
+});
+
test('MapControlFactory - click options', t => {
const onToggleSplitMap = sinon.spy();
const onTogglePerspective = sinon.spy();