VJMAP logoVJMAP
CAD · WebGIS
中

Class: Text

Updated 2026-09-14~ 11 min read
.md

创建文本组件.

param

param 文字内容

param 文字样式

param 用作文本的 DOM 元素。

param 一个字符串,指示应该放置在最靠近坐标的标记部分。选项有“center”、“top”、“bottom”、“left”、“right”、“top-left”、“top-right”、“top-right” “左下”和“右下”.

param 作为要应用的对象相对于元素中心的偏移量(以像素为单位)。负数表示向左和向上.

param 如果未提供options.element.

param 如果未提供options.element,则用于默认文本的比例。.

param 一个布尔值,指示是否可以将文本拖动到地图上的新位置.

param 用户在单击文本期间可以移动鼠标指针以将其视为有效单击(与文本拖动相反)的最大像素数。默认是继承地图的clickTolerance.

param 文本相对于其各自的“rotationAlignment”设置的旋转角度(以度为单位)。正值将顺时针旋转文本.

param map 将 Text 与地图平面对齐。 viewport 将 Text 与视口平面对齐。 auto 自动匹配 rotationAlignment 的值.

param map 对齐 Text 相对于地图的旋转,在地图旋转时保持方位。 viewport 对齐 Text 相对于视口的旋转,与地图旋转无关。 auto 等价于 viewport.

example // Create a new Text. const text = new vjmap.Text({text: "abc“}) .setLngLat([30.5, 50.5]) .addTo(map);

example // Set text options. const text = new vjmap.Text({ text: "abc“, draggable: true }).setLngLat([30.5, 50.5]) .addTo(map);

Hierarchy

  • Evented

    ↳ Text

Table of contents

Constructors

Properties

Methods

Constructors

constructor

+ new Text(options?: TextOptions): Text

构造函数

Parameters
Name Type
options? TextOptions

Returns: Text

Overrides: Evented.constructor

Properties

_style

• _style: object


_textContainerDom

• _textContainerDom: HTMLElement

Methods

addTo

▸ addTo(map: Map): Text

将 Text 附加到 Map 对象。

example const text = new vjmap.Text({text: "abc"}) .setLngLat([30.5, 50.5]) .addTo(map); // add the text to the map

Parameters
Name Type Description
map Map to add the text to.

Returns: Text

Returns itself to allow for method chaining.


getElement

▸ getElement(): HTMLElement

返回 Text 的 HTML 元素。

example const element = text.getElement();

Returns: HTMLElement

Returns the text element.


getLngLat

▸ getLngLat(): LngLatLike

得到经纬度

Returns: LngLatLike


getMarker

▸ getMarker(): Marker

返回 Text 的 Marker 对象。

Returns: Marker


getOffset

▸ getOffset(): number

获取文本的偏移量.

Returns: number

The text's screen coordinates in pixels.


getPitchAlignment

▸ getPitchAlignment(): string

返回文本的当前 pitchAlignment 属性.

Returns: string

The current pitch alignment of the text in degrees.


getPopup

▸ getPopup(): Popup

返回绑定到 Text 的 Popup 实例。

Returns: Popup

Returns the popup.


getRotation

▸ getRotation(): number

返回文本的当前旋转角度(以度为单位).

Returns: number

The current rotation angle of the text.


getRotationAlignment

▸ getRotationAlignment(): string

返回文本的当前 rotationAlignment 属性.

Returns: string

The current rotational alignment of the text.


getStyle

▸ getStyle(): object

得到文本样式

Returns: object


getText

▸ getText(): string

得到文本内容

Returns: string


hide

▸ hide(): void

隐藏

Returns: void


isDraggable

▸ isDraggable(): boolean

如果可以拖动文本,则返回 true。

Returns: boolean

True if the text is draggable.


remove

▸ remove(): Text

从地图中删除文本。

example const text = new vjmap.Text().addTo(map); text.remove();

Returns: Text

Returns itself to allow for method chaining.


setAnimation

▸ setAnimation(animationType: string): void

设置动画

Parameters
Name Type Description
animationType string MAP_ANIMATION_NONE 无动画 MAP_ANIMATION_BOUNCE 弹跳 MAP_ANIMATION_DROP 坠落

Returns: void


setCursor

▸ setCursor(cur: string): void

设置光标

Parameters
Name Type Description
cur string 光标名称

Returns: void


setDraggable

▸ setDraggable(shouldBeDraggable: boolean): Text

设置文本的 draggable 属性和功能.

Parameters
Name Type
shouldBeDraggable boolean

Returns: Text

Returns itself to allow for method chaining.


setLngLat

▸ setLngLat(lnglat: LngLatLike): Text

设置经纬度

Parameters
Name Type
lnglat LngLatLike

Returns: Text


setOffset

▸ setOffset(offset: PointLike): Text

设置文本的偏移量.

Parameters
Name Type Description
offset PointLike 以像素为单位的偏移量,作为 PointLike 对象相对于元素的中心应用。负数表示向左和向上。

Returns: Text

Returns itself to allow for method chaining.


setPitchAlignment

▸ setPitchAlignment(alignment: string): Text

设置文本的 pitchAlignment 属性.

Parameters
Name Type
alignment string

Returns: Text

Returns itself to allow for method chaining.


setPopup

▸ setPopup(popup?: Popup): Text

Binds a Popup to the Text

Parameters
Name Type
popup? Popup

Returns: Text


setRotation

▸ setRotation(rotation: number): Text

Sets the rotation property of the text.

Parameters
Name Type
rotation number

Returns: Text

Returns itself to allow for method chaining.


setRotationAlignment

▸ setRotationAlignment(alignment: string): Text

设置文本的 rotationAlignment 属性.

Parameters
Name Type
alignment string

Returns: Text

Returns itself to allow for method chaining.


setStyle

▸ setStyle(style?: object): Text

设置文本样式

Parameters
Name Type Default value
style object {}

Returns: Text


setText

▸ setText(txt: string): Text

设置文本内容

Parameters
Name Type
txt string

Returns: Text


show

▸ show(): void

显示

Returns: void


togglePopup

▸ togglePopup(): Text

根据 Popup 的当前状态打开或关闭绑定到 Text 的 Popup 实例.

Returns: Text

Returns itself to allow for method chaining.

vjmap / Exports / ThreeLayer

Was this page helpful?