Saturday 19 October 2019

javascript - How to emulate a click on a MapBox GL JS map?


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.




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?



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 }).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...