Use the basicGUI api to show a GUI onclick
// Create GUI
let gui = feature.createBasicGui()
feature.on('click',e=>{
if(gui.showing){
// if GUI is showing, hide it. (act like a toggle)
gui.destroy()
return
}
// Add our first control:
let textControl =gui.addText('Hello!')
// Add a button under it
let leftButton = gui.addButton('left',[1,0])
// Add a button under it
let rightButton = gui.addButton('right',[1,1])
// Call the GUI to show.
gui.show()
rightButton.on('click',e=>{
// On right button is clicked
textControl.text = 'right is clicked'
// Call update to update the control
textControl.update()
})
leftButton.on('click',e=>{
// On left button is clicked
textControl.text = 'left is clicked'
// Call update to update the control
textControl.update()
})
})
The scripts listens for a click and toggles a graphic interface on/off when clicked on. It also shows two buttons and reacts accordingly.