File size: 1,039 Bytes
0e11366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { useEffect } from "react";
import { useMap } from "@vis.gl/react-google-maps";
import type { SelectMeta } from "../../../lib/types";

export default function SingleSelect({
  onPick,
}: {
  onPick: (ll: [number, number], meta: SelectMeta) => void;
}) {
  const map = useMap();
  useEffect(() => {
    if (!map) return;
    map.setOptions({ disableDoubleClickZoom: true });
    const onClick = map.addListener("click", (e: google.maps.MapMouseEvent) => {
      if (!e.latLng) return;
      onPick([e.latLng.lat(), e.latLng.lng()], {
        kind: "click",
        title: "Selected point",
      });
    });
    const onDbl = map.addListener(
      "dblclick",
      (e: google.maps.MapMouseEvent) => {
        if (!e.latLng) return;
        onPick([e.latLng.lat(), e.latLng.lng()], {
          kind: "click",
          title: "Selected point",
        });
      }
    );
    return () => {
      google.maps.event.removeListener(onClick);
      google.maps.event.removeListener(onDbl);
    };
  }, [map, onPick]);

  return null;
}