style~IconFont(options)

自定义字体图标类。

Summary

Methods:
clone

克隆一个字体图标符号。

getAnchor

获取锚点的位置。

getFileUrl

获取自定义字体图标的文件地址

getFillColor

获取填充色

getFontFamily

获取字体图标的字体样式

getFontSize

获取字体图标的大小。

getOutlineColor

获取描边颜色

getOutlineWidth

获取描边的宽度

getUnicode

获取unicode

setAnchor

设置锚点位置。

setFileUrl

设置字体图标文件的路径。

setFillColor

设置填充色

setFontSize

设置字体图标的大小。

setOutlineColor

设置描边色

setOutlineWidth

设置描边宽

setUnicode

设置unicode编码

Constructor

new IconFont(options)

Iconfont的构造函数。 options参数中:fileUrl、unicode是必需的。其他属性是可选项。

Parameters:
Name Type Description
options Object
Name Type Description
fileUrl String

字体文件(.ttf)的路径。

unicode String

字体图标的唯一标识,该标识需要是传入的ttf文件中存在的标识。

fontSize Number

字体图标符号的大小。

size module:basetype~Size

符号尺寸,该属性不作为IconFont自身属性且和不影响渲染效果,只是为提供更准确的拾取服务,默认值为new Size(options.fontSize,options.fontSize)

fillColor module:style~Color

字体图标的填充颜色,默认为白色,完全透明。

outlineColor module:style~Color

字体图标的描边颜色,默认为黑色。

outlineWidth Number

字体图标的描边宽度,默认值为1,单位是像素。

anchor Array.<Number>

锚点位置。eg:默认将锚点定为字体图标的中心点,即[0.5,0.5]。字体图标的左上角为[0,0],右下角为[1,1]。单位为1。

Throws:

当字体图标参数填充颜色fillColor或者描边颜色outlineColor不是Color类型时,抛出异常:'IconFont-constructor:parameter "fillColor" and "outlineColor" must be instance of Color'。

Example
let iconFont = new hmap.style.IconFont({
   "unicode":"&#61492;",//unicode编码
   "fileUrl":"./mapicon.ttf",//ttf文件的加载路径
   "opacity":1.0,//整个iconfont图标的透明度
   "anchor":[0,0],//偏移量,单位分数
   "fontSize":16,//大小
   "fillColor":new hmap.style.Color(255,255,255,0),//填充色
   "outlineColor":new hmap.style.Color(0,0,0,1),//外边框颜色
   "outlineWidth":1,//外边框宽度
   "rotation":0
});

Methods

clone() → {module:style~IconFont}

克隆一个字体图标符号。

Example
let newIconFont = iconFont.clone();

getAnchor() → {Array}

获取锚点的位置。

Returns:
Array -

锚点的位置

Example
let anchor = iconFont.getAnchor();

getFileUrl() → {String}

获取自定义字体图标的文件地址

Returns:
String -

自定义字体图标的文件地址

Example
let fileUrl = iconFont.getFileUrl();

getFillColor() → {module:style~Color}

获取填充色

Returns:
module:style~Color -

字体填充颜色

Example
let fillColor = iconFont.getFillColor();

getFontFamily() → {String}

获取字体图标的字体样式

Returns:
String -

字体样式

Example
let fontFamily = iconFont.getFontFamily();

getFontSize() → {Number}

获取字体图标的大小。

Returns:
Number
Example
let size = iconFont.getFontSize();

getOutlineColor() → {module:style~Color}

获取描边颜色

Returns:
module:style~Color -

字体描边颜色

Example
let outLineColor = iconFont.getOutlineColor();

getOutlineWidth() → {Number}

获取描边的宽度

Returns:
Number -

字体描边宽度

Example
let outLineWidth = iconFont.getOutlineWidth();

getUnicode() → {String}

获取unicode

Returns:
String -

字体unicode

Example
let unicode = iconFont.getUnicode();

setAnchor(anchor)

设置锚点位置。

Parameters:
Name Type Description
anchor Array

锚点位置,分数值。eg:默认将锚点定为字体图标的中心点,即[0.5,0.5]。字体图标的左上角为[0,0],右下角为[1,1]。单位为1。

Example
iconFont.setAnchor([0.1,0.1]);

setFileUrl(fileUrl)

设置字体图标文件的路径。

Parameters:
Name Type Description
fileUrl String

字体图标文件的路径

Example
iconFont.setFileUrl("./mapicon.ttf");

setFillColor(fillColor)

设置填充色

Parameters:
Name Type Description
fillColor module:style~Color

填充色

Throws:

当参数不是Color类型时,抛出异常:'IconFont-setFillColor:parameter "fillColor" must be instance of Color'。

Example
let fillColor = new hmap.style.Color(255,2,2,1);
iconFont.setFillColor(fillColor);

setFontSize(fontSize)

设置字体图标的大小。

Parameters:
Name Type Description
fontSize Number

字体图标大小

Example
iconFont.setFontSize(20);

setOutlineColor(outlineColor)

设置描边色

Parameters:
Name Type Description
outlineColor module:style~Color

描边色

Throws:

当参数不是Color类型时,抛出异常:'IconFont-setOutlineColor:parameter "outlineColor" must be instance of Color'。

Example
let color = new hmap.style.Color(2,255,2,1);
iconFont.setOutlineColor(color);

setOutlineWidth(outlineWidth) → {Boolean}

设置描边宽

Parameters:
Name Type Description
outlineWidth Number

描边宽

Returns:
Boolean -

设置是否有效

Example
iconFont.setOutlineWidth(2);

setUnicode(unicode) → {Boolean}

设置unicode编码

Parameters:
Name Type Description
unicode String

unicode编码

Returns:
Boolean -

设置是否有效

Example
iconFont.setUnicode("&#61489;");