JavaScript MapBox GL JS – How to Emulate a Click

javascriptmapboxmapbox-gl-js

I need to emulate a user click on my MapBox GL JS map.

I doesn't matter where in my map: could be useful to do in the point at the center of my maps if this could be easier.

UPDATE

I've found here https://stackoverflow.com/questions/18323105/programmatically-opening-a-popup-in-a-mapbox-map something that could be useful …

map.fireEvent('click', {latlng: L.latLng(28.04419, -81.947864)});

… but seems to be something about Leaflet

I'd like my code coud be something like this ("broken code" … )

    bounds = map.getBounds();
    x = bounds._ne.lng;
    y = bounds._ne.lat;

    map.fireEvent('click', {latlng: L.latLng(x, y)});

Does fireEvent exist in MapBox GL JS or are there alternatives?

Best Answer

In the doc for Map:

The Map class mixes in Evented methods.

Doc for Evented has info on fire so you can use something like map.fire('click', { lngLat: ll, point: pt }).

Related Question