Polygons #636
Replies: 4 comments 5 replies
-
We don't provide exports for those geometries from the library at the moment. However, we do have an example which does implement components like Polygon, Polyline and Circle using this library. Take a look here:
You can copy & paste the Polygon component to your own code and work with it that way. Hope that helps :) |
Beta Was this translation helpful? Give feedback.
-
How do I get the coordinates of a drawn polygon and update them when the polygon is edited? |
Beta Was this translation helpful? Give feedback.
-
import { forwardRef, useEffect, useState } from "react"; export type DrawingManagerProps = { export const CustomDrawingManager = forwardRef<
const [drawingManager, setDrawingManager] = // Expose the drawingManager to the parent through the ref useEffect(() => {
}, [drawingLibrary, map, createdPolygons]); useEffect(() => {
}, [drawableMode, drawingManager, createdPolygons]); return null; export default CustomDrawingManager; This code provides the coordinates of a polygon whenever the polygonComplete function is triggered, typically after a user completes drawing a polygon on a map interface. Would you like me to refine or expand on this? |
Beta Was this translation helpful? Give feedback.
-
/* eslint-disable complexity */ import {GoogleMapsContext, useMapsLibrary} from '@vis.gl/react-google-maps'; import type {Ref} from 'react'; type PolygonEventProps = { type PolygonCustomProps = {
export type PolygonProps = google.maps.PolygonOptions & export type PolygonRef = Ref<google.maps.Polygon | null>; function usePolygon(props: PolygonProps) { const geometryLibrary = useMapsLibrary('geometry'); const polygon = useRef(new google.maps.Polygon()).current; const map = useContext(GoogleMapsContext)?.map; // update the path with the encodedPath // create polygon instance and add to the map once the map is available
}, [map]); // attach and re-attach event-handlers when any of the properties change
}, [polygon]); return polygon; /**
useImperativeHandle(ref, () => polygon, []); return null; |
Beta Was this translation helpful? Give feedback.
-
There is an AdvancedMarker component, <AdvancedMarker position={{lat: 29.5, lng: -81.2}}> <Pin background={'#0f9d58'} borderColor={'#006425'} glyphColor={'#60d98f'} /> . Similar to this, does a Polygon component exist in @vis.gl/react-google-maps to display and edit polygons on the map, like in the previous Google Maps API?"
Beta Was this translation helpful? Give feedback.
All reactions