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

Applying custom map styles? #53

Closed zth closed 9 years ago

zth commented 9 years ago

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!

tomchentw commented 9 years ago

@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

wuct commented 9 years ago

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

<GoogleMap mapStyles={/* YOUR MAP STYLES*/} />
jankanty commented 9 years ago

Not mapStyles but styles.

tomchentw commented 9 years ago

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

frankbo commented 7 years ago

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.

mrjosshi commented 7 years ago

you can find this on here its really useful and easy to use https://github.com/tomchentw/react-google-maps/blob/master/src/app/constants/fancyMapStyles.json

joshuawootonn commented 7 years ago

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

tomchentw commented 7 years ago

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

Please read the documentation site first!

anusree-mmlab commented 7 years ago

How can i add custom style on the GoogleMap

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

<GoogleMap mapStyles=[style object]

is not working

winsandymyint commented 7 years ago

@anusree-mmlab

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

Example here Check fancy map styles here

joshuawootonn commented 7 years ago

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 <GoogleMap 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 .

glmagicworks commented 6 years ago

@winsandymyint you did it! love you ❤️

asmmahmud commented 6 years ago

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 }}
    >
baughmann commented 5 years ago

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 }} />
coderdix commented 4 years ago

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 `<GoogleMap 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!

JustFly1984 commented 4 years ago

@coderdix The repo of this project is unmaintained more than a year, and we had build new version https://www.npmjs.com/package/@react-google-maps/api

We had rewrite it to TypeScript, and updating it frequently: https://github.com/JustFly1984/react-google-maps-api/tree/master/packages/react-google-maps-api You can enjoy autocomplete.

You can see our docs: https://react-google-maps-api-docs.netlify.app

Also a lot of examples: https://react-google-maps-api-gatsby-demo.netlify.app/ https://github.com/JustFly1984/react-google-maps-api/tree/master/packages/react-google-maps-api-gatsby-example/src/examples

The bundle size is much smaller: https://bundlephobia.com/result?p=@react-google-maps/api

Our Spectrum community: https://spectrum.chat/react-google-maps
Our Slack channel: https://join.slack.com/t/react-google-maps-api/shared_invite/enQtODc5ODU1NTY5MzQ4LTBiNTYzZmY1YmVjYzJhZThkMGU0YzUwZjJkNGJmYjk4YjQyYjZhMDk2YThlZGEzNDc0M2RhNjBmMWE4ZTJiMjQ

Enjoy!

coderdix commented 4 years ago

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

yhoungdev commented 1 year ago

my map keeps overflowing

glmagicworks commented 1 year ago

my map keeps overflowing

Can you please provide a screenshoot? And also the code you used in the example for us to be able to reproduce it...

jesusbubai25 commented 8 months ago

my map keeps overflowing

Add position property as relative in mapContainerStyle props it will not overflow