Document Maps JavaScript API Reference Manual Tool Category MouseTool

MouseTool

AMap.MouseTool

Mouse tool plugin. Through this plugin, you can perform functions such as drawing markers, lines, polygons, rectangles, circles, distance measurement, area measurement, zoom in by rectangle, zoom out by rectangle, etc. Construct a mouse tool plugin object

new AMap.MouseTool(map: Map)

Parameter

map (Map): Map instance to which the mouse tool is added

Demo

map.plugin(["AMap.MouseTool"],function(){
  var mousetool = new AMap.MouseTool(map);
  // Use mouse tool to draw markers on the map
  mousetool.marker();
});

Method

marker(opts)

Enable mouse point annotation mode. Click on the map to draw point annotations, annotation style refers to MarkerOptions settings

Parameteropts (MarkerOptions) Style, optional, default style will be used when omitted

Demo:

mousetool.marker();

circle(opts)

Enable the mouse circle drawing mode. Drag on the map to draw a circle. The circle style refers to the CircleOptions settings

Parameteropts (CircleOptions) Style, optional, default style is used when omitted

Demo:

mousetool.circle({
  fillColor: "#fff", 
});

rectangle(opts)

Enable the mouse rectangle drawing mode. Drag on the map to draw a rectangle. The rectangle style refers to the RectangleOptions settings

Parameteropts (PolygonOptions) Style, optional, default style is used when omitted

Demo:

mousetool.rectangle();

polyline(opts)

Enable the mouse polyline drawing mode. Click on the map to draw a polyline, double-click the left mouse button or right-click to end the drawing. The polyline style refers to the PolylineOptions settings

Parameteropts (PolylineOptions) Style, optional, default style is used when omitted

Demo:

mousetool.polyline();

polygon(opts)

Enable the mouse polygon drawing mode. Click on the map to start drawing a polygon, double-click the left mouse button or right-click to end the current polygon drawing. The polygon style refers to the PolygonOptions settings

Parameteropts (PolygonOptions) Style, optional, default style is used when omitted

Demo:

mousetool.polygon();

measureArea(opts)

Enable the area measurement mode. Click on the map to draw a measurement area, double-click the left mouse button or right-click to end the current measurement operation, and display the measurement result. The measurement area style refers to the PolygonOptions settings

Parameteropts (PolygonOptions) Style, optional, default style is used when omitted

Demo:

mousetool.measureArea();

rule(opts)

Enable the distance measurement mode. Click on the map to draw measurement nodes, and calculate and display the distance between each pair of nodes. Double-click the left mouse button or right-click to end the current measurement operation. The measurement line style refers to the PolylineOptions settings. Note: The rule method and RangTool plugin cannot be used simultaneously for distance measurement

Parameteropts (PolylineOptions) Style, optional, default style is used when omitted

Demo:

mousetool.rule();

rectZoomIn(opts)

Enable the mouse drag-to-zoom-in mode. The mouse can drag a box on the map to zoom in. The rectangle box style refers to the PolygonOptions settings

Parameteropts (PolygonOptions) Style, optional, default style is used when omitted

Demo:

mousetool.rectZoomIn();

rectZoomOut(opts)

Enable the mouse drag-to-zoom-out mode. The mouse can drag a box on the map to zoom out. The rectangle box style refers to the PolygonOptions settings

Parameteropts (PolygonOptions) Style, optional, default style is used when omitted

Demo:

mousetool.rectZoomOut();

close(ifClear)

Close the current mouse operation. When set to true, it closes the tool and removes all overlay objects edited and drawn by the mouse tool on the map; when set to false, it only closes the tool, keeping the overlays. The default is false.

ParameterifClear (boolean) Whether to clear overlays on the map

Demo:

mousetool.close(true);

Event

draw

This event is triggered when the mouse tool finishes drawing an overlay, with the obj being the overlay object drawn.

Parameter: event (Object) Event Callback Parameters

Attribute

Type

Description

type

string

Event Type

obj

string

Drawn overlay object