Skip to content
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

Implement pingers page #2

Merged
merged 14 commits into from
Jul 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix fast region selector, to update map
  • Loading branch information
dmitrijs-balcers committed Jul 4, 2024
commit 3ca234c1f1ddf37a3f0ca754e5f3a2175491e327
16 changes: 14 additions & 2 deletions src/components/RegionSelector/RegionSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="googlemaps" />
import { GoogleMap, Polygon, useLoadScript } from "@react-google-maps/api";
import React, { useCallback, useMemo, useState } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { Message, Segment } from "semantic-ui-react";
import convert from "./conversion";
import styles from "./RegionSelector.module.css";
Expand All @@ -25,6 +25,7 @@ export default function RegionSelector(props: RegionSelectorProps) {
() => convert.polygonStringToCoords(props.value),
[props.value],
);
const mapRef = React.useRef<google.maps.Map | null>(null);

const { isLoaded, loadError } = useLoadScript({
googleMapsApiKey: process.env.REACT_APP_GOOGLE_MAPS_KEY!,
Expand All @@ -35,10 +36,21 @@ export default function RegionSelector(props: RegionSelectorProps) {
}, [polygonRef, props]);

const onLoad = useCallback(
(map) => polygonPath && map.fitBounds(toLatLngBounds(polygonPath)),
(map) => {
polygonPath && map.fitBounds(toLatLngBounds(polygonPath));
mapRef.current = map;
},
[polygonPath],
);

useEffect(() => {
if (!polygonPath || !mapRef.current) {
return;
}

mapRef.current.fitBounds(toLatLngBounds(polygonPath));
}, [polygonPath]);

const onPolygonRemove = useCallback(
(event: google.maps.PolyMouseEvent) => {
if (event.vertex === undefined) {
Expand Down