I would like to have a satellite
, a roadmap
and a custom-map
map styles button menu available.
I tried to follow those google api guide lines: https://developers.google.com/maps/documentation/javascript/styling#creating_a_styledmaptype
And apply them to the react-google-maps
package that I use in my react application, but I can't make it work.
It is possible to do so? If yes, how?
Here is my code:
import React from 'react';
import { GoogleMap, withGoogleMap, withScriptjs } from 'react-google-maps';
import { compose, withProps } from 'recompose';
const MyMap = () => {
const styledMapType = new google.maps.StyledMapType(
[
{
elementType: 'geometry',
stylers: [{ color: '#ebe3cd' }],
},
{
elementType: 'labels.text.fill',
stylers: [{ color: '#523735' }],
},
// other properties
],
{ name: 'custom-map' }
);
const defaultOptions = {
mapTypeControlOptions: {
position: google.maps.ControlPosition.RIGHT_TOP,
mapTypeIds: ['roadmap', 'satellite', 'custom-map'],
},
fullscreenControl: false,
streetViewControl: false,
};
const mapRef = useRef(null);
return <GoogleMap
key="custom-map"
defaultOptions={defaultOptions}
ref={mapRef}
/>
}
export default compose(
React.memo,
withProps({
containerElement: <div style={{ height: '100%' }} />,
googleMapURL: 'https://maps.googleapis.com/maps/api/js?v=3.exp&key=my-key&libraries=geometry',
loadingElement: <div style={{ height: '100%' }} />,
mapElement: <div style={{ height: '100%' }} />,
}),
withScriptjs,
withGoogleMap,
)(MyMap);