Skip to content

Commit

Permalink
Mouseover popUp to show tract info (#111)
Browse files Browse the repository at this point in the history
* feat: adding tract info popUp to mouseover event

* fix: feature properites type errors

---------

Co-authored-by: avenmia <[email protected]>
  • Loading branch information
kmal808 and avenmia authored Apr 6, 2023
1 parent fd55967 commit 16a27e0
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/censusmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ interface LayerEventTarget {
};
}

interface FeatureProperties {
tractname: string;
name20: string;
pop20: number;
}

interface GeoJSONElement {
resetStyle: (element: any) => void;
}
Expand Down Expand Up @@ -56,10 +62,16 @@ const CensusTractMap: NextPage = () => {
setDisabled(false);
});
layer.on("mouseover", (e: LeafletMouseEvent) => {
const featureProperties = feature.properties as FeatureProperties;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
e.target.setStyle({
fillOpacity: 0.5,
});
e.target
.setStyle({
fillOpacity: 0.5,
})
.bindPopup(
`Name: ${featureProperties["tractname"]} <br> Tract: ${featureProperties["name20"]} <br> Population: ${featureProperties["pop20"]}`
)
.openPopup();
});
layer.on("mouseout", (e: LeafletMouseEvent) => {
if (!geoJsonRef.current) {
Expand Down Expand Up @@ -115,9 +127,9 @@ const CensusTractMap: NextPage = () => {
style={{ height: "385px" }}
>
<EsriLeafletGeoSearch
position="topleft"
expanded={true}
placeholder="Search for your address"
position="topleft"
expanded={true}
placeholder="Search for your address"
searchBounds={[
[18.367807, -162.171387],
[23.131708, -153.404297],
Expand Down

1 comment on commit 16a27e0

@vercel
Copy link

@vercel vercel bot commented on 16a27e0 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hierr – ./

hierr.vercel.app
hierr-codeforhawaii.vercel.app
hierr-git-main-codeforhawaii.vercel.app

Please sign in to comment.