0

I tried out this mapbox geocoding example: https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder/ in my application.

Now, I am trying to do the same thing, but instead of using a physical keyboard, I am trying to use on-screen keyboard like: https://virtual-keyboard.js.org/

But at the moment, the inputs from the virtual-keyboard is not triggering the mapbox geocoder. How can I link the two components?

spockshr
  • 372
  • 2
  • 14

1 Answers1

1

As indicated in the implementation of the keyevent function here in the mapbox/mapbox-gl-geocoder source code, the geocoder responds to keydown events, which are fired when a key is pressed.

The documentation for the virtual keyboard you linked includes an onKeyPress method to which you can pass a callback function to be executed when a key is pressed on the virtual keyboard. You can implement a function to simulate a keydown event (as described in this Stack Overflow post) equivalent to the last character from getInput. This should have the effect of triggering the geocoder as through an actual key was pressed.

Adriana Babakanian
  • 1,239
  • 6
  • 8
  • Thank you Adriana. I used the method from the link below to generate the keydown event. https://plainjs.com/javascript/events/trigger-an-event-11/ – spockshr Apr 03 '20 at 07:37