tomchentw / react-google-maps

React.js Google Maps integration component
https://tomchentw.github.io/react-google-maps/
MIT License
4.63k stars 936 forks source link

Feature Request: StreetView Options #984

Open madrussa opened 5 years ago

madrussa commented 5 years ago

It would be really useful to be able to pass street view options to a GoogleMap component. For example in my case I would like to disable the FullscreenControl. I first tried setting this on the Google Maps option itself but this resulted in "streetView is not a StreetViewPanorama" exception. I tried to setup the StreetViewPanorama as a child of the map but this didn't work either.

My current work around is to set the options on the map reference:

import React from 'react';
import { withGoogleMap, GoogleMap } from 'react-google-maps';

class Map extends React.Component {
  handleMapMounted = (map) => {
    this._map = map;
    if (this._map && this._map.getStreetView()) {
      this._map.getStreetView().setOptions({ fullscreenControl: false });
    }
  }

  render () {
    return (
      <GoogleMap
        ref={this.handleMapMounted}
        options={{
          tilt: 0,
          zoomControl: false,
          mapTypeControl: false,
          scaleControl: false,
          streetViewControl: true,
          rotateControl: false,
          fullscreenControl: false
        }}
      />
    );
  }
}

export default withGoogleMap(Map);

as a basic example.

It would be good to know if there is a better way or having the ability to pass in default street view options:

import React from 'react';
import { withGoogleMap, GoogleMap } from 'react-google-maps';

class Map extends React.Component {
  handleMapMounted = (map) => {
    this._map = map;
  }

  render () {
    return (
      <GoogleMap
        ref={this.handleMapMounted}
        defaultStreetViewOptions={{
          fullscreenControl: false
        }}
        options={{
          tilt: 0,
          zoomControl: false,
          mapTypeControl: false,
          scaleControl: false,
          streetViewControl: true,
          rotateControl: false,
          fullscreenControl: false
        }}
      />
    );
  }
}

export default withGoogleMap(Map);

Thanks!

JustFly1984 commented 5 years ago

Hello @madrussa, this library is unmaintained more than a year ago, and owner disappeared. We have made a successor of this lib @react-google-maps/api please consider to switch, we have active community on spectrum, working examples and docs