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.

Changing the position of controls makes them disappear

See original GitHub issue

If I set the position in either zoomControlOptions or mapTypeControlOptions, which is passed to the GoogleMap component in through the options prop, they disappear. When the attribute is not set they render fine to their default positions.

I’ve followed followed the control position class documentation, using values like: ‘BOTTOM_RIGHT’, ‘TOP_RIGHT’, and ‘LEFT_CENTER’, none of which work. https://developers.google.com/maps/documentation/javascript/reference#ControlPosition

This is how I’m using it:

import GoogleMap from 'google-map-react';
import OfficeMarker from './markers/OfficeMarker';

let mapOptions = {
  scrollwheel: false,
  zoomControlOptions: {
      //   position: 'RIGHT_CENTER',    // as long as this is not set it works
      style: 'SMALL'
  },
  mapTypeControlOptions: {
      position: 'BOTTOM_RIGHT'     // this makes the map type control disappear
  },
  draggable: false,
  rotateControl: false,
  scaleControl: false,
  streetViewControl: false,
  panControl: false,
};

const Map = React.createClass({
  render() {
    return (
      <div className="map-container" style={{height: '400px'}}>
        <GoogleMap
          options={mapOptions}
          center={this.props.center}
          zoom={this.props.zoom}>
          <OfficeMarker lat={this.props.officeCoords.lat} lng={this.props.officeCoords.lng} />
        </GoogleMap>
      </div>
  );
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
abidRahimcommented, May 19, 2020

Hi @vidyaramachandran56, did you figure it out ?

I am not able to use mapTypeControl either. They render for a micro second and it disappears quickly after. Even though i am adding this to the options

        mapTypeControl: true,
        mapTypeControlOptions: {
          style: maps.MapTypeControlStyle.HORIZONTAL_BAR,
          position: maps.ControlPosition.BOTTOM_LEFT,
          mapTypeIds: [
            maps.MapTypeId.ROADMAP,
            maps.MapTypeId.SATELLITE,
            maps.MapTypeId.HYBRID
          ]
        }
1reaction
istarkovcommented, Jun 15, 2015

Thank you. GMAP API uses it’s internal constants to set view options, like google.maps.ZoomControlStyle.SMALL. And it’s my big fault that i don’t expose this constants to user.

As there are a lot of google constants can be used in options i know this constants (but i don’t know all)

google.maps.ControlPosition
google.maps.MapTypeControlStyle
google.maps.ZoomControlStyle
google.maps.MapTypeId

It’s better to add something like optionsCreator initialization.

import GoogleMap from 'google-map-react';
import OfficeMarker from './markers/OfficeMarker';

function mapOptionsCreator(map) {
  return  {
    scrollwheel: false,
    zoomControlOptions: {
        position: map.ControlPosition.RIGHT_CENTER,    // as long as this is not set it works
        style: map.ZoomControlStyle.SMALL
    },
    mapTypeControlOptions: {
        position: map.ControlPosition.BOTTOM_RIGHT     // this makes the map type control disappear
    },
    draggable: false,
    rotateControl: false,
    scaleControl: false,
    streetViewControl: false,
    panControl: false,
  };
}

const Map = React.createClass({
  render() {
    return (
      <div className="map-container" style={{height: '400px'}}>
        <GoogleMap
          options={mapOptionsCreator}
          center={this.props.center}
          zoom={this.props.zoom}>
          <OfficeMarker lat={this.props.officeCoords.lat} lng={this.props.officeCoords.lng} />
        </GoogleMap>
      </div>
  );
});

And if options prop is function, i call it with google.map variable.

This is the first exception to my rule - Don’t expose google api

I start to add this right now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing Effect Controls Panel and No Toolbar Fix - YouTube
A tutorial on how to to fix no effect controls and a missing toolbar in Premiere Pro CC. I also demonstrate how to...
Read more >
About content controls - Microsoft Support
Content controls can provide instructional text for users, and you can set controls to disappear when users type in their own text.
Read more >
Edit Control Center on your iPhone, iPad, and iPod touch
How to rearrange a control. Go to Settings > Control Center. Touch and hold the Reorder button and move the controls in the...
Read more >
Positioning - Learn web development | MDN
To make a specific type of positioning active on an element, ... its final position, including making it overlap other elements on the...
Read more >
Controls | Maps JavaScript API - Google Developers
By default, all the controls disappear if the map is too small (200x200px). ... You can set control options to change the default...
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