ElasticMarker
AMap.ElasticMarker
Flexible point marker, a type of point marker that can change its icon and size with the map level. Construct a flexible point marker object, and set the properties of the flexible point marker object through ElasticMarkerOptions
new AMap.ElasticMarker(opts: ElasticMarkerOptions);Parameter
opts(ElasticMarkerOptions): Flexible point marker parameters
Demo
var map = new AMap.Map("container", {
zoom: 10, //Map level
center: [116.397428, 39.90923],
});
var stylesArray = [
{
icon: {
//Icon style
img: "https://a.amap.com/jsapi_demos/static/resource/img/men3.png",
size: [16, 16], //Original size of the icon
anchor: "bottom-center", //Anchor position
fitZoom: 14, //The most suitable level where the icon is displayed at its original size
scaleFactor: 2, //The zoom scale factor for one level of map zoom-in
maxScale: 2, //The maximum zoom-in scale of the image, the icon will zoom in as the map zooms in, with a maximum of 2
minScale: 1, //The minimum zoom-out scale of the image, the icon will zoom out as the map zooms out, with a minimum of 1
},
label: {
//Text Annotation
content: "百花殿", //Text content
position: "BM", //The reference point of the text position relative to the icon,"BM" stands for bottom center
minZoom: 15, //The minimum display level for the label, meaning the text annotation will only appear on the map at level 15 and above
},
},
{
icon: {
img: "https://a.amap.com/jsapi_demos/static/resource/img/tingzi.png",
size: [48, 63],
anchor: "bottom-center",
fitZoom: 17.5,
scaleFactor: 2,
maxScale: 2,
minScale: 0.125,
},
label: {
content: "万寿亭",
position: "BM",
minZoom: 15,
},
},
];
var zoomStyleMapping = {
14: 0, //Use style 0 for levels 14-17
15: 0,
16: 0,
17: 0,
18: 1, //Use style 1 for levels 18-20
19: 1,
20: 1,
};
AMap.plugin(["AMap.ElasticMarker"], function () {
var elasticMarker = new AMap.ElasticMarker({
position: [116.405562, 39.881166], //Point marker location
styles: stylesArray, //Specify the style list
zoomStyleMapping: zoomStyleMapping, //Specify the mapping of zoom and styles
});
map.add(elasticMarker); //Add to the map
map.setFitView(); //Zoom the map to an appropriate view level
});Method
getTitle()
Get the text prompt for the flexible point marker
return value: (string) Text tooltip set by the title attribute, returns an empty string if not set
Demo:
elasticMarker.getTitle();setTitle(title)
Set the text tooltip when the mouse hovers over the flexible point marker
Parameter: title(string) Text tooltip of the flexible point marker
Demo:
elasticMarker.setTitle("Text tooltip");getClickable()
Get whether the flexible point marker supports mouse click events
return value: (boolean) Boolean value
Demo:
elasticMarker.getClickable();getMap()
Get the map instance of the overlay
return value: (Map | null) If the overlay has been added to the map, return the map instance where the overlay is located. If the overlay has not been added, has been removed, or does not exist on any map, return null
Demo:
elasticMarker.getMap();setMap(map)
Set the overlay to the map
Parameter: map(Map | null) It can be a Map object or null. If it is a Map object, the overlay will be added to this map. If it is null or omitted, the overlay will be removed from the current map
Demo:
elasticMarker.setMap(map);show()
Show the overlay
Demo:
elasticMarker.show();hide()
Hide the overlay
Demo:
elasticMarker.hide();getPosition()
Get the position of the flexible point
return value: (object) Location information of the overlay
Demo:
elasticMarker.getPosition();setPosition(position)
Set the position of the flexible point
Parameter: position(Vector2 | LngLat) Supports passing in a latitude-longitude object or a one-dimensional array composed of latitude and longitude
Demo:
elasticMarker.setPosition([116.397428, 39.90923]);setAnchor(anchor)
Set flexible marker anchor, options: 'top-left'|'top-center'|'top-right'|'middle-left'|'center'|'middle-right'|'bottom-left'|'bottom-center'|'bottom-right'
Parameter: anchor(string) Specify the anchor position of the overlay
Demo:
elasticMarker.setAnchor('center');getzIndex()
Get the stacking order of overlays
return value: (number | undefined) Overlay stacking order
Demo:
elasticMarker.getzIndex()setzIndex(zIndex)
Set the overlay order
Parameter: zIndex(number) Set overlay order
Demo:
elasticMarker.setzIndex(99);getOptions()
Get all properties of the overlay
return value: (OverlayOptions) Object containing all configuration properties of the overlay
Demo:
elasticMarker.getOptions()getBounds()
Get flexible point marker range
return value: (Bounds) Flexible point marker position range
Demo:
elasticMarker.getBounds()setClickable(clickable)
Set whether the flexible point marker supports mouse click events
Parameter: clickable(boolean) The clickable parameter is optional (default is true), when set to false, the flexible point marker does not support mouse click events
Demo:
elasticMarker.setClickable(true);getDraggable()
Get whether the flexible point marker object is draggable
return value: (boolean) Boolean value
Demo:
elasticMarker.getDraggable();setDraggable(draggable)
Set whether the flexible point marker object is draggable
Parameter: draggable(boolean) The draggable parameter is optional (default is false). When set to true, the flexible marker object can be dragged
Demo:
elasticMarker.setDraggable(true);getTop()
Get whether the flexible marker is brought to the top
return value: (boolean) Boolean value
Demo:
elasticMarker.getTop();setTop(isTop)
When there are multiple markers on the map, set whether to bring the flexible marker to the top
Parameter: isTop(boolean) The isTop parameter is optional (default is false). When set to true, it will bring the flexible marker to the top when there are multiple flexible markers on the map
Demo:
elasticMarker.setTop(true);getCursor()
Get the cursor settings when the mouse hovers
return value: (string) The currently set cursor type
Demo:
elasticMarker.getCursor();setCursor(cursor)
Set the cursor when the mouse hovers
Parameter:
cursor(string) A string specifying the cursor style, the custom style should comply with the CSS cursor property specification. IE only supports cur/ani/ico formats, Opera does not support custom cursors
Demo:
elasticMarker.setCursor("crosshair");getExtData()
Get user-defined data
return value: (any | undefined) The value set by the extData property, returns an empty object if not set
Demo:
elasticMarker.getExtData();setExtData(extData)
Set User-defined Data
Parameter: extData(any) User-defined data, supporting any data type in JavaScript API
Demo:
elasticMarker.setExtData({id:1});remove()
Remove Point Marker
Demo:
elasticMarker.remove();Event
For event object property descriptions, go to:MapsEvent