Document Maps JavaScript API Reference Manual Point Marker Class Icon

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

Attribute

Type

Description

size

Size | Vector2

 Icon size, default value: [36,36]

imageOffset

Pixel | Vector2

Icon image offset. When a large image is specified in the image, the specified range of the icon can be displayed by coordinating size and imageOffset, equivalent to the backgorund-position property in CSS

image

string

The URL of the icon image (accessible icon URL string). Unless specified otherwise, it defaults to a blue pin image

imageSize

Size | Vector2

The size of the image used for the icon, stretching or compressing the image according to the set size, equivalent to the background-size property in CSS. Can be used to achieve high-definition effects on high-definition screens

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

Parametersize (Size | Vector2Used 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: (arrayValue of icon image size

Demo:

icon.getImageSize();

setSize(size)

Set icon size, default: [36,36]

Parametersize (Size Vector2Used to specify the new size of the icon, such as: new AMap.Size(25, 34) or [25, 34]

Demo:

icon.setSize([20,20]);

getSize()

Get icon size

return value: (arrayIcon size

Demo:

icon.getSize();

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

Parameteroffset (Pixel | Vector2Used 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: (arrayIcon 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)

Parameterimage (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

Parametersize (Size Vector2Original size

Demo:

icon.setOriginSize(new AMap.Size(25, 34));

getOriginSize()

Get original size

return value: (anyOriginal size

Demo:

icon.getOriginSize()