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 | 图标符号的可选项参数。
|
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对象。
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}
-
获取符号的偏移量。
-
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}
-
获取符号的像素大小。
Example
let size = icon.getSize(); -
setAnchor(anchor)
-
设置图标符号的锚点。
Parameters:
Name Type Description anchorArray 锚点
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 imgSrcString 图片请求路径
Example
icon.setImgSrc("https://www.hikvision.com/cn/images/logo.png"); -
setOffset(offset)
-
设置符号的偏移量。
Parameters:
Name Type Description offsetmodule:basetype~Offset 偏移量
Throws:
当参数不是Offset对象时,抛出异常:"The parameter must be a Offset"。
-
setOpacity(opacity)
-
设置透明度。
Parameters:
Name Type Description opacityNumber 透明度,透明度的范围是[0,1]。
Throws:
当参数的值不在0到1之间时,抛出异常:“The extent of the parameter 'opacity' is [0,1]”。
-
setRotation(rotation)
-
设置旋转角度。单位是角度制。
Parameters:
Name Type Description rotationNumber 旋转角度
-
setSize(size)
-
设置图标符号的大小。
Parameters:
Name Type Description sizemodule:basetype~Size 符号的大小。为保持图标宽高比例不变,只取size对象的第一个值进行符号大小的设置。
Example
icon.setSize(new hmap.basetype.Size(12,12));