positioned-street-view.component.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { useRef, useEffect } from "react";
  2. /* global google */
  3. export default React.memo(({ position }) => {
  4. const panoDivRef = useRef(null);
  5. const buttonRef = useRef(null);
  6. useEffect(() => {
  7. const pano = new google.maps.StreetViewPanorama(panoDivRef.current, {
  8. position,
  9. addressControl: false,
  10. showRoadLabels: false,
  11. clickToGo: true,
  12. visible: true,
  13. });
  14. console.log("Created Street View Pano");
  15. console.log("Setting up reset button");
  16. buttonRef.current.onclick = () => pano.setPosition(position);
  17. });
  18. return (
  19. <div style={{ height: "100%", position: "relative" }}>
  20. <div
  21. style={{ height: "100%" }}
  22. ref={panoDivRef}
  23. />
  24. <div
  25. // TODO this styling is very brittle
  26. style={{
  27. display: "block",
  28. position: "absolute",
  29. zIndex: 1,
  30. bottom: "200px",
  31. right: "9px",
  32. background: "#2a2a2a",
  33. color: "#9a9a9a",
  34. padding: "5px",
  35. borderRadius: "2px",
  36. fontWeight: "bold",
  37. cursor: "pointer",
  38. }}
  39. ref={buttonRef}
  40. >
  41. Reset
  42. </div>
  43. </div>
  44. );
  45. });