Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scalebar to explore page #618

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/scripts/components/common/blocks/block-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function MapBlock(props: MapBlockProps) {
cooperativeGestures
projection={projection}
onProjectionChange={allowProjectionChange ? setProjection : undefined}
withScale
/>
</Carto>
);
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/components/common/mapbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function MapboxMapComponent(
onPositionChange,
initialPosition,
withGeocoder,
withScale,
aoi,
onAoiChange,
projection,
Expand Down Expand Up @@ -439,6 +440,7 @@ function MapboxMapComponent(
cooperativeGestures
}}
withGeocoder={withGeocoder}
withScale={withScale}
aoi={aoi}
onAoiChange={onAoiChange}
projection={projection}
Expand Down Expand Up @@ -489,6 +491,7 @@ function MapboxMapComponent(
zoom: mapRef.current?.getZoom()
}}
withGeocoder={withGeocoder}
withScale={withScale}
aoi={aoi}
onAoiChange={onAoiChange}
projection={projection}
Expand Down Expand Up @@ -526,6 +529,7 @@ export interface MapboxMapProps {
}
) => void;
withGeocoder?: boolean;
withScale?: boolean;
children?: ReactNode;
aoi?: AoiState;
onAoiChange?: AoiChangeListenerOverload;
Expand Down
12 changes: 10 additions & 2 deletions app/scripts/components/common/mapbox/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import mapboxgl, {
AttributionControl,
EventData,
MapboxOptions,
NavigationControl
NavigationControl,
ScaleControl
} from 'mapbox-gl';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
import 'mapbox-gl/dist/mapbox-gl.css';
Expand Down Expand Up @@ -48,6 +49,7 @@ interface SimpleMapProps {
onUnmount?: () => void;
mapOptions: Partial<Omit<MapboxOptions, 'container'>>;
withGeocoder?: boolean;
withScale?: boolean;
aoi?: AoiState;
onAoiChange?: AoiChangeListenerOverload;
projection?: ProjectionOptions;
Expand All @@ -74,6 +76,7 @@ export function SimpleMap(props: SimpleMapProps): ReactElement {
onUnmount,
mapOptions,
withGeocoder,
withScale,
aoi,
onAoiChange,
projection,
Expand Down Expand Up @@ -149,13 +152,18 @@ export function SimpleMap(props: SimpleMapProps): ReactElement {
}

// Add zoom controls without compass.
if (mapOptions?.interactive !== false) {
if (mapOptions.interactive !== false) {
mbMap.addControl(
new NavigationControl({ showCompass: false }),
'top-left'
);
}

if (withScale) {
const scalecontrol = new ScaleControl();
mbMap.addControl(scalecontrol, 'bottom-left');
}

onLoad && mbMap.once('load', onLoad);

// Trigger a resize to handle flex layout quirks.
Expand Down
7 changes: 7 additions & 0 deletions app/scripts/components/common/mapbox/mapbox-style-override.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const MapboxStyleOverride = css`
.mapboxgl-ctrl-bottom-left {
flex-direction: row;
align-items: flex-end;
align-items: center;
}

.mapboxgl-ctrl-group {
Expand Down Expand Up @@ -167,6 +168,12 @@ const MapboxStyleOverride = css`
cursor: pointer;
}

.mapboxgl-ctrl-scale {
color: ${themeVal('color.surface')};
border-color: ${themeVal('color.surface')};
background-color: ${themeVal('color.base-400a')};
}

/* GEOCODER styles */
.mapboxgl-ctrl.mapboxgl-ctrl-geocoder {
background-color: ${themeVal('color.surface')};
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/datasets/s-explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ function DatasetsExplore() {
<MapboxMap
ref={mapboxRef}
withGeocoder
withScale
datasetId={dataset.data.id}
layerId={activeLayer?.baseLayer.data?.id}
date={selectedDatetime ?? undefined}
Expand Down
Loading