Skip to content

Commit e3df0a1

Browse files
committed
docs: add Control content
1 parent 747ffbb commit e3df0a1

3 files changed

Lines changed: 91 additions & 2 deletions

File tree

docs/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default defineConfig({
5656
link: '/docs/api/marker-clusterer',
5757
},
5858
{
59-
label: 'Control 🛠',
59+
label: 'Control',
6060
link: '/docs/api/control',
6161
},
6262
{
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Control, CustomMarker, GoogleMap, useMapContext } from "react-google-map-wrapper";
2+
3+
import { Container } from "../../Container";
4+
5+
const center = { lat: 37.5111158, lng: 127.098167 };
6+
7+
function MapContent() {
8+
const map = useMapContext();
9+
10+
const handleButtonClick = () => {
11+
map.setCenter(center);
12+
}
13+
14+
return (
15+
<Control position={google.maps.ControlPosition.TOP_CENTER}>
16+
<button style={{
17+
backgroundColor: '#fff',
18+
border: '2px solid #fff',
19+
borderRadius: '3px',
20+
boxShadow: '0 2px 6px rgba(0,0,0,.3)',
21+
color: 'rgb(25,25,25)',
22+
cursor: 'pointer',
23+
fontFamily: 'Roboto,Arial,sans-serif',
24+
fontSize: '16px',
25+
lineHeight: '38px',
26+
margin: '8px 0 22px',
27+
padding: '0 5px',
28+
textAlign: 'center',
29+
}} onClick={handleButtonClick}>Center Map</button>
30+
</Control>
31+
);
32+
}
33+
34+
export function ControlEx() {
35+
return (
36+
<Container>
37+
<GoogleMap
38+
className='h-[400px]'
39+
zoom={12}
40+
center={center}
41+
>
42+
<MapContent />
43+
</GoogleMap>
44+
</Container>
45+
)
46+
}

docs/src/content/docs/docs/api/control.mdx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,47 @@ title: Control
33
description: description
44
---
55

6-
🛠🛠🛠 This documentation is currently in progress. 🛠🛠🛠
6+
import { ControlEx } from '../../../../components/api/Control';
7+
8+
`<Control />` component is used for display custom controls that can be interacting with the user. for more detail, see <a href='https://developers.google.com/maps/documentation/javascript/controls#CustomControls' target='_blank' rel='noreferrer'>official google map documentation</a>.
9+
10+
### Basic Example
11+
12+
```tsx
13+
const center = { lat: 37.5111158, lng: 127.098167 };
14+
15+
function MapContent() {
16+
const map = useMapContext();
17+
18+
const handleButtonClick = () => {
19+
map.setCenter(center);
20+
}
21+
22+
return (
23+
<Control position={google.maps.ControlPosition.TOP_CENTER}>
24+
<button onClick={handleButtonClick}>Center Map</button>
25+
</Control>
26+
);
27+
}
28+
29+
function MyMap() {
30+
return (
31+
<GoogleMap
32+
className='h-[400px]'
33+
center={center}
34+
...
35+
>
36+
<MapContent />
37+
</GoogleMap>
38+
)
39+
}
40+
```
41+
42+
<ControlEx client:only='react' />
43+
44+
### Props
45+
46+
| Props | Type | Description |
47+
| ----------- | ----------- | ----------- |
48+
| poistion | `google.maps.ControlPosition` | position of control element |
49+
| ... | `HTMLAttributes<HTMLDivElement>` | props except `position` are passed to the `<div>` container. |

0 commit comments

Comments
 (0)