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

Custom markers throw error on map zoom event v2.1.1 "cannot read property "tranform" of undefined" #10402

Closed
ajbraudev opened this issue Feb 20, 2021 · 2 comments · Fixed by #10478

Comments

@ajbraudev
Copy link

ajbraudev commented Feb 20, 2021

We are using Mapbox gl js with react and nextjs.
After adding these markers to the map, on a zoom event, we are seeing this error:
Unhandled Runtime Error
TypeError: Cannot read property 'transform' of undefined
Call Stack
na._onOcclusionTimer

it is not a breaking error, everything is running smoothly, but we still get that error, and this error is not caught by the map.on('error') handler. (That would be sufficient for now just to have that work).

import { render } from "react-dom";
const markerEl = new mapboxgl.Marker().setLngLat(marker.lng_lat).addTo(map);

        render(
            <SquareMapIcon id={marker.id} color={marker.color} Icon={WanderIcons[marker.icon]} />,
            markerEl.getElement(),
        );

This was working on version 1, and is no longer working on v2

        markerEl.markerId = marker.id;`
@mourner
Copy link
Member

mourner commented Feb 22, 2021

Looks like a bug that occurs because we don't clear this timeout when a marker is removed:

this._occlusionTimer = setTimeout(this._onOcclusionTimer.bind(this), 60);

Should be an easy fix on our side, but meanwhile, you can work around this by clearing the timer manually when a marker or a map its added to is removed:

clearTimeout(marker._occlusionTimer);

@ajbraudev
Copy link
Author

Looks like a bug that occurs because we don't clear this timeout when a marker is removed:

this._occlusionTimer = setTimeout(this._onOcclusionTimer.bind(this), 60);

Should be an easy fix on our side, but meanwhile, you can work around this by clearing the timer manually when a marker or a map its added to is removed:

clearTimeout(marker._occlusionTimer);

That workaround works great, thank you so much!

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

Successfully merging a pull request may close this issue.

2 participants