Skip to content

Commit 8707b94

Browse files
authored
Hide boundaries on map (#690)
* Hide boundaries on map * Hide boundaries on map
1 parent fd8c094 commit 8707b94

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useMap } from 'react-map-gl'
2+
3+
export function HideBoundaries() {
4+
const { current: map } = useMap()
5+
if (map) {
6+
map.on('load', () => {
7+
const layersToHide = [
8+
'admin-2-boundaries',
9+
'admin-2-boundaries-bg',
10+
'admin-3-4-boundaries',
11+
'admin-3-4-boundaries-bg',
12+
]
13+
14+
layersToHide.forEach((layerId) => {
15+
// Check if the layer actually exists in the current style before trying to hide it
16+
if (map && map.getLayer(layerId)) {
17+
map.getMap().setLayoutProperty(
18+
layerId,
19+
'visibility',
20+
'none'
21+
)
22+
}
23+
})
24+
})
25+
}
26+
return null
27+
}

deployment/frontend/src/components/_shared/map/controls/Settings.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { type MapRef } from 'react-map-gl'
66
import Boundaries from './Boundaries'
77
import { SettingsIcon } from '../../icons/SettingsIcon'
88

9-
import dynamic from 'next/dynamic';
9+
import dynamic from 'next/dynamic'
1010
const Modal = dynamic(() => import('@/components/_shared/Modal'), {
1111
ssr: false,
12-
});
12+
})
1313

1414
export default function Settings({
1515
mapRef,
@@ -18,7 +18,7 @@ export default function Settings({
1818
}) {
1919
const [open, setOpen] = useState(false)
2020
return (
21-
<IconButton tooltip='Map settings' onClick={() => setOpen(true)}>
21+
<IconButton tooltip="Map settings" onClick={() => setOpen(true)}>
2222
<SettingsIcon />
2323
<Modal open={open} setOpen={setOpen} className="max-w-[36rem]">
2424
<h2 className="font-['Acumin Pro SemiCondensed'] text-3xl font-normal text-black mb-5">
@@ -31,12 +31,8 @@ export default function Settings({
3131
<div className="basis-1/2 pr-2">
3232
<LabelSelector />
3333
</div>
34-
<div className="basis-1/2">
35-
<Boundaries mapRef={mapRef} />
36-
</div>
3734
</div>
3835
</Modal>
3936
</IconButton>
4037
)
4138
}
42-

deployment/frontend/src/components/dashboard/datasets/admin/datafiles/DatafileLocation.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import notify from '@/utils/notify'
1515
import Spinner from '@/components/_shared/Spinner'
1616
import { UseFormReturn } from 'react-hook-form'
1717
import * as turf from '@turf/turf'
18+
import { HideBoundaries } from '@/components/_shared/HideBoundaries'
1819

1920
export function DatafileLocation({
2021
formObj,
@@ -211,6 +212,7 @@ export function DatafileLocation({
211212
touchZoomRotate={false}
212213
initialViewState={{ zoom: 2 }}
213214
>
215+
<HideBoundaries />
214216
<Source
215217
type="geojson"
216218
data={watch(
@@ -248,6 +250,7 @@ export function DatafileLocation({
248250
dragRotate={false}
249251
touchZoomRotate={false}
250252
>
253+
<HideBoundaries />
251254
<GeocoderControl
252255
mapboxAccessToken="pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHNueG5idGIwOXMzMmp0ZzE1NWVjZDV1In0.050LmRm-9m60lrzhpsKqNA"
253256
position="bottom-right"

deployment/frontend/src/components/dashboard/datasets/admin/metadata/LocationForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import GeocoderControl from '@/components/search/GeocoderControl'
2121
import { Layer, Map, Source } from 'react-map-gl'
2222
import notify from '@/utils/notify'
2323
import Spinner from '@/components/_shared/Spinner'
24+
import { HideBoundaries } from '@/components/_shared/HideBoundaries'
2425

2526
export function LocationForm({
2627
formObj,
@@ -245,6 +246,7 @@ export function LocationForm({
245246
touchZoomRotate={false}
246247
initialViewState={{ zoom: 2 }}
247248
>
249+
<HideBoundaries />
248250
<Source
249251
type="geojson"
250252
data={watch('spatial')}
@@ -280,6 +282,7 @@ export function LocationForm({
280282
dragRotate={false}
281283
touchZoomRotate={false}
282284
>
285+
<HideBoundaries />
283286
<GeocoderControl
284287
mapboxAccessToken="pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHNueG5idGIwOXMzMmp0ZzE1NWVjZDV1In0.050LmRm-9m60lrzhpsKqNA"
285288
position="bottom-right"
@@ -292,7 +295,9 @@ export function LocationForm({
292295
onClear={(e) => {
293296
setValue('spatial_address', '')
294297
}}
295-
initialValue={watch('spatial_address') ?? undefined}
298+
initialValue={
299+
watch('spatial_address') ?? undefined
300+
}
296301
/>
297302
</Map>
298303
</Tab.Panel>

deployment/frontend/src/components/datasets/sections/LocationSearch.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import {
77
MapRef,
88
Marker,
99
Source,
10+
useMap,
1011
} from 'react-map-gl'
1112
import GeocoderControl from '@/components/search/GeocoderControl'
1213
import { useQuery } from 'react-query'
1314
import { UseFormReturn, useForm } from 'react-hook-form'
1415
import DrawControl from '@/components/search/Draw'
1516
import { LocationSearchFormType } from './DataFiles'
17+
import { HideBoundaries } from '@/components/_shared/HideBoundaries'
1618

1719
export default function LocationSearch({
1820
geojsons,
@@ -126,7 +128,6 @@ export default function LocationSearch({
126128
}
127129
}, [])
128130

129-
console.log('cursor', cursor)
130131
return (
131132
<Map
132133
ref={(_map) => {
@@ -145,6 +146,7 @@ export default function LocationSearch({
145146
onClick={handleMapClick}
146147
cursor={cursor}
147148
>
149+
<HideBoundaries />
148150
<GeocoderControl
149151
mapboxAccessToken="pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHNueG5idGIwOXMzMmp0ZzE1NWVjZDV1In0.050LmRm-9m60lrzhpsKqNA"
150152
position="bottom-right"

deployment/frontend/src/components/search/LocationSearch.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Dispatch, SetStateAction } from 'react'
66
import { SearchInput } from '@/schema/search.schema'
77
import { Filter } from '@/interfaces/search.interface'
88
import classNames from '@/utils/classnames'
9+
import { HideBoundaries } from '../_shared/HideBoundaries'
910

1011
export default function LocationSearch({
1112
setFilters,
@@ -145,6 +146,7 @@ export default function LocationSearch({
145146
dragRotate={false}
146147
touchZoomRotate={false}
147148
>
149+
<HideBoundaries />
148150
<GeocoderControl
149151
mapboxAccessToken="pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHNueG5idGIwOXMzMmp0ZzE1NWVjZDV1In0.050LmRm-9m60lrzhpsKqNA"
150152
position="bottom-right"

0 commit comments

Comments
 (0)