1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import React from "react";
- import { compose, withProps } from "recompose";
- import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
- // import InfoBox from "react-google-maps/lib/components/addons/InfoBox";
- // const { InfoBox } = require("react-google-maps/lib/components/addons/InfoBox");
- const MyMapComponent = compose(
- withProps({
- googleMapURL: "https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places",
- loadingElement: <div style={{ height: `100%` }} />,
- containerElement: <div style={{ height: `500px` }} />,
- mapElement: <div style={{ height: `100%` }} />,
- mapTypeId: 'hybrid'
- }),
- withScriptjs,
- withGoogleMap
- )((props) =>
- <GoogleMap
- defaultZoom={15}
- defaultCenter={{ lat: 49.992438, lng: 36.232169 }}
- defaultType = {"hybrid"}
- >
- {props.isMarkerShown && <Marker position={{ lat: 49.992438, lng: 36.232169 }} onClick={props.onMarkerClick} />}
-
- </GoogleMap>
- )
- export default class MyFancyComponent extends React.PureComponent {
- state = {
- isMarkerShown: false,
- }
- componentDidMount() {
- this.delayedShowMarker()
- }
- delayedShowMarker = () => {
- setTimeout(() => {
- this.setState({ isMarkerShown: true })
- }, 3000)
- }
- handleMarkerClick = () => {
- this.setState({ isMarkerShown: false })
- this.delayedShowMarker()
- }
- render() {
- return (
- <MyMapComponent
- isMarkerShown={this.state.isMarkerShown}
- onMarkerClick={this.handleMarkerClick}
- />
- )
- }
- }
|