ui.root.setKeyHandler

Define um manipulador de eventos keydown para o painel raiz com uma chave não predefinida. O manipulador é disparado apenas uma vez quando um usuário pressiona o comando de tecla vinculada. A mesma chave será vinculada ao conjunto de manipuladores mais recente definido para ela.

UsoRetorna
ui.root.setKeyHandler(keyCode, handler, description)
ArgumentoTipoDetalhes
keyCodeList[ui.Key]|ui.KeyUm código de tecla ou uma matriz de códigos de tecla. Por exemplo, ui.Key.A ou [ui.Key.SHIFT, ui.Key.A].
handlerFunçãoO gerenciador do comando de chave.
descriptionString, opcionalUma breve descrição que explica esse comando principal. A descrição vai aparecer no menu de atalhos.

Exemplos

Editor de código (JavaScript)

// Replace the default UI widgets with a few custom widgets.
// Print "Shift A" to the console when Shift+A is pressed.
ui.root.setKeyHandler(
  [ui.Key.SHIFT, ui.Key.A],
  function() {
    print('Shift A');
  },
  'A simple print'
);

// Create a solid black image.
var blackImage = ee.Image(1).visualize({palette: ['black']});

// Create a Layer object so we can easily manipulate its properties.
var blackLayer = ui.Map.Layer(blackImage, {}, 'Black Overlay', true);

// Add the layer to the Map.
Map.layers().add(blackLayer);

// Pressing the "b" key will toggle the layer on and off.
ui.root.setKeyHandler(ui.Key.B, function() {
  // Get the current visibility state.
  var isShown = blackLayer.getShown();

  // Set the visibility to the opposite of the current state.
  blackLayer.setShown(!isShown);

  // Print the status to the console.
  print('Black layer visible: ' + !isShown);
}, 'Toggle black layer');