Icon
AMap.Icon
The icon for a point marker, used to add complex markers by adding an Icon class based on a regular point marker. A portion of the large image represented by the Icon is cropped and used as the annotated icon to construct a point overlay icon. The icon properties are set via IconOptions. Construct a point marker icon object, and set the icon properties via IconOpts
new AMap.Icon(opts: IconOpts)Parameter
opts(IconOpts): Marker icon parameters
Demo
const icon = new AMap.Icon({
size: new AMap.Size(25, 34), //Icon size
image: "//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png", //The image of the Icon
imageOffset: new AMap.Pixel(-9, -3), //The offset of the image relative to the display area, suitable for sprite maps, etc
imageSize: new AMap.Size(135, 40), //Stretch or compress the image according to the set size
});Method
setImageSize(size)
Set icon image size
Parameter: size (Size | Vector2) Used to specify the new size of the icon image, such as: new AMap.Size(135, 40) or [135, 40]
Demo:
icon.setImageSize([135, 40]);getImageSize()
Get icon image size
return value: (array) Value of icon image size
Demo:
icon.getImageSize();setSize(size)
Set icon size, default: [36,36]
Parameter: size (Size | Vector2) Used to specify the new size of the icon, such as: new AMap.Size(25, 34) or [25, 34]
Demo:
icon.setSize([20,20]);setImageOffset(offset)
Set the offset of the icon image. When a large image is specified in the image, the specified range of the icon can be displayed by using size and imageOffset
Parameter: offset (Pixel | Vector2) Used to specify the offset of the icon image, such as: new AMap.Pixel(10, 10) or [10,10]
Demo:
icon.setImageOffset([10,10]);getImageOffset()
Get the icon image offset. When a large image is specified in 'image', the specified range of the icon can be displayed by combining 'size' and 'imageOffset
return value: (array) Icon image offset
Demo:
icon.getImageOffset();getImage()
Get the icon's image URL (accessible icon URL string)
return value: (string) Icon image URL string
Demo:
icon.getImage();setImage(image)
Set the image URL of the icon (an accessible icon URL string)
Parameter: image (string) Accessible icon URL string
Demo:
icon.setImage("//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png");setOriginSize(size)
Set original size
Parameter: size (Size | Vector2) Original size
Demo:
icon.setOriginSize(new AMap.Size(25, 34));getOriginSize()
Get original size
return value: (any) Original size
Demo:
icon.getOriginSize()