Earth Engine 即將推出
非商業用途的配額級別,以便保護共用運算資源,並確保所有使用者都能享有穩固效能。所有非商業用途的專案都必須在
2026 年 4 月 27 日前選取配額級別,否則屆時會預設為「社群」級別。在
2026 年 4 月 27 日,所有專案 (無論選取級別的日期為何) 的級別配額都會生效。
瞭解詳情。
ui.root.setKeyHandler
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為根面板設定 keydown 事件處理常式,並使用非預先定義的鍵。使用者按下繫結的鍵盤指令時,處理常式只會觸發一次。相同鍵會繫結至最新設定的處理常式。
| 用量 | 傳回 |
|---|
ui.root.setKeyHandler(keyCode, handler, description) | |
| 引數 | 類型 | 詳細資料 |
|---|
keyCode | List[ui.Key]|ui.Key | 鍵碼或鍵碼陣列。例如 ui.Key.A 或 [ui.Key.SHIFT, ui.Key.A]。 |
handler | 函式 | 金鑰指令的處理常式。 |
description | 字串 (選用) | 簡短說明這個按鍵指令。說明會顯示在快速鍵選單中。 |
範例
程式碼編輯器 (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');
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-03-27 (世界標準時間)。
[null,null,["上次更新時間:2026-03-27 (世界標準時間)。"],[],["The `setKeyHandler` function binds a key command to a handler function on the root panel. It accepts a key code (or array of codes), a handler function, and an optional description. When the bound key is pressed, the handler is executed once. Only the most recently assigned handler for a specific key will be triggered. Key codes can be individual (e.g., `ui.Key.A`) or combined (e.g., `[ui.Key.SHIFT, ui.Key.A]`). The description is used in the Shortcuts Menu.\n"]]