Guest User

Untitled

a guest
Nov 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import React from 'react';
  2. import { compose, withProps } from 'recompose';
  3.  
  4. import {
  5. withScriptjs,
  6. withGoogleMap,
  7. GoogleMap,
  8. Marker,
  9. InfoWindow
  10. } from 'react-google-maps';
  11.  
  12. import orangeMarker from '../../../assets/img/orange-marker.png';
  13. import './MapWithAMarker.css';
  14.  
  15. const googleMapURL = process.env.REACT_APP_GOOGLE_MAPS_API_URL;
  16. const loadingElement = <div style={{ height: `100%` }} />;
  17. const containerElement = <div style={{ height: `500px` }} />;
  18. const mapElement = <div style={{ height: `100%` }} />;
  19. const position = { lat: 37.999314, lng: 23.8193796 };
  20. const icon = { url: orangeMarker, scaledSize: { width: 31, height: 50 } };
  21.  
  22. const MapWithMarkers = compose(
  23. withProps({
  24. googleMapURL: googleMapURL,
  25. loadingElement: loadingElement,
  26. containerElement: containerElement,
  27. mapElement: mapElement,
  28. }),
  29. withScriptjs,
  30. withGoogleMap
  31. )(props =>
  32. <GoogleMap
  33. defaultZoom={14}
  34. defaultCenter={position}>
  35. <MarkerWithInfoWindow position={position} />
  36. </GoogleMap>
  37. );
  38.  
  39. class MarkerWithInfoWindow extends React.Component {
  40. state = {
  41. isWindowOpen: true
  42. }
  43.  
  44. onToggleOpen = () => {
  45. this.setState({
  46. isWindowOpen: !this.state.isWindowOpen
  47. });
  48. }
  49.  
  50. render() {
  51. return (<Marker
  52. position={this.props.position}
  53. icon={icon}
  54. onClick={this.onToggleOpen}>
  55. {this.state.isWindowOpen && <InfoWindow onCloseClick={this.onToggleOpen}>
  56. <div id="demokritos">
  57. National Centre of Scientific
  58. <br></br>Research DEMOKRITOS
  59. </div>
  60. </InfoWindow>}
  61. </Marker>)
  62. }
  63. }
  64.  
  65. export default MapWithMarkers;
Add Comment
Please, Sign In to add comment