Skip to content

[Bug] Geolocate control is shown twice on page load #1883

@britt

Description

@britt

Description

I have a next.js app where I am rendering a fullscreen map with a GeolocateControl. The first time I load the page, or if I reload it, it shows two GeolocateControls one on top of the other.

Screen Shot 2022-06-09 at 10 48 52 AM

The control works as expected, but no matter which one you click the bottom control highlights.

Screen Shot 2022-06-09 at 10 48 57 AM

If I navigate away from the page to another route in my app (I am using next.js routing) when I return to the map it only shows one control.

Expected Behavior

It should show only one Geolocate control.

Steps to Reproduce

import Map, { GeolocateControl } from 'react-map-gl'

<Map
        initialViewState={{
          longitude: long,
          latitude: lat,
          zoom: 15
        }}
        id='spot-map'
        ref={map}
        className='h-full w-full'
        attributionControl={false}
        mapStyle='mapbox://styles/mapbox/streets-v11'
        mapboxAccessToken={mapboxgl.accessToken}
      >
        {position && <Marker color='bg-info' latitude={lat} longitude={long} anchor='top' />}
        <GeolocateControl
          trackUserLocation
          showUserLocation
          style={{ position: 'absolute', zIndex: '50', top: 80, right: 6 }}
        />
      </Map>
  1. Load the page
  2. Notice two controls
  3. Navigate to another route
  4. Navigate back
  5. Notice that there is now only 1 control

Environment

  • Framework version: react-map-gl@7.0.10
  • Map library: mapbox-gl@2.7.0
  • Browser: Firefox
  • OS: MacOS 12.2.1

Logs

WebGL warning: texImage: Alpha-premult and y-flip are deprecated for non-DOM-Element uploads. 2
WebGL warning: texImage: Alpha-premult and y-flip are deprecated for non-DOM-Element uploads. 21
WebGL warning: texImage: Alpha-premult and y-flip are deprecated for non-DOM-Element uploads. 4
WebGL warning: texImage: Alpha-premult and y-flip are deprecated for non-DOM-Element uploads. 4
After reporting 32, no further warnings will be reported for this WebGL context. ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions