开发 Maps JavaScript API Reference Manual Custom Data Layer LabelsLayer

LabelsLayer 最后更新时间: 2026年07月02日

AMap.LabelsLayer

Annotation layer, used to carry LabelMarker markers. Construct a LabelsLayer object and set the layer properties through LabelsLayerOptions

new AMap.LabelsLayer(opts: LabelsLayerOptions)

Parameter

options(LabelsLayerOptions): Annotation Layer Parameters

Attribute

Type

Description

visible

Boolean

Whether the annotation layer is visible, default: true

zIndex

Number

The order value of layer stacking, the larger the number, the higher the layer level, and 1 represents the bottom layer. Default: 120

opacity

Number

The transparency of the layer, the value range is [0 ~ 1], 1 represents completely opaque, 0 represents completely transparent

collision

Boolean

Whether annotations within the annotation layer avoid each other

allowCollision

Boolean

Whether annotations within the layer allow avoidance by other annotation layers

zooms

[Number, Number]

Display hierarchy range of the annotation layer

Demo

var labelsLayer = new AMap.LabelsLayer({
  zooms: [3, 20],
  zIndex: 1000,
  collision: true, //Whether annotations within this layer avoid each other
  allowCollision: true, //Whether to avoid between different annotation layers
});
map.add(labelsLayer);

Method

getCollision()

Get whether the annotation layer supports internal annotation avoidance

return value: (Boolean) Return true if avoidance is supported, return false if avoidance is not supported

Demo:

labelsLayer.getCollision();

setCollision(collision)

Set whether the annotation layer supports internal annotation avoidance

Parameter: collision (boolean) Pass true to support avoidance, pass false to not support avoidance

Demo:

labelsLayer.setCollision(true);

getAllowCollision()

Get whether the annotation layer allows other layers to avoid annotations

return value: (Boolean) Returns true if avoidance is allowed, returns false if avoidance is not allowed

Demo:

labelsLayer.getAllowCollision();

setAllowCollision(allowCollision)

Set whether the annotation layer allows avoidance by other layer annotations. Enabling this feature allows map annotations to avoid LabelMarker

Parameter: allowCollision(boolean) Pass true to allow avoidance, pass false to disallow avoidance

Demo:

labelsLayer.setAllowCollision(true);

getOpacity()

Get the transparency of the annotation layer

return value: (Number) opacity layer transparency

Demo:

labelsLayer.getOpacity();

setOpacity(opacity)

Set layer transparency, range [0 ~ 1], where 1 represents completely opaque and 0 represents completely transparent

Parameter: opacity (Number) Layer transparency

Demo:

labelsLayer.setOpacity(0.5);

getZooms()

Get the display level range of the annotation layer

return value: ([Number, Number]) The displayable level range of this layer

Demo:

labelsLayer.getZooms();

setZooms(zooms)

Set the display level range of the annotation layer

Parameter: zooms([Number, Number]) Zoom Range Displayable by This Layer

Demo:

labelsLayer.setZooms([8,12]);

getzIndex()

Get Label Layer Overlay Order

return value: (Number) zIndex Layer Level

Demo:

labelsLayer.getzIndex();

setzIndex(zIndex)

Set Label Layer Overlay Order

Parameter: zIndex (Number) Layer Z-index Value

Demo:

labelsLayer.setzIndex(10);

add(labelMarkers)

Add labelMarker to the label layer

Parameter: labelMarkers (LabelMarker | Array<LabelMarker>) Can add a single label or label array

Demo:

labelsLayer.add(labelMarker); //Detailed example reference tutorial document

remove(labelMarkers)

Remove labelMarker from the label layer

Parameter: labelMarkers (LabelMarker | Array<LabelMarker>) Can remove a single label or label array

Demo:

labelsLayer.remove(labelMarker); //Detailed example reference tutorial document

clear()

Clear all annotations on the annotation layer

Demo:

labelsLayer.clear();

show()

Set layer visibility to visible

Demo:

labelsLayer.show();

hide()

Set layer visibility to hidden

Demo:

labelsLayer.hide();

getAllOverlays()

Retrieve all annotation objects within the annotation layer

return value: (Array<any>) All annotation objects within the annotation layer

Demo:

labelsLayer.getAllOverlays();

返回顶部 示例中心 常见问题 智能客服 公众号
二维码