Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locate User example not working when used in CRA #921

Closed
woss opened this issue Oct 28, 2019 · 20 comments
Closed

Locate User example not working when used in CRA #921

woss opened this issue Oct 28, 2019 · 20 comments
Assignees

Comments

@woss
Copy link

woss commented Oct 28, 2019

when i try to add the same code to a component and then call it within my react app i keep getting the following error,

mapbox-gl.js:33 Uncaught TypeError: Cannot read property 'getMaxBounds' of undefined
    at o._isOutOfMapMaxBounds (mapbox-gl.js:33)
    at o._onSuccess (mapbox-gl.js:33)

Map settings are the same as in the example.

In general all other (that i am using) features are working.

Any help would be appreciated

@Pessimistress
Copy link
Collaborator

This error seems to be inside mapbox-gl. Can you check which mapbox-gl version is installed in your project?

@woss
Copy link
Author

woss commented Oct 29, 2019

These are installed components

yarn list v1.19.1
├─ react-map-gl@5.1.0-alpha.1
├─ @mapbox/geojson-area@0.2.2
├─ @mapbox/geojson-rewind@0.4.0
├─ @mapbox/geojson-types@1.0.2
├─ @mapbox/jsonlint-lines-primitives@2.0.2
├─ @mapbox/mapbox-gl-supported@1.4.1
├─ @mapbox/point-geometry@0.1.0
├─ @mapbox/tiny-sdf@1.1.1
├─ @mapbox/unitbezier@0.0.0
├─ @mapbox/vector-tile@1.3.1
├─ @mapbox/whoots-js@3.1.0
└─ mapbox-gl@1.5.0

I wonder why copying 100% of the code from your example to separate file and creating the Storybook story fails.

@niikNak
Copy link

niikNak commented Oct 29, 2019

Yeah I'm having the same issue. Have the same mapbox-gl version.
Maybe this is relevant? https://github.com/mapbox/mapbox-gl-js/pull/8756/files

@niikNak
Copy link

niikNak commented Oct 30, 2019

Downgrading to mapbox-gl@1.4.1 seemed to fix the issue.
I'll be honest, I'm a bit new to reporting issues on public repos. Would it be a good idea to report the issue to the mapbox-gl-js team as well?

@woss
Copy link
Author

woss commented Oct 31, 2019

well, it would, but I am using this lib and their examples. Maybe there is nothing to do with the mapbox itself rather than passing the correct data from wrapped component to actual mapbox component.

@VictorBaudot
Copy link

Downgrading to mapbox-gl@1.4.1 seemed to fix the issue.

I personally still have the error after downgrading to 1.4.1

@woss
Copy link
Author

woss commented Oct 31, 2019

for me, it's gone.
now I realised that location is off by close to 1km, investigating that 😁

@TashTenner
Copy link

Same issue here - is downgrading the only way to solve it?

@Pessimistress
Copy link
Collaborator

@xintongxia I tried this on the standalone example and it also errors out. You can reproduce this by upgrading the mapbox-gl dependency to 1.5.0. I believe it can be fixed by assigning _mapboxGeolocateControl._map.

@Pessimistress
Copy link
Collaborator

Should be fixed in 5.1.2.

@xintongxia
Copy link

5.1.2 is published

@krewllobster
Copy link

krewllobster commented Nov 8, 2019

@xintongxia After upgrading from react-map-gl 5.1.0 to 5.1.2 and trying to nest the within my component, I receive the following error:

Uncaught TypeError: Cannot read property 'classList' of undefined at o._onSuccess (mapbox-gl.js:24638) o._onSuccess @ mapbox-gl.js:24638

This error (when in debug mode on localhost) causes the debugger to pause execution. If I unpause to continue past this error, the map jumps to the user-location (it doesn't fly) and then the map becomes unresponsive.

I am also using create-react-app.

Edit: I found this stack overflow thread from 2016 which implies that a div may be missing around the internal mapbox instance?

@xintongxia
Copy link

@krewllobster what is your mapboxgl version? maybe you can try 1.5?

I put our example code in a sandbox, which you can playaround. It would be easier for me to debug if you can share the code which can reproduce the error.
https://codesandbox.io/s/geolocate-control-07nod

@krewllobster
Copy link

krewllobster commented Nov 8, 2019

@xintongxia already on {"mapbox-gl": "^1.5.0"}

The code causing the issue:

import MapGL, { GeolocateControl } from 'react-map-gl'
import mapboxgl from 'mapbox-gl'

const REACT_APP_MAPBOX_TOKEN = process.env.REACT_APP_MAPBOX_TOKEN

const initialViewport = {
  latitude: 40.7128,
  longitude: -74.006,
  zoom: 7
}

const geolocateStyle = {
  position: 'absolute',
  top: 0,
  right: 0,
  margin: 10
}

export const MainMap = () => {
  // local state
  const [mapViewport, setMapViewport] = useState(initialViewport)
  const [currentBounds, setCurrentBounds] = useState()

  // map reference to give access to underlying mapbox instance
  const mainMapRef = useRef()

  return (
    <MapGL
      {...mapViewport}
      height={'100%'}
      width={'100%'}
      ref={mainMapRef}
      mapStyle={'mapbox://styles/mapbox/light-v9'}
      onViewportChange={setMapViewport}
      mapboxApiAccessToken={REACT_APP_MAPBOX_TOKEN}
      mapOptions={{ maxZoom: 15 }}
    >
      <GeolocateControl
        positionOptions={{ enableHighAccuracy: true }}
        style={geolocateStyle}
      />
    </MapGL>
  )
}

I did get it to work within your codesandbox, but its still causing issues in my repo.

@krewllobster
Copy link

krewllobster commented Nov 8, 2019

Also, upon further investigation, the map is not unresponsive after resuming from the error. It was tricking me! I have maxZoom: 15 in mapOptions, rather than using the maxZoom prop.

FYI, if you add mapOptions={{maxZoom: 15}} and keep zooming after the map stops (using macbook trackpad), the map continue "zooming in" even as the viewport doesn't change. In order to zoom back out, you have to un-scroll as much as you over-scrolled.

The zooming is totally fixed by just using the maxZoom prop though, so probably not a real issue. Geolocate still breaks though.

@krewllobster
Copy link

krewllobster commented Nov 8, 2019

And sorry, one more thing (I'm not sure about Github issue etiquette as to whether I should be leaving new comments or editing):

The line in mapbox.gl.js that is causing the error is:
this.options.showUserLocation && "OFF" !== this._watchState && this._updateMarker(e), this.options.trackUserLocation && "ACTIVE_LOCK" !== this._watchState || this._updateCamera(e), this.options.showUserLocation && this._dotElement.classList.remove("mapboxgl-user-location-dot-stale"), this.fire(new t.Event("geolocate", e)), this._finish();
So it seems like its trying to remove an old user location dot that doesn't exist?

If I set showUserLocation={false} then the error goes away.

@Pessimistress
Copy link
Collaborator

@krewllobster Which browser are you using?

@krewllobster
Copy link

Google Chrome
Version 78.0.3904.97 (Official Build) (64-bit)

@xintongxia
Copy link

I'll look into it shortly.

@Pessimistress
Copy link
Collaborator

fixed in 5.1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants