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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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
Parameter: opts (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.
Parameter: ifClear (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