Skip to content
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
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
PROJECT_ROOT: __dirname,
},
images: {
domains: ['storage.googleapis.com'],
domains: ['storage.googleapis.com', 'cloud.maptiler.com'],
},
async redirects() {
return [
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@heroicons/react": "^2.1.5",
"@maptiler/sdk": "^2.5.1",
"@maptiler/geocoding-control": "^1.4.1",
"@nextui-org/react": "^2.4.6",
"@phosphor-icons/react": "^2.1.7",
Expand Down
91 changes: 91 additions & 0 deletions src/components/MapStyleSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use client';
import React, { useEffect, useState } from 'react';
import Image from 'next/image';

interface MapStyleSwitcherProps {
handleStyleChange: (style: string) => void;
}

const MapStyleSwitcher: React.FC<MapStyleSwitcherProps> = ({
handleStyleChange,
}) => {
const [activeStyle, setActiveStyle] = useState('DATAVIZ');
const [isHovered, setIsHovered] = useState(false);
type BaseMap = {
name: string;
img: string;
};

type BaseMaps = Record<string, BaseMap>;

const baseMaps: BaseMaps = {
DATAVIZ: {
name: 'DataVisualization',
img: 'https://cloud.maptiler.com/static/img/maps/dataviz.png',
},
HYBRID: {
name: 'Hybrid',
img: 'https://cloud.maptiler.com/static/img/maps/hybrid.png',
},
STREETS: {
name: 'Street',
img: 'https://cloud.maptiler.com/static/img/maps/streets.png',
},
};

useEffect(() => {
handleStyleChange(baseMaps[activeStyle].name);
}, [activeStyle]);

const onClick = (key: string) => {
setActiveStyle(key);
handleStyleChange(baseMaps[key].name);
};

return (
<div
className="relative maplibregl-ctrl maplibregl-ctrl-basemaps p-2 w-1/5"
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
<Image
src={baseMaps[activeStyle].img}
alt={activeStyle}
width={65}
height={65}
title={activeStyle.toLowerCase()}
className="cursor-pointer w-16 h-16 rounded-md border-2 border-gray-400 z-10"
/>

<div
className={`absolute flex flex-row items-center pl-2 transition-transform duration-300 ${
isHovered
? 'translate-x-20 opacity-100'
: 'translate-x-0 opacity-0 pointer-events-none'
}`}
style={{
left: '4rem',
top: '50%',
transform: 'translateY(-50%)',
}}
>
{Object.keys(baseMaps)
.filter((key) => key !== activeStyle)
.map((key) => (
<Image
key={key}
src={baseMaps[key].img}
alt={key}
width={65}
height={65}
title={key.toLowerCase()}
onClick={() => onClick(key)}
className={`cursor-pointer rounded-md border-2 border-transparent hover:border-gray-400`}
/>
))}
</div>
</div>
);
};

export default MapStyleSwitcher;
53 changes: 47 additions & 6 deletions src/components/PropertyMap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';

import '../components/components-css/PropertyMap.css';
import {
FC,
useEffect,
Expand All @@ -25,6 +25,7 @@ import Map, {
} from 'react-map-gl/maplibre';
import maplibregl, {
Map as MaplibreMap,
IControl,
PointLike,
MapGeoJSONFeature,
ColorSpecification,
Expand All @@ -49,6 +50,13 @@ import { centroid } from '@turf/centroid';
import { Position } from 'geojson';
import { toTitleCase } from '../utilities/toTitleCase';
import { ThemeButton } from '../components/ThemeButton';
import MapStyleSwitcher from './MapStyleSwitcher';

type MapStyle = {
url: string;
};

type MapStyles = Record<string, MapStyle>;

type SearchedProperty = {
coordinates: [number, number];
Expand Down Expand Up @@ -104,15 +112,30 @@ const layerStylePoints: CircleLayerSpecification = {
},
};

const mapStyles: MapStyles = {
DataVisualization: {
url: `https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`,
},
Hybrid: {
url: `https://api.maptiler.com/maps/hybrid/style.json?key=${maptilerApiKey}`,
},
Street: {
url: `https://api.maptiler.com/maps/streets/style.json?key=${maptilerApiKey}`,
},
};

// info icon in legend summary
let summaryInfo: ReactElement | null = null;

const MapControls = () => {
const MapControls: React.FC<{
handleStyleChange: (styleName: string) => void;
}> = ({ handleStyleChange }) => {
const [smallScreenToggle, setSmallScreenToggle] = useState<boolean>(false);
return (
<>
<NavigationControl showCompass={false} position="bottom-right" />
<GeolocateControl position="bottom-right" />
<MapStyleSwitcher handleStyleChange={handleStyleChange} />
{smallScreenToggle || window.innerWidth > 640 ? (
<MapLegendControl
position="bottom-left"
Expand Down Expand Up @@ -161,7 +184,10 @@ const PropertyMap: FC<PropertyMapProps> = ({
const { appFilter } = useFilter();
const [popupInfo, setPopupInfo] = useState<any | null>(null);
const [map, setMap] = useState<MaplibreMap | null>(null);
const [mapController, setMapController] = useState();
const [mapController, setMapController] = useState<IControl>();
const [currentStyle, setCurrentStyle] = useState<string>(
'Data Visualization View'
);
const [searchedProperty, setSearchedProperty] = useState<SearchedProperty>({
coordinates: [-75.1628565788269, 39.97008211622267],
address: '',
Expand All @@ -180,6 +206,10 @@ const PropertyMap: FC<PropertyMapProps> = ({
handleMapClick(e.lngLat);
};

const handleStyleChange = (styleName: string) => {
setCurrentStyle(styleName);
};

const moveMap = (targetPoint: LngLatLike) => {
if (map) {
map.easeTo({
Expand Down Expand Up @@ -373,7 +403,7 @@ const PropertyMap: FC<PropertyMapProps> = ({
if (map) {
updateFilter();
}
}, [map, appFilter]);
}, [map, appFilter, currentStyle]);

const changeCursor = (e: any, cursorType: 'pointer' | 'default') => {
e.target.getCanvas().style.cursor = cursorType;
Expand All @@ -385,7 +415,7 @@ const PropertyMap: FC<PropertyMapProps> = ({
<Map
mapLib={maplibregl as any}
initialViewState={initialViewState}
mapStyle={`https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`}
mapStyle={mapStyles[currentStyle]?.url}
onMouseEnter={(e) => changeCursor(e, 'pointer')}
onMouseLeave={(e) => changeCursor(e, 'default')}
onClick={onMapClick}
Expand All @@ -409,8 +439,20 @@ const PropertyMap: FC<PropertyMapProps> = ({
onSourceData={(e) => {
handleSetFeatures(e);
}}
onStyleData={(e) => {
const layerIds = e.target
.getStyle()
.layers.map((layer: any) => layer.id);
const layersApplied = layers.every((layer) =>
layerIds.includes(layer)
);
if (layersApplied) {
setHasLoadingError(false);
}
}}
onMoveEnd={handleSetFeatures}
>
<MapControls handleStyleChange={handleStyleChange} />
<div
className="geocoding"
style={{
Expand Down Expand Up @@ -453,7 +495,6 @@ const PropertyMap: FC<PropertyMapProps> = ({
}}
/>
</div>
<MapControls />
{popupInfo && (
<Popup
className="customized-map-popup"
Expand Down
16 changes: 16 additions & 0 deletions src/components/components-css/PropertyMap.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.map-style-button {
position: absolute;
top: 10px;
left: 10px;
z-index: 1;
padding: 10px 15px;
background: white;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}

.map-style-button:hover {
background: #e0e0e0;
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { default as Hotjar } from './Hotjar';
export { default as Footer } from './Footer';
export { default as PropertyMap } from './PropertyMap';
export { default as PropertyDetailSection } from './PropertyDetailSection';
export { default as MapStyleSwitcher } from './MapStyleSwitcher';
export { default as SidePanel } from './SidePanel';
export { default as SidePanelControlBar } from './SidePanelControlBar';
export { default as FilterView } from './FilterView';
Expand Down
Loading