Summary
Methods:
clone |
克隆一个新的文本符号。 |
getBackgroundColor |
获取背景填充颜色。 |
getBackgroundImage |
获取文字样式背景图片 |
getFontColor |
获取填充颜色。 |
getFontFace |
获取字体的字族,比如'宋体'。 |
getFontSize |
获取字体大小。 |
getFontStyle |
获取字体类型eg:斜体。 |
getFontWeight |
获取字体粗细。 |
getHaloColor |
获取描边颜色。 |
getHaloWidth |
获取描边宽度。 |
getLineRenderData |
创建线文字图集,返回纹理坐标, |
getLineRenderData2 |
临时使用 勿删 |
getOffset |
获取偏移量。 |
getOpacity |
获取透明系数。 |
getOriginText |
获取原始文本内容。当原始文本太长时,会被截取展示。 |
getPaddingBottom |
获取文字的底部内衬宽度 |
getPaddingLeft |
获取文字的左边内衬宽度 |
getPaddingRight |
获取文字的右边内衬宽度 |
getPaddingTop |
获取文字的顶部内衬宽度 |
getRotation |
获取旋转角度。 |
getRowTextCount |
获取每行文字个数的最大值。 |
getRowWidth |
固定文字宽度的模式下,获取每行宽度。 |
getShadowColor |
获取文字样式的阴影颜色 |
getShadowOffset |
获取文字样式的阴影偏移量 |
getText |
获取文本内容。 |
getTextAlign |
已废弃,建议使用getTextAlignment代替。用于获取文本水平排列方式。 |
getTextAlignment |
获取文本水平排列方式。 |
getTextBaseline |
获取文本基线,即垂直排列的方式。 |
setBackgroundColor |
设置背景填充颜色。 |
setBackgroundImage |
设置文字样式背景图片 |
setFontColor |
设置字体的颜色。 |
setFontFace |
设置字体族名称。参数fontFace即css中的fontFamily,但是只支持单个字体族名称,不支持多个字体族组成的列表。 |
setFontSize |
设置字体大小。最小值为8,最大值为64. |
setFontStyle |
设置字体样式。默认是“normal”,可取的值包括“normal”、“italic”、“oblique”。 |
setFontWeight |
设置字体粗细,默认是"normal"。可以传入的值包括:"normal"、"bold"、"bolder",传入其它异常值,会导致不可预估的错误! |
setHaloColor |
设置字的描边颜色。 |
setHaloWidth |
设置描边宽度。 |
setOffset |
设置文字的偏移量。 |
setOpacity |
设置文字整体的透明系数。 |
setRotation |
设置旋转角度。 |
setRowTextCount |
设置每行文字个数的上限。 |
setText |
设置文本内容。 |
setTextAlign |
已废弃,建议使用setTextAlignment代替。用于设置文本水平排列方式,可选项包括'left','right','center'。 |
setTextAlignment |
设置文本水平排列方式。 |
setTextBaseline |
设置文本基线。 |
Constructor
new TextSymbol(options)
构造函数。
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | 文本符号的可选属性。
|
Example
let textSymbol = new hmap.style.TextSymbol({
fontWeight: 'normal',//字的粗细
fontStyle: "normal",//斜体等
fontSize: 16,//字大小
fontFace: "Microsoft YaHei",//字体
text: "江南大道",
offset: new hmap.basetype.Offset(1,1,0),
placement: "point",//文本的放置方式
rotateWithView: false,//是否跟着视图旋转
rotation: 0,//旋转角度,单位为度
textAlignment: "center",//文本水平排列方式,分为center、left、right,end,start
textBaseline: "top",//文本垂直排列方式,分为top、middle、bottom
overflow: false,//是否允许文本超出多边形或线的路径长度
fontColor: new hmap.style.Color(6,6,6,1),//字体填充颜色
haloColor: new hmap.style.Color(255,1,1,1),//字体描边颜色
haloWidth: 1,//字体描边宽
backgroundColor: new hmap.style.Color(157,200,247,1),//背景填充颜色
maxAngle: Math.PI/4, //允许相邻文字之间的最大角度,单位弧度
opacity: 0.5
});
Methods
-
clone() → {module:style~TextSymbol}
-
克隆一个新的文本符号。
Example
let newTextSymbol = textSymbol.clone();
-
getBackgroundColor() → {module:style~Color}
-
获取背景填充颜色。
Example
let backgroundColor = textSymbol.getBackgroundColor();
-
getBackgroundImage() → {Image|Promise}
-
获取文字样式背景图片
Returns:
Image | Promise -返回文字背景图片,或者请求该背景图片的Promise
-
getFontColor() → {module:style~Color}
-
获取填充颜色。
Example
let fontColor = textSymbol.getFontColor();
-
getFontFace() → {String}
-
获取字体的字族,比如'宋体'。
Returns:
String -返回字体的字族。
Example
let fontFace = textSymbol.getFontFace();
-
getFontSize() → {Number}
-
获取字体大小。
Returns:
Number -字体大小。
Example
let fontSize = textSymbol.getFontSize();
-
getFontStyle() → {String}
-
获取字体类型eg:斜体。
Returns:
String -字体的类型。
Example
let fontStyle = textSymbol.getFontStyle();
-
getFontWeight() → {String}
-
获取字体粗细。
Returns:
String -字体的粗细。
Example
let fontWeight = textSymbol.getFontWeight();
-
getHaloColor() → {module:style~Color}
-
获取描边颜色。
Example
let haloColor = textSymbol.getHaloColor();
-
getHaloWidth() → {Number}
-
获取描边宽度。
Returns:
Number -文字描边的宽度。
Example
let haloWidth = textSymbol.getHaloWidth();
-
getLineRenderData(options, callback)
-
创建线文字图集,返回纹理坐标,
Parameters:
Name Type Description options
callback
-
getLineRenderData2(options, callback)
-
临时使用 勿删
Parameters:
Name Type Description options
callback
-
getOffset() → {module:basetype~Offset}
-
获取偏移量。
Example
let offset = textSymbol.getOffset();
-
getOpacity() → {Number}
-
获取透明系数。
Returns:
Number -透明系数。
Example
let opacity = textSymbol.getOpacity();
-
getOriginText() → {String}
-
获取原始文本内容。当原始文本太长时,会被截取展示。
Returns:
String -原始文本内容。
Example
let text = textSymbol.getText();
-
getPaddingBottom() → {Number}
-
获取文字的底部内衬宽度
Returns:
Number -文字的底部内衬宽度
-
getPaddingLeft() → {Number}
-
获取文字的左边内衬宽度
Returns:
Number -文字的左边内衬宽度
-
getPaddingRight() → {Number}
-
获取文字的右边内衬宽度
Returns:
Number -文字的右边内衬宽度
-
getPaddingTop() → {Number}
-
获取文字的顶部内衬宽度
Returns:
Number -文字的顶部内衬宽度
-
getRotation() → {Number}
-
获取旋转角度。
Returns:
Number -文字的旋转角度。
Example
let rotation = textSymbol.getRotation();
-
getRowTextCount() → {Number}
-
获取每行文字个数的最大值。
Returns:
Number -每行文字个数的最大值。
Example
let rowTextCount = textSymbol.getRowTextCount();
-
getRowWidth() → {Number}
-
固定文字宽度的模式下,获取每行宽度。
Returns:
Number -每行文字的宽度。
Example
let rowTextCount = textSymbol.getRowWidth();
-
getShadowColor() → {module:style~Color}
-
获取文字样式的阴影颜色
-
getShadowOffset() → {Array.<Number>}
-
获取文字样式的阴影偏移量
Returns:
Array.<Number> -文字样式的阴影偏移量
-
getText() → {String}
-
获取文本内容。
Returns:
String -文本内容。
Example
let text = textSymbol.getText();
-
getTextAlign() → {String} -
已废弃,建议使用getTextAlignment代替。用于获取文本水平排列方式。
Returns:
String -'left'、'center'、'right'三者之一。
Example
let textAlign = textSymbol.getTextAlign();
- Deprecated:
- Yes
-
getTextAlignment() → {String}
-
获取文本水平排列方式。
Returns:
String -'left'、'center'、'right'三者之一。
Example
let textAlignment = textSymbol.getTextAlignment();
-
getTextBaseline() → {String}
-
获取文本基线,即垂直排列的方式。
Returns:
String -’top‘、’bottom‘、’middle‘三者之一。
Example
let textBaseline = textSymbol.getTextBaseline();
-
setBackgroundColor(color) → {module:style~Color}
-
设置背景填充颜色。
Parameters:
Name Type Description color
module:style~Color 背景填充色。
Example
let color = new hmap.style.Color(255,0,0,1); let backgroundColor = textSymbol.setBackgroundColor(color);
-
setBackgroundImage(value)
-
设置文字样式背景图片
Parameters:
Name Type Description value
Image | String 图片,或者图片的url
-
setFontColor(color) → {module:style~Color}
-
设置字体的颜色。
Parameters:
Name Type Description color
module:style~Color 字的填充色。
Throws:
当参数不是Color时,抛出异常:"parameter 'color' must be instance of Color"。
Example
let color = new hmap.style.Color(255,0,0,1); let result = textSymbol.setFontColor(color);
-
setFontFace(fontFace) → {String}
-
设置字体族名称。参数fontFace即css中的fontFamily,但是只支持单个字体族名称,不支持多个字体族组成的列表。
默认值是“Microsoft YaHei”,其他可取的值包括:"arial"、"serif"、"sans-serif"、"monospace"、"fantasy"、"cuisive"、"宋体"、"微软雅黑"、"华文细黑"、"黑体"等。Parameters:
Name Type Description fontFace
String 字体族名称。
Throws:
当参数不是String类型时,抛出异常:"parameter 'fontFace' must be string"。
Returns:
String -返回修改后的字体族名称。
Example
textSymbol.setFontFace("楷体"); let result = textSymbol.getFontFace();//result="楷体"
-
setFontSize(fontSize) → {Number}
-
设置字体大小。最小值为8,最大值为64.
Parameters:
Name Type Description fontSize
Number 字体大小,单位像素。默认是20,最大64。根据一般需求,建议定义13-64之间的整数,8-12会出现渲染模糊的问题。
Returns:
Number -返回修改后的字体大小。
Example
let result = textSymbol.setFontSize(25);
-
setFontStyle(fontStyle) → {String}
-
设置字体样式。默认是“normal”,可取的值包括“normal”、“italic”、“oblique”。
1、normal 默认值。浏览器显示标准的字体样式。
2、italic 浏览器会显示一个斜体的字体样式。
3、oblique 浏览器会显示一个倾斜的字体样式。Parameters:
Name Type Description fontStyle
String 字体样式。
Returns:
String -字体样式。
Example
let fontStyle = textSymbol.setFontStyle("italic");
-
setFontWeight(fontWeight) → {String}
-
设置字体粗细,默认是"normal"。可以传入的值包括:"normal"、"bold"、"bolder",传入其它异常值,会导致不可预估的错误!
Parameters:
Name Type Description fontWeight
String 字体粗细。
Returns:
String -返回修改后的字体粗细。
Example
textSymbol.setFontWeight("bold"); let result = textSymbol.getFontWeight();//result="bold"
-
setHaloColor(color) → {module:style~Color}
-
设置字的描边颜色。
Parameters:
Name Type Description color
module:style~Color 描边颜色。
Throws:
Example
let color = new hmap.style.Color(255,1,1,1); let haloColor = textSymbol.setHaloColor(color);
-
setHaloWidth(width) → {Number}
-
设置描边宽度。
Parameters:
Name Type Description width
Number 大于等于0。
Throws:
传入的参数小于0或者无穷大时,抛出异常:“parameter 'width' must be number”。
Returns:
Number -描边的宽度。
Example
let haloWidth = textSymbol.setHaloWidth(3);
-
setOffset(offset) → {module:basetype~Offset}
-
设置文字的偏移量。
Parameters:
Name Type Description offset
module:basetype~Offset 偏移量。表示文字相对于坐标点的偏移量。
Throws:
当参数不是Offset时,抛出异常:"parameter 'offset' must be instance of Offset"。
Example
let offset = new hmap.basetype.Offset(1,1,0); textSymbol.setOffset(offset); let result = textSymbol.getOffset();//result=new hmap.basetype.Offset(1,1,0)
-
setOpacity(opacity) → {Number}
-
设置文字整体的透明系数。
Parameters:
Name Type Description opacity
Number 透明系数。
Returns:
Number -返回透明系数。
Example
textSymbol.setOpacity(0.5);
-
setRotation(rotation) → {Number}
-
设置旋转角度。
Parameters:
Name Type Description rotation
Number 旋转角度。单位是弧度制。
Throws:
当参数是正、负无穷大时,抛出异常:"parameter 'rotation' must be number"。
Returns:
Number -返回修改后的旋转角度。
Example
textSymbol.setRotation(Math.PI/4); let result = textSymbol.getRotation();//result=Math.PI/4
-
setRowTextCount(rowTextCount) → {Number}
-
设置每行文字个数的上限。
Parameters:
Name Type Description rowTextCount
Number 文字个数的上限。
Returns:
Number -修改后的每行文字个数的上限。
Example
let rowTextCount = textSymbol.setRowTextCount(rowTextCount);
-
setText(text) → {String}
-
设置文本内容。
Parameters:
Name Type Description text
String 文本内容。
Throws:
当参数类型不是String时,抛出异常:"parameter 'text' must be string"。
Returns:
String -返回修改后的文本内容。
Example
textSymbol.setText("江陵路"); let result = textSymbol.getText();//result="江陵路"
-
setTextAlign(textAlign) → {String} -
已废弃,建议使用setTextAlignment代替。用于设置文本水平排列方式,可选项包括'left','right','center'。
Parameters:
Name Type Description textAlign
String 文本水平排列方式。枚举值是:'left','right','center'。
Throws:
当参数不在上述枚举值范围之内时,抛出异常:"parameter 'textAlign' should be left, or right, or center"。
Returns:
String -返回修改后的水平排列方式。
Example
textSymbol.setTextAlign("left"); let result = textSymbol.getTextAlign();//result="left"
- Deprecated:
- Yes
-
setTextAlignment(textAlignment) → {String}
-
设置文本水平排列方式。
Parameters:
Name Type Description textAlignment
String 文本水平排列方式。枚举值是:'left','right','center'。
Throws:
当参数不在上述枚举值范围之内时,抛出异常:"parameter 'textAlignment' should be left, or right, or center"。
Returns:
String -返回修改后的水平排列方式。
Example
textSymbol.setTextAlignment("left"); let result = textSymbol.getTextAlignment();//result="left"
-
setTextBaseline(textBaseline) → {String}
-
设置文本基线。
Parameters:
Name Type Description textBaseline
String 垂直排列方式。枚举值是:"middle" "bottom" "top"。
Throws:
当参数不在上述枚举值范围内时,抛出异常:"parameter 'textBaseline' should be middle, or bottom, or top"。
Returns:
String -返回修改后的垂直排列方式。
Example
textSymbol.setTextBaseline("bottom"); let result = textSymbol.getTextBaseline();//result="bottom"