Advertisement
Guest User

Untitled

a guest
May 14th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  componentDidMount() {
  2.         this.setState({isLoading: true});
  3.  
  4.         fetch('/api/alert', {credentials: 'include'})
  5.             .then(response => response.json())
  6.             .then(data => this.setState({alerts: data, isLoading: false}))
  7.             .catch(() => this.props.history.push('/'));
  8.  
  9.         if (navigator.geolocation) {
  10.             navigator.geolocation.watchPosition((position) => {
  11.                 this.setState({currentPos: {lat: 53.10, lng: 18}})
  12.             },
  13.                 (error) => this.setState({ error: error.message }),
  14.                 { enableHighAccuracy: false, timeout: 100000, maximumAge: 1000 },)
  15.         }
  16.     }
  17.  
  18.     render() {
  19.         console.log(this.state)
  20.         const MapWithAMarker = withScriptjs(withGoogleMap(props =>
  21.             <GoogleMap
  22.                defaultZoom={8}
  23.                defaultCenter={this.state.currentPos}
  24.                options={{
  25.                    styles:mapStyles,
  26.                    disableDefaultUI: true,
  27.                }}
  28.  
  29.            >
  30.                 <Marker
  31.                     position={this.state.currentPos}
  32.                     icon={{
  33.                         url: '/position.svg',
  34.                         scaledSize: new google.maps.Size(35, 35)
  35.                     }
  36.                     }/>
  37.  
  38.                 {this.state.alerts.filter(alert => alert.current && alert.latitude && alert.longitude).map((alert) => (
  39.                     <Marker key={alert.id} position={{lat: alert.latitude, lng: alert.longitude}} icon={
  40.                         {
  41.                             url: '/alert.svg',
  42.                             scaledSize: new google.maps.Size(35, 35)
  43.                         }
  44.                     }/>
  45.                 ))}
  46.             </GoogleMap>
  47.         ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement