Skip to content

Commit dc84a95

Browse files
reintroduces style switcher and adds types
1 parent c6e3bfd commit dc84a95

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/components/MapStyleSwitcher.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ const MapStyleSwitcher: React.FC<MapStyleSwitcherProps> = ({
1414
useEffect(() => {
1515
console.log('MapStyleSwitcher rendered', handleStyleChange);
1616
});
17-
const baseMaps = {
17+
type BaseMap = {
18+
name: string;
19+
img: string;
20+
};
21+
22+
type BaseMaps = Record<string, BaseMap>;
23+
24+
const baseMaps: BaseMaps = {
1825
STREETS: {
1926
name: 'Street',
2027
img: 'https://cloud.maptiler.com/static/img/maps/streets.png',
@@ -37,7 +44,7 @@ const MapStyleSwitcher: React.FC<MapStyleSwitcherProps> = ({
3744

3845
return (
3946
<div
40-
className="relative maplibregl-ctrl maplibregl-ctrl-basemaps"
47+
className="relative maplibregl-ctrl maplibregl-ctrl-basemaps p-2"
4148
onMouseEnter={() => setIsHovered(true)}
4249
onMouseLeave={() => setIsHovered(false)}
4350
>
@@ -51,7 +58,7 @@ const MapStyleSwitcher: React.FC<MapStyleSwitcherProps> = ({
5158
/>
5259

5360
<div
54-
className={`absolute flex flex-row items-center transition-transform duration-300 ${
61+
className={`absolute flex flex-row items-center pl-2 transition-transform duration-300 ${
5562
isHovered
5663
? 'translate-x-20 opacity-100'
5764
: 'translate-x-0 opacity-0 pointer-events-none'

src/components/PropertyMap.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Dispatch,
99
SetStateAction,
1010
ReactElement,
11-
ElementRef,
1211
} from 'react';
1312
import {
1413
maptilerApiKey,
@@ -108,7 +107,13 @@ const layerStylePoints: CircleLayerSpecification = {
108107
},
109108
};
110109

111-
const mapStyles = {
110+
type MapStyle = {
111+
url: string;
112+
};
113+
114+
type MapStyles = Record<string, MapStyle>;
115+
116+
const mapStyles: MapStyles = {
112117
DataVisualization: {
113118
url: `https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`,
114119
},
@@ -131,6 +136,8 @@ const MapControls: React.FC<{
131136
<>
132137
<NavigationControl showCompass={false} position="bottom-right" />
133138
<GeolocateControl position="bottom-right" />
139+
<ScaleControl />
140+
<MapStyleSwitcher handleStyleChange={handleStyleChange} />
134141
{smallScreenToggle || window.innerWidth > 640 ? (
135142
<MapLegendControl
136143
position="bottom-left"
@@ -509,21 +516,13 @@ const PropertyMap: FC<PropertyMapProps> = ({
509516
onError={(e) => {
510517
console.log(e);
511518
if (
512-
e.message ===
519+
e.error.cause ===
513520
"The layer 'vacant_properties_tiles_polygons' does not exist in the map's style and cannot be queried for features."
514521
)
515522
setHasLoadingError(true);
516523
}}
517524
onLoad={(e) => {
518525
setMap(e.target);
519-
const attributionButton: HTMLElement | null = document.querySelector(
520-
'.maplibregl-ctrl-attrib-button'
521-
);
522-
if (attributionButton) {
523-
attributionButton.click();
524-
} else {
525-
console.warn('Attribution button not found.');
526-
}
527526
}}
528527
onSourceData={(e) => {
529528
handleSetFeatures(e);

0 commit comments

Comments
 (0)