UNPKG

@syncromatics/react-google-maps

Version:
66 lines (62 loc) 1.9 kB
### Styled Map with an InfoBox ```jsx const { compose, withProps, withStateHandlers } = require("recompose"); const { withScriptjs, withGoogleMap, GoogleMap, } = require("@syncromatics/react-google-maps"); const { InfoBox } = require("@syncromatics/react-google-maps/lib/components/addons/InfoBox"); const demoFancyMapStyles = require("./demoFancyMapStyles.json"); const StyledMapWithAnInfoBox = compose( withProps({ googleMapURL: GOOGLE_MAP_URL, loadingElement: <div style={{ height: `100%` }} />, containerElement: <div style={{ height: `400px` }} />, mapElement: <div style={{ height: `100%` }} />, center: { lat: 25.03, lng: 121.6 }, }), withStateHandlers(() => ({ isOpen: false, }), { onToggleOpen: ({ isOpen }) => () => ({ isOpen: !isOpen, }) }), withScriptjs, withGoogleMap )(props => <GoogleMap defaultZoom={5} defaultCenter={props.center} defaultOptions={{ styles: demoFancyMapStyles }} > <InfoBox defaultPosition={new google.maps.LatLng(props.center.lat, props.center.lng)} options={{ closeBoxURL: ``, enableEventPropagation: true }} > <div style={{ backgroundColor: `yellow`, opacity: 0.75, padding: `12px` }}> <div style={{ fontSize: `16px`, fontColor: `#08233B` }}> Hello, Taipei! </div> </div> </InfoBox> <Marker position={{ lat: 22.6273, lng: 120.3014 }} onClick={props.onToggleOpen} > {props.isOpen && <InfoBox onCloseClick={props.onToggleOpen} options={{ closeBoxURL: ``, enableEventPropagation: true }} > <div style={{ backgroundColor: `yellow`, opacity: 0.75, padding: `12px` }}> <div style={{ fontSize: `16px`, fontColor: `#08233B` }}> Hello, Kaohsiung! </div> </div> </InfoBox>} </Marker> </GoogleMap> ); <StyledMapWithAnInfoBox /> ```