与地图互动
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
此页面介绍了可通过程序化方式监听和处理的界面事件及错误事件。
界面事件
本部分概述了在使用 3D 地图时,您可以通过程序化方式监听和处理的互动事件和状态变化通知。浏览器中的 JavaScript 是由事件驱动的,这意味着它会生成事件来响应用户互动,而您的程序可以相应地监听并执行代码。
事件主要有两种类型:
- 用户互动事件(例如鼠标点击)会从 3D 地图视口传播到您的代码中。借助这些事件,您可以响应 3D 地图环境中的直接用户操作。查看示例。
- 状态更改通知使用传统的
gmp-propertychange
命名方案反映对底层 3D 地图数据模型和渲染状态的更新。
每个 3D 地图绘制 API 对象都会公开一组已命名的事件,您的程序可以使用内置的 addEventListener()
函数为这些事件注册事件监听器并在这些事件发生时执行逻辑。
以下示例展示了当用户与地图互动时触发的事件:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-29。
[null,null,["最后更新时间 (UTC):2025-04-29。"],[],[],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:"]]