2

When I added react-google-maps to project, render worked twice. So I have 2 circles one under another. Also, I display the center coordinates by onDragEnd() method. This event works for only one of this circles.

Any others google maps dosen`t exist on project.

Here is some ways I was trying to fix it: 1) Use only withGoogleMap, 2) Use GoogleMapsWrapper component inside render() method of parent component, 3) Use componentDidMount(); trying everything from satckoverflow :) and nothing helps.

import React, { Component } from 'react';
import MapForm from './mapForm';
import { GoogleMap, withGoogleMap, withScriptjs, Circle } from 'react-google-maps';

const GoogleMapsWrapper = withScriptjs(withGoogleMap(props => {
    const {onMapMounted, ...otherProps} = props;
    return <GoogleMap {...otherProps} ref={c => {
       onMapMounted && onMapMounted(c)
    }}>{props.children}</GoogleMap>
}));

class GoogleMapsContainer extends Component {
    state = {
        coords: {lat:0, lng: 0}
    };


dragCircle = () => {
    this.setState({
        coords: {
            lat: this._circle.getCenter().lat(),
            lng: this._circle.getCenter().lng()
        }
    })
}

render() {
    return(
        <div style={{display: 'flex',flexDirection: 'row', width: '100%', marginLeft: '37px'}}>
        <MapForm 
            filters={this.props.filters}
            coords={this.state.coords}  
        />
        <GoogleMapsWrapper
            googleMapURL={`https://maps.googleapis.com/maps/api/js?key=${KEY}&v=3.exp&libraries=geometry,drawing,places`}
            loadingElement={<div style={{height: `100%`}}/>}
            containerElement={<div style={{position: 'relative',width: '100%',  }} />}
            mapElement={<div style={{height: `100%`}}/>}
            defaultZoom={13}
            defaultCenter={KYIV}
        >
            <Circle
                ref={(circle) => {this._circle = circle}}
                defaultCenter = {KYIV}
                defaultDraggable={true}
                defaultEditable={true}
                defaultRadius={2000}
                onDragEnd = {this.dragCircle}
                options={{
                    strokeColor: `${colors.vividblue}`,
                    fillColor: `${colors.vividblue}`,
                    fillOpacity: 0.1
                }}
            />
      </GoogleMapsWrapper>
      </div>
    )
  }
}

export default GoogleMapsContainer;

I need only one circle with my methods.mycircles

VladaNak
  • 21
  • 1

1 Answers1

0

Ok, the problem was in React StrictMode component in project.

VladaNak
  • 21
  • 1