Skip to content

Commit fcedeba

Browse files
authored
Add ScaleControl to various map components (#2802)
* Add ScaleControl to various map components - Integrated ScaleControl into ActivityMap, BoundsSelectorModal, InsetMap, SupplementalMap, TaskMap, TaskNearbyMap, and LeaderboardMap components for improved user navigation. - Updated styles in MapPane.scss to ensure proper positioning of the ScaleControl. - Removed redundant ScaleControl styles from TaskClusterMap.scss. This enhancement provides users with a clearer understanding of the map scale across different views. * Refactor imports in ActivityMap and TaskNearbyMap components - Updated import statements for better readability by using multiline syntax for imports from 'react-leaflet'. - This change enhances code clarity and maintains consistency across components.
1 parent 4d91c26 commit fcedeba

11 files changed

Lines changed: 38 additions & 10 deletions

File tree

src/components/ActivityMap/ActivityMap.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import _map from "lodash/map";
77
import PropTypes from "prop-types";
88
import { useEffect, useState } from "react";
99
import { FormattedMessage, injectIntl } from "react-intl";
10-
import { AttributionControl, CircleMarker, MapContainer, Popup, useMap } from "react-leaflet";
10+
import {
11+
AttributionControl,
12+
CircleMarker,
13+
MapContainer,
14+
Popup,
15+
ScaleControl,
16+
useMap,
17+
} from "react-leaflet";
1118
import { GLOBAL_MAPBOUNDS, toLatLngBounds } from "../../services/MapBounds/MapBounds";
1219
import { TaskStatusColors } from "../../services/Task/TaskStatus/TaskStatus";
1320
import { buildLayerSources } from "../../services/VisibleLayer/LayerSources";
@@ -120,6 +127,7 @@ export const ActivityMap = (props) => {
120127
/>
121128
<ResizeMap />
122129
<AttributionControl position="bottomleft" prefix={false} />
130+
<ScaleControl position="bottomleft" />
123131
<VisibleTileLayer {...props} zIndex={1} noWrap bounds={toLatLngBounds(GLOBAL_MAPBOUNDS)} />
124132
{overlayLayers}
125133
{coloredMarkers}

src/components/BoundsSelectorModal/BoundsSelectorModal.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import classNames from "classnames";
33
import _split from "lodash/split";
44
import { Component, Fragment } from "react";
55
import { FormattedMessage } from "react-intl";
6-
import { AttributionControl, MapContainer } from "react-leaflet";
6+
import { AttributionControl, MapContainer, ScaleControl } from "react-leaflet";
77
import { fromLatLngBounds, toLatLngBounds } from "../../services/MapBounds/MapBounds";
88
import { DEFAULT_MAP_BOUNDS } from "../../services/MapBounds/MapBounds";
99
import { defaultLayerSource } from "../../services/VisibleLayer/LayerSources";
@@ -103,6 +103,7 @@ export default class BoundsSelectorModal extends Component {
103103
fitBoundsControl
104104
/>
105105
<AttributionControl position="bottomleft" prefix={false} />
106+
<ScaleControl position="bottomleft" />
106107
<SourcedTileLayer source={defaultLayerSource()} skipAttribution={true} />
107108
<AreaSelect
108109
bounds={boundingBox}

src/components/EnhancedMap/MapPane/MapPane.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
color: $grey;
107107
}
108108
}
109+
110+
.leaflet-control-scale.leaflet-control {
111+
top: 0;
112+
box-shadow: none;
113+
}
109114
}
110115
}
111116

src/components/EnhancedMap/SourcedTileLayer/SourcedTileLayer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import TileLayerErrorBoundary from "../../TaskClusterMap/TileLayerErrorBoundary"
2222
*
2323
* @author [Neil Rotstan](https://github.com/nrotstan)
2424
*/
25-
const SourcedTileLayerInternal = (props) => {
25+
const SourcedTileLayerInternal = ({ className, ...props }) => {
2626
const [layerRenderFailed, setLayerRenderFailed] = useState(false);
2727

2828
const attribution = (layer) => {

src/components/InsetMap/InsetMap.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import classNames from "classnames";
22
import PropTypes from "prop-types";
33
import { Component, useEffect } from "react";
4-
import { AttributionControl, MapContainer, Marker, useMap } from "react-leaflet";
4+
import { AttributionControl, MapContainer, Marker, ScaleControl, useMap } from "react-leaflet";
55
import { defaultLayerSource, layerSourceWithId } from "../../services/VisibleLayer/LayerSources";
66
import SourcedTileLayer from "../EnhancedMap/SourcedTileLayer/SourcedTileLayer";
77
import "./InsetMap.scss";
@@ -36,6 +36,7 @@ export default class InsetMap extends Component {
3636
>
3737
<ResizeMap />
3838
<AttributionControl position="bottomleft" prefix={false} />
39+
<ScaleControl position="bottomleft" />
3940
<SourcedTileLayer source={layerSource} skipAttribution={true} />
4041
<Marker
4142
position={this.props.centerPoint}

src/components/SupplementalMap/SupplementalMap.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import _map from "lodash/map";
44
import _sortBy from "lodash/sortBy";
55
import _uniqueId from "lodash/uniqueId";
66
import { useEffect, useState } from "react";
7-
import { AttributionControl, MapContainer, Pane, useMap } from "react-leaflet";
7+
import { AttributionControl, MapContainer, Pane, ScaleControl, useMap } from "react-leaflet";
88
import {
99
DEFAULT_ZOOM,
1010
MAX_ZOOM,
@@ -131,6 +131,7 @@ const SupplementalMap = (props) => {
131131
>
132132
<ResizeMap />
133133
<AttributionControl position="bottomleft" prefix={false} />
134+
<ScaleControl position="bottomleft" />
134135
<SupplementalMapContent {...props} />
135136
</MapContainer>
136137
</div>

src/components/TaskClusterMap/MapControlsDrawer.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ const MapControlsDrawer = (props) => {
365365
transition: transform 0.3s ease-in-out;
366366
}
367367
368+
.map-controls-drawer:not(.open) .map-drawer-content {
369+
display: none;
370+
}
371+
368372
/* Add styles for lasso icons */
369373
.lasso-icon-container {
370374
position: relative;

src/components/TaskClusterMap/TaskClusterMap.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
height: 100%;
5656
}
5757

58-
.leaflet-control-scale {
59-
top: 0px !important;
60-
}
6158
}
6259

6360
.greyscale-cluster {

src/components/TaskPane/TaskMap/TaskMap.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
LayerGroup,
2222
MapContainer,
2323
Pane,
24+
ScaleControl,
2425
useMap,
2526
useMapEvents,
2627
} from "react-leaflet";
@@ -769,6 +770,7 @@ const TaskMap = (props) => {
769770
>
770771
<ResizeMap />
771772
<AttributionControl position="bottomleft" prefix={false} />
773+
<ScaleControl position="bottomleft" />
772774
<TaskMapContent {...props} />
773775
</MapContainer>
774776
</div>

src/components/TaskPane/TaskNearbyList/TaskNearbyMap.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import "leaflet-vectoricon";
66
import "leaflet.markercluster/dist/MarkerCluster.css";
77
import _cloneDeep from "lodash/cloneDeep";
88
import _map from "lodash/map";
9-
import { AttributionControl, MapContainer, Marker, Tooltip, useMap } from "react-leaflet";
9+
import {
10+
AttributionControl,
11+
MapContainer,
12+
Marker,
13+
ScaleControl,
14+
Tooltip,
15+
useMap,
16+
} from "react-leaflet";
1017
import resolveConfig from "tailwindcss/resolveConfig";
1118
import AsMappableTask from "../../../interactions/Task/AsMappableTask";
1219
import {
@@ -271,6 +278,7 @@ export class TaskNearbyMap extends Component {
271278
/>
272279
<ResizeMap />
273280
<AttributionControl position="bottomleft" prefix={false} />
281+
<ScaleControl position="bottomleft" />
274282

275283
<VisibleTileLayer {...this.props} zIndex={1} />
276284
{overlayLayers}

0 commit comments

Comments
 (0)