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

Applying custom map styles? #53

Closed
zth opened this issue May 16, 2015 · 20 comments
Closed

Applying custom map styles? #53

zth opened this issue May 16, 2015 · 20 comments

Comments

@zth
Copy link

zth commented May 16, 2015

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
Copy link
Owner

@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
Copy link
Collaborator

wuct commented May 19, 2015

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

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

@jankanty
Copy link

Not mapStyles but styles.

@tomchentw
Copy link
Owner

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

@frankbo
Copy link

frankbo commented Jan 5, 2017

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
Copy link

mrjosshi commented Jul 6, 2017

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
Copy link

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

@tomchentw
Copy link
Owner

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

Please read the documentation site first!

@anusree-mmlab
Copy link

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
Copy link

@anusree-mmlab

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

Example here
Check fancy map styles here

@joshuawootonn
Copy link

joshuawootonn commented Nov 14, 2017 via email

@glmagicworks
Copy link

@winsandymyint you did it! love you ❤️

@asmmahmud
Copy link

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
Copy link

baughmann commented Nov 24, 2018

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
Copy link

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!

@coderdix
Copy link

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

@yhoungdev
Copy link

my map keeps overflowing

@glmagicworks
Copy link

glmagicworks commented Nov 25, 2022

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
Copy link

my map keeps overflowing

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

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