Skip to content

Rectangle

<Rectangle /> component is a simplified Polygon for rectangles. for more detail, see official documentation.

Basic Example

function MyMap() {
return (
<GoogleMap
className='h-[400px]'
initialZoom={11}
initialCenter={{ lat: 33.678, lng: -116.243 }}
mapOptions={{
mapTypeId: "terrain",
}}
>
<Rectangle
strokeColor="#FF0000"
strokeOpacity={0.8}
strokeWeight={2}
fillColor="#FF0000"
fillOpacity={0.35}
bounds={{
north: 33.685,
south: 33.671,
east: -116.234,
west: -116.251,
}}
/>
</GoogleMap>
);
}

Props

PropsTypeDescription
pathsgoogle.maps.MVCArray<google.maps.MVCArray<LatLng>> | google.maps.MVCArray<LatLng> | Array<Array<LatLng | LatLngLiteral>> | Array<LatLng | LatLngLiteral>The ordered sequence of coordinates for drawing Rectangle. Paths are closed automatically; do not repeat the first vertex of the path as the last vertex.
clickablebooleanIndicates whether this Rectangle handles mouse events.
draggablebooleanif flag is set to true, the user can drag Rectangle over the map.
editablebooleanif flag is set to true, the user can edit Rectangle by dragging the control points shown at the vertices and on each segment.
fillColorstringThe fill color. All CSS3 colors are supported except for extended named colors.
fillOpacitynumberThe fill opacity between 0.0 and 1.0
geodesicbooleanif flag is set to true, edges of the polygon are interpreted as geodesic and will follow the curvature of the Earth.
strokeColorstringThe stroke color. All CSS3 colors are supported except for extended named colors.
strokeOpacitynumberThe stroke opacity between 0.0 and 1.0.
strokePositiongoogle.maps.StrokePositionThe stroke position.
strokeWeightnumberThe stroke width in pixels.
visiblebooleanWhether this polygon is visible on the map.
zIndexnumberzIndex for Rectangle
onClick(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for click event. Please refer to the official documentation.
onContextmenu(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for contextmenu event. Please refer to the official documentation.
onDblClick(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for dblclick event. Please refer to the official documentation.
onDrag(polygon: google.maps.Rectangle, event: google.maps.MapMouseEvent) => void;callback for drag event. Please refer to the official documentation.
onDragEnd(polygon: google.maps.Rectangle, event: google.maps.MapMouseEvent) => void;callback for dragend event. Please refer to the official documentation.
onDragStart(polygon: google.maps.Rectangle, event: google.maps.MapMouseEvent) => void;callback for dragstart event. Please refer to the official documentation.
onMouseDown(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for mousedown event. Please refer to the official documentation.
onMouseMove(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for mousemove event. Please refer to the official documentation.
onMouseOut(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for mouseout event. Please refer to the official documentation.
onMouseOver(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for mouseover event. Please refer to the official documentation.
onMouseUp(polygon: google.maps.Rectangle, event: google.maps.PolyMouseEvent) => void;callback for mouseup event. Please refer to the official documentation.