Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the position of controls makes them disappear #6

Closed
sseppola opened this issue Jun 15, 2015 · 10 comments
Closed

Changing the position of controls makes them disappear #6

sseppola opened this issue Jun 15, 2015 · 10 comments

Comments

@sseppola
Copy link

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>
  );
});
@istarkov
Copy link
Collaborator

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.

istarkov added a commit to google-map-react/old-examples that referenced this issue Jun 15, 2015
istarkov added a commit that referenced this issue Jun 15, 2015
@istarkov
Copy link
Collaborator

Done, example
example source

@istarkov istarkov reopened this Jun 15, 2015
@sseppola
Copy link
Author

Perfect! thank you for fixing that so fast :)

@vidyaramachandran56
Copy link

Hi,i am having same issue with Map component.Not able to change maptypecontrol options.

<Map

      google={this.props.google}
      zoom={8}
      mapTypeControl="true"
      mapTypeControlOptions={{
        style: this.props.google.maps.MapTypeControlStyle.DROPDOWN_MENU,
        position: this.props.google.maps.ControlPosition.TOP_RIGHT
      }
      }/>

@abidRahim
Copy link

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
          ]
        }

@vidyaramachandran56
Copy link

@abidRahim ,the issue is resolved.Since I was using google-maps library ,I couldn't change the type control style and position.
Try using google-map-react.

@abidRahim
Copy link

Thanks. It just worked for me.

I was working under Development Mode , with no key . As soon as i added the key it worked for me.

@MSonia0903
Copy link

I have a similar problem. Are you using a Development mode key or Production mode key?

@scottkz
Copy link

scottkz commented Feb 12, 2021

Is this working in the Curren release. I cannot get it working

function createMapOptions(maps) {
  return {
    styles: mapStyles,
    zoomControl: true,
    ZoomControlOptions: {
      position: maps.ControlPosition.TOP_LEFT,
      style: maps.ZoomControlStyle.SMALL,
    },
    mapTypeControl: false,
    streetViewControl: false,
    rotateControl: false,
    scaleControl: false,
    fullscreenControl: false,
  }
}

@mariraja-selvakumar
Copy link

How to enable TIlt & Rotate Control with React Google Map API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants