style~Icon(options)

图标符号。

Summary

Methods:
clone

克隆一个Icon对象。

getAnchor

获取锚点在图标上的位置,用比例值表示。

getImgSrc

获取图标的图片地址。

getOffset

获取符号的偏移量。

getOpacity

获取符号的透明度。

getRotateWithView

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

getRotation

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

getSize

获取符号的像素大小。

setAnchor

设置图标符号的锚点。

setImgSrc

设置图标的图片地址。

setOffset

设置符号的偏移量。

setOpacity

设置透明度。

setRotation

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

setSize

设置图标符号的大小。

Constructor

new Icon(options)

构造函数

Parameters:
Name Type Description
options JSON

图标符号的可选项参数。

Name Type Description
imgSrc String

图标的图片路径。

size module:basetype~Size

符号大小。默认值为32,单位为像素。图标宽高比例不变,取options.size的第一个值,对图标宽高中的最大边进行设置。

anchor Array

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

sprite Boolean

增加 图标是否来自雪碧图,默认为false。eg:当矢量图层使用雪碧图时,并且图标符号来自该雪碧图,该参数需要设置为true。

Example
let icon = new hmap.style.Icon({
        "color":new hmap.style.Color(0.0,0.0,0.0,0.0),
        "imgSrc":"https://www.hikvision.com/cn/images/logo.png",
        "size":new hmap.basetype.Size(32, 32),
        "anchor":[0.5,0.5],
        "offset":new hmap.basetype.Offset(0,0,0),
        "rotation":0
});

Methods

clone() → {module:style~Icon}

克隆一个Icon对象。

Returns:
module:style~Icon -

克隆后的图标对象。

Example
let newIcon = icon.clone();

getAnchor() → {Array}

获取锚点在图标上的位置,用比例值表示。

Returns:
Array -

比例值

Example
let anchor = icon.getAnchor();

getImgSrc() → {String}

获取图标的图片地址。

Returns:
String -

图片地址

Example
let imgSrc = icon.getImgSrc();

getOffset() → {module:basetype~Offset}

获取符号的偏移量。

Returns:
module:basetype~Offset -

偏移量

getOpacity() → {Number}

获取符号的透明度。

Returns:
Number -

透明度

getRotateWithView() → {Boolean}

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

Returns:
Boolean -

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

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

getRotation() → {Number}

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

Returns:
Number -

旋转角度

getSize() → {module:basetype~Size}

获取符号的像素大小。

Returns:
module:basetype~Size -

像素大小

Example
let size = icon.getSize();

setAnchor(anchor)

设置图标符号的锚点。

Parameters:
Name Type Description
anchor Array

锚点

Throws:

当参数不是数组,或者数组长度小于2时,抛出异常:"the anchor should be Array with a length of at least 2."。

Example
icon.setAnchor([0.5,0.5]);//锚点在图标的正中心
icon.setAnchor([0,0]);//锚点在图标的左上角
icon.setAnchor([0.5,1]);//锚点在图标的下边线的中心
icon.setAnchor([0.5,0]);//锚点在图标的上边线的中心
icon.setAnchor([1,0.5]);//锚点在图标的右边线的中心
icon.setAnchor([0,0.5]);//锚点在图标的左边线中心

setImgSrc(imgSrc)

设置图标的图片地址。

Parameters:
Name Type Description
imgSrc String

图片请求路径

Example
icon.setImgSrc("https://www.hikvision.com/cn/images/logo.png");

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]”。

setRotation(rotation)

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

Parameters:
Name Type Description
rotation Number

旋转角度

setSize(size)

设置图标符号的大小。

Parameters:
Name Type Description
size module:basetype~Size

符号的大小。为保持图标宽高比例不变,只取size对象的第一个值进行符号大小的设置。

Example
icon.setSize(new hmap.basetype.Size(12,12));