Skip to content

m-gis核心库 v0.4.4


m-gis核心库 / Label

类: Label ​

定义于: overlay/entity/Label.ts:45

用于三维中添加文字标签

// 添加图层 const layer = new EntityLayer().addToViewer(this.$viewer); const label = new Label( new Position(118.78600228, 31.9135434, 1.66113721), "启业云南京大数据" ).addToLayer(layer); label.setStyle({ showBackground: true, backgroundColor: Color.fromCssColor("rgba(47, 53, 60, 0.8)"), verticalOrigin: 1, font: "16px 宋体" }); // 注册 label 鼠标移入事件 label.on(MouseEventType.CLICK, evt => { console.log(evt); });

继承 ​

构造函数 ​

构造函数 ​

new Label(position, options?): Label

定义于: overlay/entity/Label.ts:56

参数 ​

position ​

Position

坐标

options? ​

OPT = DEF_OPT

参数

返回 ​

Label

重写了 ​

Overlay.constructor

属性 ​

_attr ​

_attr: any

定义于: overlay/Overlay.ts:26

继承自 ​

Overlay._attr


_bid ​

_bid: any

定义于: overlay/Overlay.ts:17

继承自 ​

Overlay._bid


_canvasStyles ​

_canvasStyles: any

定义于: overlay/entity/Label.ts:48


_customData ​

_customData: any

定义于: overlay/Overlay.ts:29

继承自 ​

Overlay._customData


_delegate ​

_delegate: any

定义于: overlay/Overlay.ts:21

继承自 ​

Overlay._delegate


_id ​

_id: string | number

定义于: overlay/Overlay.ts:16

继承自 ​

Overlay._id


_isCanvas ​

_isCanvas: boolean

定义于: overlay/entity/Label.ts:47


_labelBackgroundOptions ​

_labelBackgroundOptions: any

定义于: overlay/entity/Label.ts:49


_labelBackgroundStyle ​

_labelBackgroundStyle: any

定义于: overlay/entity/Label.ts:50


_layer ​

_layer: any

定义于: overlay/Overlay.ts:22

继承自 ​

Overlay._layer


_options ​

_options: any

定义于: overlay/Overlay.ts:18

继承自 ​

Overlay._options


_overlayEvent ​

_overlayEvent: OverlayEvent

定义于: overlay/Overlay.ts:28

继承自 ​

Overlay._overlayEvent


_position ​

_position: any

定义于: overlay/Overlay.ts:19

继承自 ​

Overlay._position


_positions ​

_positions: any

定义于: overlay/Overlay.ts:20

继承自 ​

Overlay._positions


_relaters ​

_relaters: any

定义于: overlay/Overlay.ts:30

继承自 ​

Overlay._relaters


_show ​

_show: boolean

定义于: overlay/Overlay.ts:24

继承自 ​

Overlay._show


_state ​

_state: any

定义于: overlay/Overlay.ts:23

继承自 ​

Overlay._state


_style ​

_style: any

定义于: overlay/Overlay.ts:25

继承自 ​

Overlay._style


_text ​

_text: any

定义于: overlay/entity/Label.ts:46


interactionEvents ​

interactionEvents: any[]

定义于: overlay/Overlay.ts:31

继承自 ​

Overlay.interactionEvents


type ​

type: any

定义于: overlay/Overlay.ts:27

继承自 ​

Overlay.type

访问器 ​

attr ​

Getter 签名 ​

get attr(): any

定义于: overlay/Overlay.ts:106

返回 ​

any

Setter 签名 ​

set attr(attr): void

定义于: overlay/Overlay.ts:102

覆盖物的额外属性设置

参数 ​
attr ​

any

返回 ​

void

继承自 ​

Overlay.attr


center ​

Getter 签名 ​

get center(): Position

定义于: overlay/Overlay.ts:137

返回 ​

Position

继承自 ​

Overlay.center


customData ​

Getter 签名 ​

get customData(): any

定义于: overlay/Overlay.ts:141

返回 ​

any

继承自 ​

Overlay.customData


delegate ​

Getter 签名 ​

get delegate(): any

定义于: overlay/Overlay.ts:124

覆盖物的代理对象

返回 ​

any

继承自 ​

Overlay.delegate


id ​

Getter 签名 ​

get id(): any

定义于: overlay/Overlay.ts:78

返回 ​

any

Setter 签名 ​

set id(id): void

定义于: overlay/Overlay.ts:74

设置覆盖物的业务 id

参数 ​
id ​

any

返回 ​

void

继承自 ​

Tileset.id


overlayEvent ​

Getter 签名 ​

get overlayEvent(): OverlayEvent

定义于: overlay/Overlay.ts:115

覆盖物的事件对象

返回 ​

OverlayEvent

继承自 ​

Overlay.overlayEvent


overlayId ​

Getter 签名 ​

get overlayId(): string | number

定义于: overlay/Overlay.ts:61

覆盖物唯一标识

返回 ​

string | number

继承自 ​

Overlay.overlayId


position ​

Getter 签名 ​

get position(): any

定义于: overlay/entity/Label.ts:79

返回 ​

any

Setter 签名 ​

set position(position): void

定义于: overlay/entity/Label.ts:74

参数 ​
position ​

any

返回 ​

void


relaters ​

Getter 签名 ​

get relaters(): any[]

定义于: overlay/Overlay.ts:145

返回 ​

any[]

继承自 ​

Overlay.relaters


show ​

Getter 签名 ​

get show(): boolean

定义于: overlay/Overlay.ts:94

返回 ​

boolean

Setter 签名 ​

set show(show): void

定义于: overlay/Overlay.ts:86

覆盖物的可见性

参数 ​
show ​

boolean

返回 ​

void

继承自 ​

Overlay.show


state ​

Getter 签名 ​

get state(): any

定义于: overlay/Overlay.ts:133

覆盖物的状态

返回 ​

any

继承自 ​

Overlay.state


text ​

Getter 签名 ​

get text(): any

定义于: overlay/entity/Label.ts:94

返回 ​

any

Setter 签名 ​

set text(text): void

定义于: overlay/entity/Label.ts:83

参数 ​
text ​

any

返回 ​

void


viewer ​

Getter 签名 ​

get viewer(): any

定义于: overlay/Overlay.ts:52

返回 ​

any

继承自 ​

Overlay.viewer

方法 ​

_combineIconAndLabel() ​

_combineIconAndLabel(options): HTMLCanvasElement

定义于: overlay/entity/Label.ts:254

参数 ​

options ​

any

返回 ​

HTMLCanvasElement


_drawRoundRectPath() ​

_drawRoundRectPath(ctx, x, y, width, height, radius): void

定义于: overlay/entity/Label.ts:316

参数 ​

ctx ​

CanvasRenderingContext2D

x ​

number

y ​

number

width ​

number

height ​

number

radius ​

number

返回 ​

void


_fillRoundRect() ​

_fillRoundRect(ctx, x, y, width, height, radius, fillColor, lineWidth, strokeColor): false | undefined

定义于: overlay/entity/Label.ts:288

参数 ​

ctx ​

CanvasRenderingContext2D

x ​

number

y ​

number

width ​

number

height ​

number

radius ​

number

fillColor ​

string

lineWidth ​

number

strokeColor ​

string

返回 ​

false | undefined


_strokeRoundRect() ​

_strokeRoundRect(ctx, x, y, width, height, radius, lineWidth, strokeColor): false | undefined

定义于: overlay/entity/Label.ts:303

参数 ​

ctx ​

CanvasRenderingContext2D

x ​

number

y ​

number

width ​

number

height ​

number

radius ​

number

lineWidth ​

number

strokeColor ​

string

返回 ​

false | undefined


addCustomData() ​

addCustomData(key, value): void

定义于: overlay/Overlay.ts:267

参数 ​

key ​

any

value ​

any

返回 ​

void

继承自 ​

Overlay.addCustomData


addToLayer() ​

addToLayer(layer): Label

定义于: overlay/Overlay.ts:260

添加到指定图层

参数 ​

layer ​

any

指定图层

返回 ​

Label

继承自 ​

Overlay.addToLayer


clearCustomData() ​

clearCustomData(): void

定义于: overlay/Overlay.ts:275

返回 ​

void

继承自 ​

Overlay.clearCustomData


clearRelate() ​

clearRelate(): void

定义于: overlay/Overlay.ts:288

返回 ​

void

继承自 ​

Overlay.clearRelate


eachRelaters() ​

eachRelaters(callback): void

定义于: overlay/Overlay.ts:292

参数 ​

callback ​

any

返回 ​

void

继承自 ​

Overlay.eachRelaters


fire() ​

fire(type, params): Label

定义于: overlay/Overlay.ts:339

触发事件

参数 ​

type ​

string | number

params ​

any

返回 ​

Label

继承自 ​

Overlay.fire


getCustomData() ​

getCustomData(key): any

定义于: overlay/Overlay.ts:271

参数 ​

key ​

any

返回 ​

any

继承自 ​

Overlay.getCustomData


off() ​

off(type, callback, context?): Label

定义于: overlay/Overlay.ts:324

注销事件

参数 ​

type ​

string | number

事件类型

callback ​

any

监听回调

context? ​

any

返回 ​

Label

继承自 ​

Overlay.off


on() ​

on(type, callback, context?): Label

定义于: overlay/Overlay.ts:304

注册事件

参数 ​

type ​

string | number

事件类型

callback ​

any

监听回调

context? ​

any

返回 ​

Label

继承自 ​

Overlay.on


relate() ​

relate(overlay): void

定义于: overlay/Overlay.ts:279

参数 ​

overlay ​

Overlay

返回 ​

void

继承自 ​

Overlay.relate


remove() ​

remove(): Label

定义于: overlay/Overlay.ts:243

从图层上移出

返回 ​

Label

继承自 ​

Overlay.remove


setBackgroundCanvas() ​

setBackgroundCanvas(options): Label | undefined

定义于: overlay/entity/Label.ts:229

设置文字背景图片(canvas方式)

参数 ​

options ​

any

样式可选属性

返回 ​

Label | undefined

示例 ​

js
   {
     "width": 128, // canvas宽度
     "height": 48, // canvas高度
     "radius": 20, // 圆角,只支持数字
     "label": {
       font: 'bold 14px sans-serif',
       textAlign: 'center',
       textBaseline: 'middle',
       fillStyle: 'rgba(245,255,250)',
       labelLeft: 64,
       labelTop: 24
     },
     "stroke": {
       lineWidth: 5,
       strokeStyle: 'rgba(200,128,128, 1)'
     },
     "fill": {
       fillStyle: 'rgba(70,130,180, 0)'
     },
     "img":{
       "translucencyByDistance": {
         "near": 0, //最近距离
         "nearValue": 0, //最近距离值
         "far": 1, //最远距离值
         "farValue": 0 //最远距离值
       }, //根据距离设置透明度
       "scaleByDistance": {
         "near": 0, //最近距离
         "nearValue": 0, //最近距离值
         "far": 1, //最远距离值
         "farValue": 0 //最远距离值
       }, //根据距离设置比例
       "distanceDisplayCondition": {
         "near": 0, //最近距离
         "far": Number.MAX_VALUE //最远距离
       }, //根据距离设置可见
       "disableDepthTestDistance": 0 //
     }
   }

setBackgroundImg() ​

setBackgroundImg(options): Label

定义于: overlay/entity/Label.ts:381

设置文字背景图片(传图片方式)

参数 ​

options ​

any

参数可选项,参数等同于billboard参数

返回 ​

Label

示例 ​

js
// 样式参数(可选)
 {
   "icon": require("../xxx.png"), // 图标资源,可以为 URI, Canvas等
   "size": [32,32], // 图标尺寸
   "scale": 1, //比例
   "pixelOffset": { "x": 0, "y": 0 }, //偏移像素
   "rotation": 0, //旋转角度
   "heightReference": 0, // 指定 billboard 高度模式。 NONE: 0, CLAMP_TO_GROUND: 1, RELATIVE_TO_GROUND: 2
   "color": Color.WHITE, // 指定 billboard 图片的颜色。
   "translucencyByDistance": {
     "near": 0, //最近距离
     "nearValue": 0, //最近距离值
     "far": 1, //最远距离值
     "farValue": 0 //最远距离值
   }, //根据距离设置透明度
   "scaleByDistance": {
     "near": 0, //最近距离
     "nearValue": 0, //最近距离值
     "far": 1, //最远距离值
     "farValue": 0 //最远距离值
   }, //根据距离设置比例
   "distanceDisplayCondition": {
     "near": 0, //最近距离
     "far": Number.MAX_VALUE //最远距离
   }, //根据距离设置可见
   "disableDepthTestDistance": 0 // 深度检测距离,用于防止剪切地形,设置为零时,将始终应用深度测试。设置为Number.POSITIVE_INFINITY时,永远不会应用深度测试。
 }

setLabel() ​

setLabel(text, textStyle): Label

定义于: overlay/Overlay.ts:229

设置文字标签

参数 ​

text ​

string

指定文本的属性。支持显式换行符'\ n'。

textStyle ​

any

text 样式

返回 ​

Label

继承自 ​

Overlay.setLabel


setStyle() ​

setStyle(style): Label

定义于: overlay/entity/Label.ts:151

设置 Label 样式

参数 ​

style ​

OPT

样式可选属性

// 样式参数(可选) { "text": "测试文本", // 文本内容 "font": "30px sans-serif", // CSS 字体设置 "style": 2, // 指定 label 绘制风格。FILL: 0, OUTLINE: 1, FILL_AND_OUTLINE: 2 "scale": 1, //比例 "pixelOffset": { "x": 0, "y": 0 }, //偏移像素 "horizontalOrigin": 0, // 水平对齐方式。CENTER: 0, LEFT: 1, RIGHT: -1 "verticalOrigin": 0, // 垂直对齐方式。 CENTER: 0, BOTTOM: 1, BASELINE: 2, TOP: -1 "heightReference": 0, //高度参照,0:位置无参照,位置是绝对的,1:位置固定在地形上 2:位置高度是指地形上方的高度。 "showBackground": false, //是否显示背景 "backgroundColor":Color.BLACK, //背景颜色 "backgroundPadding": { "x": 0, "y": 0 }, //背景间隙 "fillColor": Color.BLACK, //文字颜色 "outlineColor": Color.WHITE, //边框颜色 "outlineWidth": 0, //边框大小, "scaleByDistance": { "near": 0, //最近距离 "nearValue": 0, //最近距离值 "far": 1, //最远距离值 "farValue": 0 //最远距离值 }, //根据距离设置比例 "translucencyByDistance": { "near": 0, //最近距离 "nearValue": 0, //最近距离值 "far": 1, //最远距离值 "farValue": 0 //最远距离值 }, //根据距离设置透明度 "distanceDisplayCondition": { "near": 0, //最近距离 "far": Number.MAX_VALUE //最远距离 }, //根据距离设置可见 "disableDepthTestDistance": 0 // 深度检测距离,用于防止剪切地形,设置为零时,将始终应用深度测试。设置为Number.POSITIVE_INFINITY时,永远不会应用深度测试。 }

返回 ​

Label


unRelate() ​

unRelate(overlay): void

定义于: overlay/Overlay.ts:283

参数 ​

overlay ​

Overlay

返回 ​

void

继承自 ​

Overlay.unRelate


fromEntity() ​

static fromEntity(entity): Label | undefined

定义于: overlay/entity/Label.ts:416

从 entity 中解析出 Label

参数 ​

entity ​

Entity

返回 ​

Label | undefined


getOverlayType() ​

static getOverlayType(type): string | number | undefined

定义于: overlay/Overlay.ts:361

获取 Overlay 类型

参数 ​

type ​

string

返回 ​

string | number | undefined

继承自 ​

Overlay.getOverlayType


registerType() ​

static registerType(type): void

定义于: overlay/Overlay.ts:349

Overlay 类型注册

参数 ​

type ​

string

返回 ​

void

继承自 ​

Overlay.registerType

MGis 地理三维库