tomchentw / react-google-maps

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

Can I set "satellite" view as default? #835

Open kstulgys opened 6 years ago

kstulgys commented 6 years ago

I get that 'map' view but can I change it to be 'satellite' as default? I see I can change it manually in the UI but couldn't find that prop so it's always default

AonanLi commented 6 years ago

you can set "mapTypeId" in GoogleMap

AdrianTudC commented 6 years ago

Namely this way: `<GoogleMapReact bootstrapURLKeys={{ key: =<>}} defaultCenter={this.props.center} defaultZoom={this.props.zoom} options={function (maps) { return { mapTypeId: "satellite" } }}

`

rockia commented 6 years ago

Both @AonanLi and @Edeph are correct. I would want to add a comment on top of Edeph's solution. It's better to use google.maps.MapTypeId.SATELLITE instead of the string "satellite" just to avoid typo.

enterthevoid commented 5 years ago

Hey guys and how to know which map type is on? I need something like this google.maps.MapType === google.maps.MapTypeId.SATELLITE ? do something : do something

AonanLi commented 5 years ago

@enterthevoid

You can call getMapTypeId() from ref

<GoogleMap
            {...mapProps}
            ref={ref => {
                if (ref) {
                    console.log(ref.getMapTypeId());
                }
            }}
        >
            {children}
        </GoogleMap>

However, the default mapType Id is roadmap. Since you want to know which map type is on, you must have changed the map type by yourself, therefore you should already know what map type you are using.