react-google-maps-api icon indicating copy to clipboard operation
react-google-maps-api copied to clipboard

Issue on modifying drawing modes

Open yodivanbaped opened this issue 4 years ago • 1 comments

I cant modify the drawing modes to show on the maps component.

If I use google global var, I keep getting the error message google is not defined

Your Environment

os: linux

node --version: v12.14.1

How should it behave correctly?

I only want to show polygon on the drawing menu.

<DrawingManager
          onPolygonComplete={this.handlePolygonComplete}
          defaultDrawingMode={null}
          defaultOptions={{
                  drawingControl: true,
                  drawingControlOptions: {
                            drawingModes: [
                                    'polygon'
                            ],

yodivanbaped avatar May 20 '20 07:05 yodivanbaped

@yodivanbaped your code is not from our library. please use docs. google is not defined is very common issue for everybody, please use search, but in short - you need to have separate component which is used as child to <LoadScript />, Loadscript injects google-maps-api script into head, and it is in turn creates global google object. Loadscript does not render children until google object is initialized, that is how you can use it in the code. One more thing - for performance reasons in React you should not pass new objects or arrays to props directly, you need to cache them as const variable or state or React.useMemo()

JustFly1984 avatar May 29 '20 08:05 JustFly1984