tylerzika
3/19/2017 - 6:12 PM

React map componente

React map componente

import React, { Component } from 'react';
import key from '../key';

class Map extends Component {

  componentDidMount() {
    let script = document.createElement('script')

    script.setAttribute('type', 'text/javascript');
    script.setAttribute('src', `https://maps.googleapis.com/maps/api/js?key=${key.API_KEY}&callback=initMap`);
    document.getElementsByTagName('head')[0].appendChild(script);

    window.initMap = () => {
      console.log('initMap');
      console.log(google);
      this.map = new google.maps.Map(this.refs.map, {
        center: this.props.defaultCenter,
        zoom: this.props.defaultZoom
      });
    }
  }

  render() {
    const mapStyle = {
      height: "400px",
      width: "100%"
    };

    return <div ref="map" style={mapStyle} />;
  }

}

export default Map;