-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/WG-5: complete leaflet map (#284)
* Add zoom-to-feature on feature selection * Do some performance optimizations * Refactor zoom bahvior into own file * Add display of geosjson features and point clouds to map * Refactor selecting feature to be a hook * Add click on top-level to get back to main menu * Fix issue of bounds when navigating between projects Clear feature queries when changing projects as causing an issue when trying to zoom to map bounds as old projects features were still there. * Add missing file * Use react-leaflet-cluster * Remove unused import * Remove unused topNavbar class * Add link to main page when clicking in HeaderNavBar * Use icons for point markers * Minor changes * Fix unit test * Add missing files * Improve TypeScript types/constants to replace string literals * Add font awesome icons * Revert "Add font awesome icons" This reverts commit cdae716. * Add custom markers * Use css module * Refactor marker work into seperate file * Add missing file; improve sizes and comments * Tweak css * Add underscore to non-exported methods * Add aria * Add type info
- Loading branch information
1 parent
04a764f
commit a0e4ab3
Showing
21 changed files
with
634 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,16 @@ | ||
import React from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'; | ||
import { | ||
faCameraRetro, | ||
faVideo, | ||
faClipboardList, | ||
faMapMarkerAlt, | ||
faDrawPolygon, | ||
faCloud, | ||
faBezierCurve, | ||
faRoad, | ||
faLayerGroup, | ||
faQuestionCircle, | ||
} from '@fortawesome/free-solid-svg-icons'; | ||
|
||
import { FeatureType, FeatureTypeNullable } from '@hazmapper/types'; | ||
import { FeatureTypeNullable } from '@hazmapper/types'; | ||
import { featureTypeToIcon } from '@hazmapper/utils/featureIconUtil'; | ||
import styles from './FeatureIcon.module.css'; | ||
|
||
const featureTypeToIcon: Record<FeatureType, IconDefinition> = { | ||
// Asset types | ||
image: faCameraRetro, | ||
video: faVideo, | ||
questionnaire: faClipboardList, | ||
point_cloud: faCloud /* https://tacc-main.atlassian.net/browse/WG-391 */, | ||
streetview: faRoad, | ||
|
||
// Geometry types | ||
Point: faMapMarkerAlt, | ||
LineString: faBezierCurve, | ||
Polygon: faDrawPolygon, | ||
MultiPoint: faMapMarkerAlt, | ||
MultiLineString: faBezierCurve, | ||
MultiPolygon: faDrawPolygon, | ||
GeometryCollection: faLayerGroup, | ||
|
||
// Collection type | ||
collection: faLayerGroup, | ||
}; | ||
|
||
interface Props { | ||
featureType: FeatureTypeNullable; | ||
} | ||
|
||
export const FeatureIcon: React.FC<Props> = ({ featureType }) => { | ||
const icon = featureType ? featureTypeToIcon[featureType] : faQuestionCircle; | ||
const icon = featureTypeToIcon(featureType); | ||
|
||
return <FontAwesomeIcon className={styles.icon} icon={icon} size="sm" />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useEffect, useCallback, useRef } from 'react'; | ||
import * as turf from '@turf/turf'; | ||
import { useMap } from 'react-leaflet'; | ||
import { FeatureCollection, Feature } from '@hazmapper/types'; | ||
import { useFeatureSelection } from '@hazmapper/hooks'; | ||
import { MAP_CONFIG } from './config'; | ||
import L from 'leaflet'; | ||
|
||
const FitBoundsHandler: React.FC<{ | ||
featureCollection: FeatureCollection; | ||
}> = ({ featureCollection }) => { | ||
const map = useMap(); | ||
const hasFeatures = useRef(false); | ||
const { selectedFeatureId } = useFeatureSelection(); | ||
|
||
const getBoundsFromFeature = useCallback( | ||
(feature: FeatureCollection | Feature) => { | ||
const bbox = turf.bbox(feature); | ||
return [ | ||
[bbox[1], bbox[0]] as [number, number], | ||
[bbox[3], bbox[2]] as [number, number], | ||
]; | ||
}, | ||
[] | ||
); | ||
|
||
const zoomToFeature = useCallback( | ||
(feature: Feature) => { | ||
if (feature.geometry.type === 'Point') { | ||
const coordinates = feature.geometry.coordinates; | ||
const point = L.latLng(coordinates[1], coordinates[0]); | ||
|
||
map.setView(point, MAP_CONFIG.maxPointSelectedFeatureZoom, { | ||
animate: false, | ||
}); | ||
} else { | ||
const bounds = getBoundsFromFeature(feature); | ||
map.fitBounds(bounds, { | ||
maxZoom: MAP_CONFIG.maxFitBoundsSelectedFeatureZoom, | ||
padding: [50, 50], | ||
animate: false, | ||
}); | ||
} | ||
}, | ||
[map, getBoundsFromFeature] | ||
); | ||
|
||
// Handle initial bounds when features are loaded | ||
useEffect(() => { | ||
if ( | ||
featureCollection.features.length && | ||
!selectedFeatureId && | ||
!hasFeatures.current | ||
) { | ||
const bounds = getBoundsFromFeature(featureCollection); | ||
map.fitBounds(bounds, { | ||
maxZoom: MAP_CONFIG.maxFitBoundsInitialZoom, | ||
padding: [50, 50], | ||
}); | ||
hasFeatures.current = true; | ||
} | ||
}, [map, featureCollection, selectedFeatureId, getBoundsFromFeature]); | ||
|
||
// Handle selected feature bounds | ||
useEffect(() => { | ||
if (selectedFeatureId) { | ||
const activeFeature = featureCollection.features.find( | ||
(f) => f.id === selectedFeatureId | ||
); | ||
|
||
if (activeFeature) { | ||
zoomToFeature(activeFeature); | ||
} | ||
} | ||
}, [map, selectedFeatureId, featureCollection, zoomToFeature]); | ||
|
||
return null; | ||
}; | ||
|
||
export default FitBoundsHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.markerCluster { | ||
/* Size and shape */ | ||
min-width: 36px; | ||
min-height: 36px; | ||
border-radius: 50%; | ||
|
||
/* Colors and borders */ | ||
color: #ffffff; | ||
background: var(--global-color-accent--normal); | ||
border: 3px solid #ffffff; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
|
||
/* Centering container */ | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
/* Text styling */ | ||
font-family: var(--global-font-family--sans); | ||
font-size: 14px; | ||
font-weight: 500; | ||
line-height: 1; | ||
text-align: center; | ||
} | ||
|
||
/* Style for the span containing the number */ | ||
.markerCluster span { | ||
/* Additional centering for the text itself */ | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
/* Offset slightly to account for border */ | ||
margin-top: -1px; | ||
} | ||
|
||
.marker { | ||
border-radius: 50%; | ||
} | ||
|
||
.markerContainer { | ||
border-radius: 50%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.