question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Zoom Control UI

See original GitHub issue

Hello, this is the first time I am opening issue in this project. I have a question regarding adding custom control. Here is my environment:

  • “react-google-maps”: “^9.4.5”
  • “react”: “^16.3.2”
  • “react-dom”: “^16.3.2”

Upon some googling and stackoverflow searching. I have found some good references: For example:

However, I don’t think the .controls are in the google.maps object.

Following is my code:

class MapComponent extends Component {
constructor(props){
    super(props);
    this.mapComponentRef = React.createRef();
  }

  render(){
      return (
      <GoogleMap
        ref={this.mapComponentRef}
      />);
  }
}

I can confirm that I can access the ref of the map. For example, I use

this.mapComponentRef.current.fitBounds(this.bounds);

to update the bounds of the map and it works.

However, when I try to do this.mapComponentRef.current.controls[google.maps.ControlPosition.TOP_CENTER].push(centerControlDiv), it gives me errors that the controls is undefined.

Does anyone has pointer on how to get access the controls so I can push my custom component to control the zoom level of the map?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
rockiacommented, Aug 13, 2018

For anyone who is looking into this issue. I have posted my solution in https://github.com/tomchentw/react-google-maps/issues/82#issuecomment-412579391 .

I will close this PR now. Thanks so much for the help.

0reactions
veysiyildizcommented, Jul 10, 2018

you just need to add current to ref <CustomControl mapHolderRef={this.mapComponentRef.current} controlPosition={window.google.maps.ControlPosition.TOP_LEFT} > <div onClick={() => this.mapComponentRef.current.map.setZoom(8)}>testing component</div> </CustomControl>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Zoom Controls - Dribbble
Discover 1 Zoom Controls design on Dribbble. ... animation app behance case study controls customization dashboard interaction interface mobile motion ui.
Read more >
Custom UI Feature - Zoom App Marketplace
Custom UI Feature · Contents · Initialize the SDK · Create Customized UI Service and SetEvent · Create Video Container, Video Element(s) and...
Read more >
Zoom Controls | UI Controls | Common Settings
Zoom Control Panel is an HTML object with three buttons: Zoom All (100%, or 1x Zoom), Zoom In and Zoom Out. To create...
Read more >
Class of the UI Control ZOOM in HERE MAPS - Stack Overflow
The Maps API supports changing the position of the UI controls. In the following example, all map controls are moved to the top-left...
Read more >
Controls | Maps JavaScript API - Google Developers
The following example sets the map to hide the Zoom control and display the Scale control. Note that we do not explicitly disable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found