Skip to content

Commit

Permalink
feat: Pass selected property to map view
Browse files Browse the repository at this point in the history
  • Loading branch information
markgoetz committed Jan 19, 2024
1 parent e009418 commit 663f142
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/app/components/PropertyMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, {
Dispatch,
SetStateAction,
} from "react";
import mapboxgl, { Map as MapboxMap, Point, PointLike } from "mapbox-gl";
import mapboxgl, { Map as MapboxMap, PointLike } from "mapbox-gl";
import { mapboxAccessToken } from "../../config/config";
import { useFilter } from "@/context/FilterContext";
import LegendControl from "mapboxgl-legend";
Expand Down Expand Up @@ -70,13 +70,15 @@ const MapControls = () => (
interface PropertyMapProps {
setFeaturesInView: Dispatch<SetStateAction<any[]>>;
setLoading: Dispatch<SetStateAction<boolean>>;
selectedProperty: MapboxGeoJSONFeature | null;
setSelectedProperty: (property: MapboxGeoJSONFeature | null) => void;
}
const PropertyMap: React.FC<PropertyMapProps> = ({
setFeaturesInView,
setLoading,
selectedProperty,
setSelectedProperty,
}: any) => {
}) => {
const { filter } = useFilter();
const [popupInfo, setPopupInfo] = useState<any | null>(null);
const [map, setMap] = useState<MapboxMap | null>(null);
Expand Down Expand Up @@ -231,6 +233,19 @@ const PropertyMap: React.FC<PropertyMapProps> = ({
}
}, [map, filter, updateFilter]);

const id = selectedProperty?.properties?.OPA_ID ?? null;
useEffect(() => {
/** Ticket #87 - focus on map when a property is selected */
if (id && map != null) {
const features = map.queryRenderedFeatures(undefined, {
layers: ["vacant_properties"],
});
const mapItem = features.find(feature => feature.properties?.OPA_ID === id);
console.log({ mapItem });
// TODO: Focus the map on the given lat/long.
}
}, [id]);

const changeCursor = (e: any, cursorType: "pointer" | "default") => {
e.target.getCanvas().style.cursor = cursorType;
};
Expand Down
1 change: 1 addition & 0 deletions src/app/map/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Page: FC = () => {
<PropertyMap
setFeaturesInView={setFeaturesInView}
setLoading={setLoading}
selectedProperty={selectedProperty}
setSelectedProperty={setSelectedProperty}
/>
</div>
Expand Down

0 comments on commit 663f142

Please sign in to comment.