style~IconFont(options)

自定义字体图标类。

Summary

Methods:
clone

克隆一个字体图标符号。

getAnchor

获取锚点的位置。

getFileUrl

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

getFillColor

获取填充色

getFontFamily

获取字体图标的字体样式

getFontSize

获取字体图标的大小。

getOffset

获取符号的偏移量。

getOpacity

获取符号的透明度。

getOutlineColor

获取描边颜色

getOutlineWidth

获取描边的宽度

getRotateWithView

获得符号是否跟着地图旋转。

getRotation

获取符号的旋转角度。单位是角度制。

getUnicode

获取unicode

setAnchor

设置锚点位置。

setFileUrl

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

setFillColor

设置填充色

setFontSize

设置字体图标的大小。

setOffset

设置符号的偏移量。

setOpacity

设置透明度。

setOutlineColor

设置描边色

setOutlineWidth

设置描边宽

setRotation

设置旋转角度。单位是角度制。

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类型时,抛出异常:'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}

获取填充色

Example
let fillColor = iconFont.getFillColor();

getFontFamily() → {String}

获取字体图标的字体样式

Returns:
String -

字体样式

Example
let fontFamily = iconFont.getFontFamily();

getFontSize() → {Number}

获取字体图标的大小。

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

getOffset() → {module:basetype~Offset}

获取符号的偏移量。

Returns:
module:basetype~Offset -

偏移量

getOpacity() → {Number}

获取符号的透明度。

Returns:
Number -

透明度

getOutlineColor() → {module:style~Color}

获取描边颜色

Example
let outLineColor = iconFont.getOutlineColor();

getOutlineWidth() → {Number}

获取描边的宽度

Returns:
Number
Example
let outLineWidth = iconFont.getOutlineWidth();

getRotateWithView() → {Boolean}

获得符号是否跟着地图旋转。

Returns:
Boolean -

如果旋转返回true;如果不旋转,返回false。

Example
let iconSymbol = new hmap.style.Icon();
let result = iconSymbol.getRotateWithView();//result=false

getRotation() → {Number}

获取符号的旋转角度。单位是角度制。

Returns:
Number -

旋转角度

getUnicode() → {String}

获取unicode

Returns:
String
Example
let unicode = iconFont.getUnicode();

setAnchor(anchor)

设置锚点位置。

Parameters:
Name Type Description
anchor Array
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类型时,抛出异常:'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);

setOffset(offset)

设置符号的偏移量。

Parameters:
Name Type Description
offset module:basetype~Offset

偏移量

Throws:

当参数不是Offset对象时,抛出异常:"The parameter must be a Offset"。

setOpacity(opacity)

设置透明度。

Parameters:
Name Type Description
opacity Number

透明度,透明度的范围是[0,1]。

Throws:

当参数的值不在0到1之间时,抛出异常:“The extent of the parameter 'opacity' is [0,1]”。

setOutlineColor(outlineColor)

设置描边色

Parameters:
Name Type Description
outlineColor module:style~Color

描边色

Throws:

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

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

setOutlineWidth(outlineWidth)

设置描边宽

Parameters:
Name Type Description
outlineWidth Number

描边宽

Example
iconFont.setOutlineWidth(2);

setRotation(rotation)

设置旋转角度。单位是角度制。

Parameters:
Name Type Description
rotation Number

旋转角度

setUnicode(unicode)

设置unicode编码

Parameters:
Name Type Description
unicode String
Example
iconFont.setUnicode("&#61489;");