控制冲突行为
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面演示了如何设置标记的冲突行为。
冲突行为用于控制标记与其他标记冲突(重叠)时的显示方式。
如需设置冲突行为,请将 collisionBehavior
设置为以下其中一项:
REQUIRED
:无论是否冲突,一律显示标记
REQUIRED_AND_HIDES_OPTIONAL
:无论是否冲突,始终显示该标记,并隐藏与该标记重叠的所有 OPTIONAL_AND_HIDES_LOWER_PRIORITY
标记或标签。
OPTIONAL_AND_HIDES_LOWER_PRIORITY
:标记仅在未与其他标记重叠时才显示。如果两个同属于这种类型的标记发生重叠,则会显示 zIndex
较高的那个标记。如果二者的 zIndex
也相同,则会显示在屏幕上纵向位置较低的那个标记。
以下示例显示了如何为标记设置冲突行为:
const marker = new Marker3DElement({
position: {lat, lng},
collisionBehavior: google.maps.CollisionBehavior.REQUIRED
});
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-22。
[null,null,["最后更新时间 (UTC):2025-07-22。"],[],[],null,["Select platform: [Android](/maps/documentation/maps-3d/android-sdk/configure-marker-collision-behavior \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/configure-marker-collision-behavior \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/marker-collision \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n\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\n\nThis page demonstrates how to set the collision behavior for a marker.\nCollision behavior controls how a marker will display if it collides (overlaps)\nwith another marker.\n\nTo set collision behavior, set `collisionBehavior` to one of the following:\n\n- `REQUIRED`: Always display the marker regardless of collision\n- `REQUIRED_AND_HIDES_OPTIONAL`: Always display the marker regardless of collision, and hide any `OPTIONAL_AND_HIDES_LOWER_PRIORITY` markers or labels that would overlap with the marker.\n- `OPTIONAL_AND_HIDES_LOWER_PRIORITY`: Display the marker only if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher `zIndex` is shown. If they have the same `zIndex`, the one with the lower vertical screen position is shown.\n\nThe following example shows setting collision behavior for a marker: \n\n const marker = new Marker3DElement({\n position: {lat, lng},\n collisionBehavior: google.maps.CollisionBehavior.REQUIRED\n });"]]