-
-
Notifications
You must be signed in to change notification settings - Fork 6
Conditionally Display Zoom Icons in Drawing Mode #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ export const Mapbox: React.FC<{ position?: { latitude: number; longitude: number | |
| const { mapData, setMapData } = useMapData(); // Consume the new context, get setMapData | ||
| const { setIsMapLoaded } = useMapLoading(); // Get setIsMapLoaded from context | ||
| const previousMapTypeRef = useRef<MapToggleEnum | null>(null) | ||
| const navigationControlRef = useRef<mapboxgl.NavigationControl | null>(null); | ||
|
|
||
| // Refs for long-press functionality | ||
| const longPressTimerRef = useRef<NodeJS.Timeout | null>(null); | ||
|
|
@@ -351,6 +352,19 @@ export const Mapbox: React.FC<{ position?: { latitude: number; longitude: number | |
|
|
||
| // Handle geolocation setup based on mode | ||
| setupGeolocationWatcher() | ||
|
|
||
| // Handle navigation controls based on mode | ||
| if (mapType === MapToggleEnum.DrawingMode) { | ||
| if (!navigationControlRef.current) { | ||
| navigationControlRef.current = new mapboxgl.NavigationControl(); | ||
| map.current.addControl(navigationControlRef.current, 'top-left'); | ||
| } | ||
|
Comment on lines
+357
to
+361
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the intent is to show only zoom icons (as the PR title/description states), the default SuggestionReplace the constructor with options to hide the compass and show only zoom: navigationControlRef.current = new mapboxgl.NavigationControl({
showCompass: false,
showZoom: true,
});Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change. |
||
| } else { | ||
| if (navigationControlRef.current) { | ||
| map.current.removeControl(navigationControlRef.current); | ||
| navigationControlRef.current = null; | ||
| } | ||
| } | ||
|
Comment on lines
+356
to
+367
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The navigation control toggling is gated by Recommend handling the control setup regardless of whether the mode changed (idempotent due to the ref), or add an initial check after map initialization to reflect the current mode. SuggestionMove the navigation control toggling outside of the // After ensuring map.current and initializedRef.current
if (mapType === MapToggleEnum.DrawingMode) {
if (!navigationControlRef.current) {
navigationControlRef.current = new mapboxgl.NavigationControl();
map.current.addControl(navigationControlRef.current, 'top-left');
}
} else if (navigationControlRef.current) {
map.current.removeControl(navigationControlRef.current);
navigationControlRef.current = null;
}Alternatively, add a one-time check in the Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change. |
||
|
|
||
| // Handle draw controls based on mode | ||
| if (mapType === MapToggleEnum.DrawingMode) { | ||
|
|
@@ -409,8 +423,6 @@ export const Mapbox: React.FC<{ position?: { latitude: number; longitude: number | |
| preserveDrawingBuffer: true | ||
| }) | ||
|
|
||
| map.current.addControl(new mapboxgl.NavigationControl(), 'top-left') | ||
|
|
||
| // Register event listeners | ||
| map.current.on('moveend', captureMapCenter) | ||
| map.current.on('mousedown', handleUserInteraction) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added a persistent
navigationControlRef, but there is no corresponding unmount/cleanup path shown for removing the control if the map is destroyed. While Mapbox cleans up onmap.remove(), explicitly removing the control prevents potential dangling references and keeps the lifecycle clear.Suggestion
Add cleanup to remove the control during component unmount or before calling
map.remove():Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change.