Summary
Methods:
| clone |
克隆一个新的文本符号。 |
| getBackgroundColor |
获取背景填充颜色。 |
| getFontColor |
获取填充颜色。 |
| getFontFace |
获取字体的字族,比如'宋体'。 |
| getFontSize |
获取字体大小。 |
| getFontStyle |
获取字体类型eg:斜体。 |
| getFontWeight |
获取字体粗细。 |
| getHaloColor |
获取描边颜色。 |
| getHaloWidth |
获取描边宽度。 |
| getOffset |
获取偏移量。 |
| getOpacity |
获取透明系数。 |
| getRotation |
获取旋转角度。 |
| getRowTextCount |
获取每行文字个数的最大值。 |
| getText |
获取文本内容。 |
| getTextAlign |
获取文本水平(左右)排列方式。 |
| getTextBaseline |
获取文本基线,即上下排列的方式。 |
| setBackgroundColor |
设置背景填充颜色。 |
| setFontColor |
设置字体的颜色。 |
| setFontFace |
设置字体族名称。参数fontFace即css中的fontFamily,但是只支持单个字体族名称,不支持多个字体族组成的列表。 |
| setFontSize |
设置字体大小。 |
| setFontStyle |
设置字体样式。默认是“normal”,可取的值包括“normal”、“italic”、“oblique”。 |
| setFontWeight |
设置字体粗细,默认是"normal"。可以传入的值包括:"normal"、"bold"、"bolder",传入其它异常值,会导致不可预估的错误! |
| setHaloColor |
设置字的描边颜色。 |
| setHaloWidth |
设置描边宽度。 |
| setOffset |
设置文字的偏移量。 |
| setOpacity |
设置文字整体的透明系数。 |
| setRotation |
设置旋转角度。 |
| setRowTextCount |
设置每行文字个数的上限。 |
| setText |
设置文本内容。 |
| setTextAlign |
设置文本排列方式。 |
| 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,//旋转角度,单位为度
textAlign: "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(); -
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(); -
getOffset() → {module:basetype~Offset}
-
获取偏移量。
Example
let offset = textSymbol.getOffset(); -
getOpacity() → {Number}
-
获取透明系数。
Returns:
Number -透明系数。
Example
let opacity = textSymbol.getOpacity(); -
getRotation() → {Number}
-
获取旋转角度。
Returns:
Number -文字的旋转角度。
Example
let rotation = textSymbol.getRotation(); -
getRowTextCount() → {Number}
-
获取每行文字个数的最大值。
Returns:
Number -每行文字个数的最大值。
Example
let rowTextCount = textSymbol.getRowTextCount(); -
getText() → {String}
-
获取文本内容。
Returns:
String -文本内容。
Example
let text = textSymbol.getText(); -
getTextAlign() → {String}
-
获取文本水平(左右)排列方式。
Returns:
String -'left'、'center'、'right'三者之一。
Example
let textAlign = textSymbol.getTextAlign(); -
getTextBaseline() → {String}
-
获取文本基线,即上下排列的方式。
Returns:
String -’top‘、’bottom‘、’middle‘三者之一。
Example
let textBaseline = textSymbol.getTextBaseline(); -
setBackgroundColor(color) → {module:style~Color}
-
设置背景填充颜色。
Parameters:
Name Type Description colormodule:style~Color 背景填充色。
Example
let color = new hmap.style.Color(255,0,0,1); let backgroundColor = textSymbol.setBackgroundColor(color); -
setFontColor(color) → {module:style~Color}
-
设置字体的颜色。
Parameters:
Name Type Description colormodule: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 fontFaceString 字体族名称。
Throws:
当参数不是String类型时,抛出异常:"parameter 'fontFace' must be string"。
Returns:
String -返回修改后的字体族名称。
Example
textSymbol.setFontFace("楷体"); let result = textSymbol.getFontFace();//result="楷体" -
setFontSize(fontSize) → {Number}
-
设置字体大小。
Parameters:
Name Type Description fontSizeNumber 字体大小,单位像素。默认是20。理论上支持所有的非负整数,根据一般需求,建议定义13-64之间的整数。
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 fontStyleString 字体样式。
Returns:
String -字体样式。
Example
let fontStyle = textSymbol.setFontStyle("italic"); -
setFontWeight(fontWeight) → {String}
-
设置字体粗细,默认是"normal"。可以传入的值包括:"normal"、"bold"、"bolder",传入其它异常值,会导致不可预估的错误!
Parameters:
Name Type Description fontWeightString 字体粗细。
Returns:
String -返回修改后的字体粗细。
Example
textSymbol.setFontWeight("bold"); let result = textSymbol.getFontWeight();//result="bold" -
setHaloColor(color) → {module:style~Color}
-
设置字的描边颜色。
Parameters:
Name Type Description colormodule: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 widthNumber 大于等于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 offsetmodule: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 opacityNumber 透明系数。
Returns:
Number -返回透明系数。
Example
textSymbol.setOpacity(0.5); -
setRotation(rotation) → {Number}
-
设置旋转角度。
Parameters:
Name Type Description rotationNumber 旋转角度。单位是弧度制。
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 rowTextCountNumber 文字个数的上限。
Returns:
Number -修改后的每行文字个数的上限。
Example
let rowTextCount = textSymbol.setRowTextCount(rowTextCount); -
setText(text) → {String}
-
设置文本内容。
Parameters:
Name Type Description textString 文本内容。
Throws:
当参数类型不是String时,抛出异常:"parameter 'text' must be string"。
Returns:
String -返回修改后的文本内容。
Example
textSymbol.setText("江陵路"); let result = textSymbol.getText();//result="江陵路" -
setTextAlign(textAlign) → {String}
-
设置文本排列方式。
Parameters:
Name Type Description textAlignString 文本横向排列方式。枚举值是:'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" -
setTextBaseline(textBaseline) → {String}
-
设置文本基线。
Parameters:
Name Type Description textBaselineString 纵向排列方式。枚举值是:"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"