Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { Map, GoogleApiWrapper } from 'google-maps-react';
  3. import { Polygon } from 'google-maps-react/dist/components/Polygon';
  4. import Axios from 'axios';
  5.  
  6. const mapStyles = {
  7.   width: '80%',
  8.   height: '80%'
  9. };
  10.  
  11. export class MapContainer extends Component {
  12.  
  13.   constructor(props) {
  14.     super(props);
  15.     this.state = {
  16.       polygons: [],
  17.       // selected: false
  18.     };
  19.   }
  20.  
  21.   polyClick(e, data) {
  22.     e.setState({"fillColor" : "#00FFFF"})
  23.   }
  24.  
  25.   getPoly() {
  26.     Axios.get("/load").then(res => {
  27.       return res.data.features
  28.     }).then(data => {
  29.       let polys = data.map((coordinates, index) => {
  30.         return(
  31.           <Polygon
  32.             paths={coordinates}
  33.             onClick={((e) => this.polyClick(e, data))}
  34.             strokeColor="#0000FF"
  35.             strokeOpacity={0.8}
  36.             strokeWeight={2}
  37.             fillColor="#0000FF"
  38.             fillOpacity={0.35} />
  39.         )
  40.       })
  41.       this.setState({polygons: polys});
  42.       console.log(this.state.polygons)
  43.     })
  44.   }
  45.  
  46.   componentDidMount() {
  47.     this.getPoly();
  48.   }
  49.  
  50.   render() {
  51.     return(
  52.       <Map google={this.props.google}
  53.           style={{width: '100%', height: '100%', position: 'relative'}}
  54.           className={'map'}
  55.           zoom={14}
  56.           initialCenter={{
  57.             lat: 51.5,
  58.             lng: -0.14
  59.            }}
  60.           >
  61.           {this.state.polygons}
  62.  
  63.       </Map>
  64.     )
  65.   }
  66. }
  67.  
  68. export default GoogleApiWrapper({
  69.   apiKey: 'AIzaSyD3DstthrfYiEovv9cql8q8P3UrmgMDCe8'
  70. })(MapContainer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement