How can I simulate a click on Mapbox

Viewed 530

I'm struggling to simulate a click on the map. Here is my code.

map.fire('click', function ()
    { 
        newDropoff({lng: 27.4199870950609,lat: 53.240419723523775});
        updateDropoffs(dropoffs);
    })

The original code is taken from this guide

map.on('click', function (e) {
    // When the map is clicked, add a new drop off point
    // and update the `dropoffs-symbol` layer
    newDropoff(map.unproject(e.point));
    updateDropoffs(dropoffs);
    });

Does anyone know what should be corrected in my code? PS I've checked other sources already

1 Answers

You just pass an object, not a function:

map.fire('click', {
  lngLat: new mapboxgl.LngLat(27.42, 53.24)})
})

If you need the other properties from MapMouseEvent you will need to add them manually.

Related