Skip to content

Commit

Permalink
adds map scale
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgnlez committed Jan 26, 2024
1 parent 913a7d8 commit ac69bfb
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 52 deletions.
17 changes: 17 additions & 0 deletions app/components/map/scale/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ComponentProps } from 'react';

import { ScaleControl } from 'react-map-gl';

import { cn } from 'utils/cn';

const MapScale = ({ className, ...props }: ComponentProps<typeof ScaleControl>): JSX.Element => (
<ScaleControl
{...props}
className={cn({
'absolute bottom-6 right-[305px]': true,
[className]: !!className,
})}
/>
);

export default MapScale;
15 changes: 10 additions & 5 deletions app/layout/project/reports/comparison/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useProject } from 'hooks/projects';
import { useScenarios } from 'hooks/scenarios';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ScreenshotComparisionMap = ({ id }: { id: string }): JSX.Element => {
const [cache] = useState<number>(Date.now());
Expand Down Expand Up @@ -145,11 +146,15 @@ export const ScreenshotComparisionMap = ({ id }: { id: string }): JSX.Element =>
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
{LAYERS.map((l) => (
<Layer key={l.id} {...l} />
))}
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
{LAYERS.map((l) => (
<Layer key={l.id} {...l} />
))}
</LayerManager>

<MapScale />
</>
);
}}
</Map>
Expand Down
14 changes: 9 additions & 5 deletions app/layout/projects/new/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Controls from 'components/map/controls';
import FitBoundsControl from 'components/map/controls/fit-bounds';
import LoadingControl from 'components/map/controls/loading';
import ZoomControl from 'components/map/controls/zoom';
import MapScale from 'components/map/scale';
import type { NewProjectFields } from 'layout/projects/new/form';
import { MapProps } from 'types/map';
import { centerMap } from 'utils/map';
Expand Down Expand Up @@ -167,11 +168,14 @@ export const ProjectNewMap = ({
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
{LAYERS.map((l) => (
<Layer key={l.id} {...l} />
))}
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
{LAYERS.map((l) => (
<Layer key={l.id} {...l} />
))}
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
18 changes: 12 additions & 6 deletions app/layout/projects/show/map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentProps, useCallback, useEffect, useMemo, useState, useRef } from 'react';

import { useQueryClient } from 'react-query';
import { ScaleControl } from 'react-map-gl';

import { useRouter } from 'next/router';

Expand Down Expand Up @@ -50,6 +50,7 @@ import LegendTypeBasic from 'components/map/legend/types/basic';
import LegendTypeChoropleth from 'components/map/legend/types/choropleth';
import LegendTypeGradient from 'components/map/legend/types/gradient';
import LegendTypeMatrix from 'components/map/legend/types/matrix';
import MapScale from 'components/map/scale';
import HelpBeacon from 'layout/help/beacon';
import { Scenario } from 'types/api/scenario';
import { MapProps } from 'types/map';
Expand Down Expand Up @@ -525,11 +526,14 @@ export const ProjectMap = (): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
{LAYERS.map((l) => (
<Layer key={l.id} {...l} />
))}
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
{LAYERS.map((l) => (
<Layer key={l.id} {...l} />
))}
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down Expand Up @@ -639,6 +643,8 @@ export const ProjectMap = (): JSX.Element => {
</Legend>
</div>

<ScaleControl className="absolute right-0 z-30" />

{!!SCENARIOS_RUNNED.sid1Options.length && !tab && (
<div
className={cn({
Expand Down
3 changes: 2 additions & 1 deletion app/layout/scenarios/edit/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import LegendTypeBasic from 'components/map/legend/types/basic';
import LegendTypeChoropleth from 'components/map/legend/types/choropleth';
import LegendTypeGradient from 'components/map/legend/types/gradient';
import LegendTypeMatrix from 'components/map/legend/types/matrix';
import MapScale from 'components/map/scale';
import { TABS } from 'layout/project/navigation/constants';
import ScenariosDrawingManager from 'layout/scenarios/edit/map/drawing-manager';
import { MapProps } from 'types/map';
Expand All @@ -69,7 +70,6 @@ export const ScenariosEditMap = (): JSX.Element => {
const { isSidebarOpen } = useAppSelector((state) => state['/projects/[id]']);

const accessToken = useAccessToken();
// const queryClient = useQueryClient();

const { query } = useRouter();

Expand Down Expand Up @@ -581,6 +581,7 @@ export const ScenariosEditMap = (): JSX.Element => {

{/* Drawing editor */}
<ScenariosDrawingManager />
<MapScale />
</>
);
}}
Expand Down
2 changes: 2 additions & 0 deletions app/layout/scenarios/new/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import LegendTypeBasic from 'components/map/legend/types/basic';
import LegendTypeChoropleth from 'components/map/legend/types/choropleth';
import LegendTypeGradient from 'components/map/legend/types/gradient';
import LegendTypeMatrix from 'components/map/legend/types/matrix';
import MapScale from 'components/map/scale';
import ScenariosDrawingManager from 'layout/scenarios/edit/map/drawing-manager';
import { MapProps } from 'types/map';
import { centerMap } from 'utils/map';
Expand Down Expand Up @@ -150,6 +151,7 @@ export const ScenarioNewMap = (): JSX.Element => {

{/* Drawing editor */}
<ScenariosDrawingManager />
<MapScale />
</>
);
}}
Expand Down
10 changes: 7 additions & 3 deletions app/layout/scenarios/reports/blm/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useBBOX, useScenarioBlmLayer } from 'hooks/map';
import { useProject } from 'hooks/projects';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export interface ScreenshotBLMMapProps {
id: string;
Expand Down Expand Up @@ -117,9 +118,12 @@ export const ScreenshotBLMMap: React.FC<ScreenshotBLMMapProps> = ({
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={BLMLayer.id} {...BLMLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={BLMLayer.id} {...BLMLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
10 changes: 7 additions & 3 deletions app/layout/scenarios/reports/frequency/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useBBOX, usePUGridLayer } from 'hooks/map';
import { useProject } from 'hooks/projects';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export interface ScreenshotBLMMapProps {
id: string;
Expand Down Expand Up @@ -118,9 +119,12 @@ export const ScreenshotBLMMap: React.FC<ScreenshotBLMMapProps> = ({
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useProject } from 'hooks/projects';
import { useBestSolution } from 'hooks/solutions';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ReportMap = ({ id }: { id: string }): JSX.Element => {
const accessToken = useAccessToken();
Expand Down Expand Up @@ -111,9 +112,12 @@ export const ReportMap = ({ id }: { id: string }): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useBBOX, useCostSurfaceLayer } from 'hooks/map';
import { useProject } from 'hooks/projects';

import Map from 'components/map';
import MapScale from 'components/map/scale';

const minZoom = 2;
const maxZoom = 20;
Expand Down Expand Up @@ -119,9 +120,12 @@ export const CostSurfaceReportMap = ({ id }: { id: string }): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useBBOX, usePUGridLayer } from 'hooks/map';
import { useProject } from 'hooks/projects';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ReportMap = ({ id, runId }: { id: string; runId: number }): JSX.Element => {
const accessToken = useAccessToken();
Expand Down Expand Up @@ -108,9 +109,12 @@ export const ReportMap = ({ id, runId }: { id: string; runId: number }): JSX.Ele
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
10 changes: 7 additions & 3 deletions app/layout/scenarios/reports/solutions/frequency/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useProject } from 'hooks/projects';
import { useScenario } from 'hooks/scenarios';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ReportMap = ({ id }: { id: string }): JSX.Element => {
const [cache] = useState<number>(Date.now());
Expand Down Expand Up @@ -112,9 +113,12 @@ export const ReportMap = ({ id }: { id: string }): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
10 changes: 7 additions & 3 deletions app/layout/scenarios/reports/solutions/grid/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useBBOX, usePUGridLayer } from 'hooks/map';
import { useProject } from 'hooks/projects';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ReportMap = ({ id }: { id: string }): JSX.Element => {
const accessToken = useAccessToken();
Expand Down Expand Up @@ -108,9 +109,12 @@ export const ReportMap = ({ id }: { id: string }): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
10 changes: 7 additions & 3 deletions app/layout/scenarios/reports/solutions/pu-status/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useScenario, useScenarioPU } from 'hooks/scenarios';
import { useWDPACategories } from 'hooks/wdpa';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ReportMap = ({ id }: { id: string }): JSX.Element => {
const accessToken = useAccessToken();
Expand Down Expand Up @@ -128,9 +129,12 @@ export const ReportMap = ({ id }: { id: string }): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useScenario } from 'hooks/scenarios';
import { useBestSolution, useSolution } from 'hooks/solutions';

import Map from 'components/map';
import MapScale from 'components/map/scale';

export const ScenariosReportMap = ({ id }: { id: string }): JSX.Element => {
const accessToken = useAccessToken();
Expand Down Expand Up @@ -124,9 +125,12 @@ export const ScenariosReportMap = ({ id }: { id: string }): JSX.Element => {
>
{(map) => {
return (
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<>
<LayerManager map={map} plugin={PluginMapboxGl}>
<Layer key={PUGridLayer.id} {...PUGridLayer} />
</LayerManager>
<MapScale />
</>
);
}}
</Map>
Expand Down
11 changes: 3 additions & 8 deletions app/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,8 @@ a.mapboxgl-ctrl-logo.mapboxgl-compact {
display: none;
}
.mapboxgl-ctrl-scale {
background-color: hsla(0, 0%, 100%, 0.75);
font-size: 10px;
border: 2px solid #333;
border-top: #333;
padding: 0 5px;
color: #333;
box-sizing: border-box;
background-color: hsla(0, 0%, 100%, 0.50);
@apply text-xs text-center text-gray-900 uppercase !w-20;
}
.mapboxgl-popup {
position: absolute;
Expand Down Expand Up @@ -812,4 +807,4 @@ a.mapboxgl-ctrl-logo.mapboxgl-compact {
.modal-checkbox-list {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
}

0 comments on commit ac69bfb

Please sign in to comment.