myMap.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from "react";
  2. import { compose, withProps } from "recompose";
  3. import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
  4. // import InfoBox from "react-google-maps/lib/components/addons/InfoBox";
  5. // const { InfoBox } = require("react-google-maps/lib/components/addons/InfoBox");
  6. const MyMapComponent = compose(
  7. withProps({
  8. googleMapURL: "https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places",
  9. loadingElement: <div style={{ height: `100%` }} />,
  10. containerElement: <div style={{ height: `500px` }} />,
  11. mapElement: <div style={{ height: `100%` }} />,
  12. mapTypeId: 'hybrid'
  13. }),
  14. withScriptjs,
  15. withGoogleMap
  16. )((props) =>
  17. <GoogleMap
  18. defaultZoom={15}
  19. defaultCenter={{ lat: 49.992438, lng: 36.232169 }}
  20. defaultType = {"hybrid"}
  21. >
  22. {props.isMarkerShown && <Marker position={{ lat: 49.992438, lng: 36.232169 }} onClick={props.onMarkerClick} />}
  23. </GoogleMap>
  24. )
  25. export default class MyFancyComponent extends React.PureComponent {
  26. state = {
  27. isMarkerShown: false,
  28. }
  29. componentDidMount() {
  30. this.delayedShowMarker()
  31. }
  32. delayedShowMarker = () => {
  33. setTimeout(() => {
  34. this.setState({ isMarkerShown: true })
  35. }, 3000)
  36. }
  37. handleMarkerClick = () => {
  38. this.setState({ isMarkerShown: false })
  39. this.delayedShowMarker()
  40. }
  41. render() {
  42. return (
  43. <MyMapComponent
  44. isMarkerShown={this.state.isMarkerShown}
  45. onMarkerClick={this.handleMarkerClick}
  46. />
  47. )
  48. }
  49. }