UNPKG

@syncromatics/react-google-maps

Version:
80 lines (75 loc) 2.42 kB
### Click the Marker to show OverlayView ```jsx const { compose, withProps, withStateHandlers } = require("recompose"); const FaAnchor = require("react-icons/lib/fa/anchor"); const { withScriptjs, withGoogleMap, GoogleMap, OverlayView, } = require("@syncromatics/react-google-maps"); const getPixelPositionOffset = (width, height) => ({ x: -(width / 2), y: -(height / 2), }) const MapWithAnOverlayView = compose( withStateHandlers(() => ({ count: 0, }), { onClick: ({ count }) => () => ({ count: count + 1, }) }), withScriptjs, withGoogleMap )(props => <GoogleMap defaultZoom={8} defaultCenter={{ lat: -34.397, lng: 150.644 }} > <OverlayView position={{ lat: -34.397, lng: 150.644 }} /* * An alternative to specifying position is specifying bounds. * bounds can either be an instance of google.maps.LatLngBounds * or an object in the following format: * bounds={{ * ne: { lat: 62.400471, lng: -150.005608 }, * sw: { lat: 62.281819, lng: -150.287132 } * }} */ /* * 1. Specify the pane the OverlayView will be rendered to. For * mouse interactivity, use `OverlayView.OVERLAY_MOUSE_TARGET`. * Defaults to `OverlayView.OVERLAY_LAYER`. */ mapPaneName={OverlayView.OVERLAY_MOUSE_TARGET} /* * 2. Tweak the OverlayView's pixel position. In this case, we're * centering the content. Warning, this ultimately causes the browser * to render/reflow. If you can use a fixed pixel position offset, use * the pixelPositionOffset prop instead: * * pixelPositionOffset={{ x: 10, y: 20 }} */ getPixelPositionOffset={getPixelPositionOffset} /* * 3. Create OverlayView content using standard React components. */ > <div style={{ background: `white`, border: `1px solid #ccc`, padding: 15 }}> <h1>OverlayView</h1> <button onClick={props.onClick} style={{ height: 60 }}> I have been clicked {props.count} time{props.count > 1 ? `s` : ``} </button> </div> </OverlayView> </GoogleMap> ); <MapWithAnOverlayView googleMapURL={GOOGLE_MAP_URL} loadingElement={<div style={{ height: `100%` }} />} containerElement={<div style={{ height: `400px` }} />} mapElement={<div style={{ height: `100%` }} />} /> ```