Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này mô tả các sự kiện trên giao diện người dùng và sự kiện lỗi mà bạn có thể nghe và xử lý theo phương thức lập trình.
Sự kiện trên giao diện người dùng
Phần này trình bày các sự kiện tương tác và thông báo thay đổi trạng thái mà bạn có thể nghe và xử lý theo phương thức lập trình khi làm việc với bản đồ 3D. JavaScript trong trình duyệt dựa trên sự kiện, tức là phản hồi tương tác của người dùng bằng cách tạo ra các sự kiện mà chương trình của bạn có thể nghe và thực thi mã cho phù hợp.
Có hai loại sự kiện chính:
Các sự kiện tương tác của người dùng (chẳng hạn như lượt nhấp chuột) sẽ được truyền từ khung nhìn bản đồ 3D sang mã của bạn. Những sự kiện này cho phép bạn phản hồi các thao tác trực tiếp của người dùng trong môi trường bản đồ 3D. Xem mẫu.
Thông báo thay đổi trạng thái phản ánh nội dung cập nhật đối với mô hình dữ liệu bản đồ 3D và trạng thái kết xuất cơ bản, bằng cách sử dụng lược đồ đặt tên gmp-propertychange thông thường.
Mỗi đối tượng API ánh xạ 3D sẽ hiển thị một tập hợp các sự kiện được đặt tên mà chương trình của bạn có thể đăng ký trình nghe sự kiện và thực thi logic khi những sự kiện đó xảy ra bằng hàm addEventListener() tích hợp sẵn.
Mẫu sau đây cho biết những sự kiện nào được kích hoạt khi người dùng tương tác với bản đồ:
[null,null,["Cập nhật lần gần đây nhất: 2025-04-29 UTC."],[],[],null,["\u003cbr /\u003e\n\n| This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage\n| descriptions](/maps/launch-stages).\n\n\u003cbr /\u003e\n\nThis page describes the user interface events and error events that you can\nlisten for and handle programmatically.\n\nUser Interface Events\n\nThis section outlines the interactive events and state change notifications you\ncan listen for and handle programmatically when working with 3D maps. JavaScript\nwithin the browser is event-driven, meaning it responds to user interactions by\ngenerating events that your program can listen to and execute code accordingly.\n\nThere are two main types of events:\n\n- User interaction events (such as mouse clicks) are propagated from the 3D map viewport to your code. These events allow you to respond to direct user actions within the 3D map environment. [View\n sample](/maps/documentation/javascript/examples/3d/polygon-click-event).\n- State change notifications reflect updates to the underlying 3D map data models and rendering state, using a conventional `gmp-propertychange` naming scheme.\n\nEach 3D mapping API object exposes a set of named events that your program can\nregister event listeners for and execute logic when those events occur using the\nbuilt-in `addEventListener()` function.\n\nThe following sample shows which events are triggered as a user interacts with\nthe map:"]]