React-google-maps: Applying custom map styles?

Created on 16 May 2015  ·  17Comments  ·  Source: tomchentw/react-google-maps

Hi! I just found this repo and am implementing it in a project I'm working on. Runs very smooth, thanks for this!

However, I want to apply my own map style to the map, and I fail to see how/where I can do that. Any ideas on how/if that can be done?

Also, where do I put other props for the map/markers, like icon for marker, assigning an info window to it and opening it on click etc? I noticed there seems to be a component called InfoWindow, but I couldn't find any documentation about it.

Thanks in advance, and thanks for the great repo!

Most helpful comment

@anusree-mmlab

const exampleMapStyles = [] //Add some style  
<GoogleMap
    defaultOptions={{ styles: exampleMapStyles }}
    >

Example here
Check fancy map styles here

All 17 comments

@zth do you refer to stuff like this?

Custom map style:

http://git.io/vTkmW

Marker and InfoWindow

https://tomchentw.github.io/react-google-maps/#events/event-closure

@zth You can apply all google.map options as props to a <GoogleMap />. For example:

<GoogleMap mapStyles={/* YOUR MAP STYLES*/} />

Not mapStyles but styles.

Close this due to inactivity. Thanks @JanKantyPawelski to point that out.

For me adding styles as a prop didn't work. I had to add the styles to the defaultOptions prop as one can see in this example.
https://github.com/tomchentw/react-google-maps/blob/master/src/app/pages/basics/StyledMapExample.js
It is also possible to add the custom styles to the options prop as options.styles.

If one of you can update your links that would make my night :D

New example:
https://tomchentw.github.io/react-google-maps/#!/InfoBox

Please read the documentation site first!

How can i add custom style on the GoogleMap

import {withGoogleMap, GoogleMap, Marker, Polyline} from "react-google-maps";

mapStyles=[style object]

is not working

@anusree-mmlab

const exampleMapStyles = [] //Add some style  
<GoogleMap
    defaultOptions={{ styles: exampleMapStyles }}
    >

Example here
Check fancy map styles here

Hey I am not sure if I actually ever got this working, because I know right
now I just have a greyscale filter. But Here is what my component
looks like[image:
Inline image 1]
where styles is [image: Inline image 2]
You can find/ create different mapstyle.json on Google map developer site.

Good luck!

On Tue, Nov 14, 2017 at 1:54 AM, Win Sandy Myint notifications@github.com
wrote:

@anusree-mmlab https://github.com/anusree-mmlab

const exampleMapStyles = [] //Add some style
defaultOptions={{ styles: exampleMapStyles }}
>

Example here https://tomchentw.github.io/react-google-maps/#!/InfoBox
Check fancy map styles here https://snazzymaps.com/


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/tomchentw/react-google-maps/issues/53#issuecomment-344174297,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AT-vXIBmM0k1Hc5tzZ9H0jiQw6noiOwNks5s2UdQgaJpZM4EclFw
.

@winsandymyint you did it! love you ❤️

It is possible using the following way:

const exampleMapStyles = [{
        featureType: "water",
        elementType: "labels.text.fill",
        stylers: [
            {
                color: "#9e9e9e",
            },
        ],
    }] //Add some style  
<GoogleMap
    options={{ styles: exampleMapStyles }}
    >

I can confirm @anusree-mmlab method worked for me.

Just put your JSON style into a JS file as so:
export const MyStyle = [ YOUR STYLES HERE]

Then, in your map component:

import { MyStyle } from './MyStyle';

// other stuff

<GoogleMap defaultOptions={{ styles: MyStyle }}
        defaultZoom={8}
        defaultCenter={{ lat: -34.397, lng: 150.644 }} />

Little late to the party but nothing I do seems to quite work. I gave up on having ...

Style data as JSON (from snazzy maps) and placed within a exported variable named "greyMap" and saved the file as mapStyles.js

I then imported it into a component the GoogleMaps component is in import { greyMap } from "./mapStyles"

With my GoogleMaps component looking like
` id="map"
zoom={9}
center={hasLocation ? currentLocation : center}
onLoad={(map) => setMapRef(map)}
styles={greyMap}

`

I tried defaultOptions={{ style: greyMap }} and got the same results. Not sure what I'm doing wrong!

I'm using that one I keep searching when I have an issue and posting on the wrong forum lol

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PaulieScanlon picture PaulieScanlon  ·  3Comments

ShintaroNippon picture ShintaroNippon  ·  3Comments

tahir-masood1 picture tahir-masood1  ·  4Comments

madbean picture madbean  ·  3Comments

shrimpy picture shrimpy  ·  3Comments