-
Notifications
You must be signed in to change notification settings - Fork 11
Migrate Google Maps integration to @vis.gl/react-google-maps #1619
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
347 changes: 132 additions & 215 deletions
347
packages/evolution-frontend/src/components/inputs/__tests__/InputMapFindPlace.test.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
packages/evolution-frontend/src/components/inputs/maps/google/GoogleMapOverlays.tsx
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * Copyright Polytechnique Montreal and contributors | ||
| * | ||
| * This file is licensed under the MIT License. | ||
| * License text available at https://opensource.org/licenses/MIT | ||
| */ | ||
|
|
||
| /** | ||
| * Lightweight React wrappers around `google.maps.Polyline` and | ||
| * `google.maps.Polygon`, mounted onto the current `<Map>` via `useMap()`. | ||
| * | ||
| * `@vis.gl/react-google-maps` does not ship Polyline/Polygon components, so we | ||
| * recreate the small subset used by the survey widgets imperatively. The | ||
| * underlying overlay is created once per map instance and disposed on unmount; | ||
| * options are pushed via `setOptions` whenever the prop changes. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { useMap } from '@vis.gl/react-google-maps'; | ||
|
|
||
| /** | ||
| * Renders a `google.maps.Polyline` on the enclosing `<Map>`. | ||
| * | ||
| * @param props.options Polyline options forwarded to `setOptions`. | ||
| */ | ||
| export const MapPolyline: React.FC<{ options: google.maps.PolylineOptions }> = ({ options }) => { | ||
| const map = useMap(); | ||
| const polylineRef = React.useRef<google.maps.Polyline | null>(null); | ||
|
|
||
| // Use a ref so the create-effect can read the latest options on mount | ||
| // without depending on `options` (which would re-create the overlay on | ||
| // every option change instead of just calling setOptions). | ||
| const optionsRef = React.useRef(options); | ||
| optionsRef.current = options; | ||
|
|
||
| React.useEffect(() => { | ||
| if (!map) return; | ||
| const polyline = new google.maps.Polyline({ ...optionsRef.current, map }); | ||
| polylineRef.current = polyline; | ||
| return () => { | ||
| polyline.setMap(null); | ||
| polylineRef.current = null; | ||
| }; | ||
| }, [map]); | ||
|
|
||
| React.useEffect(() => { | ||
| polylineRef.current?.setOptions(options); | ||
| }, [options]); | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| /** | ||
| * Renders a `google.maps.Polygon` on the enclosing `<Map>`. | ||
| * | ||
| * @param props.options Polygon options forwarded to `setOptions` (including | ||
| * `paths`). | ||
| */ | ||
| export const MapPolygon: React.FC<{ options: google.maps.PolygonOptions }> = ({ options }) => { | ||
| const map = useMap(); | ||
| const polygonRef = React.useRef<google.maps.Polygon | null>(null); | ||
|
|
||
| const optionsRef = React.useRef(options); | ||
| optionsRef.current = options; | ||
|
|
||
| React.useEffect(() => { | ||
| if (!map) return; | ||
| const polygon = new google.maps.Polygon({ ...optionsRef.current, map }); | ||
| polygonRef.current = polygon; | ||
| return () => { | ||
| polygon.setMap(null); | ||
| polygonRef.current = null; | ||
| }; | ||
| }, [map]); | ||
|
|
||
| React.useEffect(() => { | ||
| polygonRef.current?.setOptions(options); | ||
| }, [options]); | ||
|
|
||
| return null; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.