2

I need to render a button centered over a specific location, right now I'm using an OverlayView to render the button.

    <OverlayView
      position={north}
      mapPaneName={OverlayView.OVERLAY_MOUSE_TARGET}
    >
      <MapContextButton
        onClick={e => {
          e.preventDefault();
          console.log('click');
        }}
      />
    </OverlayView>

It produces the following result, rendering the overlay's top-left position on the north point. Is there a way to make it render centered on location?

enter image description here

Eugene
  • 10,006
  • 4
  • 37
  • 55

2 Answers2

1

It can be done with CSS using transform: translate(-50%,-50%):

<OverlayView
             position={north}
             mapPaneName={OverlayView.OVERLAY_MOUSE_TARGET}
             >
  <MapContextButton
                    style={transform: "translate(-50%,-50%)"}
                    onClick={e => {
    e.preventDefault();
    console.log('click');
    }}
    />
</OverlayView>
ATP
  • 2,939
  • 4
  • 13
  • 34
0

I was able to solve this by using Marker with an anchor position set for the icon

          <Marker
            position={north}
            icon={{
              url: MapContextIcon,
              anchor: new window.google.maps.Point(16, 16),
            }}
            onClick={() => {
              setIsPopoverOpen(!isPopoverOpen);
            }}
          />
Eugene
  • 10,006
  • 4
  • 37
  • 55