Drag box zoom
This article describes how to use the AMap.MouseTool mouse tool plugin to achieve zoom-in/zoom-out operations after selecting a map area, thereby achieving the effect of regional zoom.
Example of mouse drag box zoom
1、Drag box zoom AMap.MouseTool
1
1.1 Create a map
const map = new AMap.Map("container", {
zoom: 10,
showOversea: true, //Enable world Map
mapStyle: "amap://styles/whitesmoke",
viewMode: "2D",
});2
1.2 Create a MouseTool instance
This example uses asynchronous plugin installation. Introduce plugins as needed through the AMap.plugin method, and use plugin functions after the plugin callback. Plugin introduction method Plugin usage.
AMap.plugin("AMap.MouseTool", function () {
var mouseTool = new AMap.MouseTool(map); //Create an instance of the mouse tool plugin
});3
1.3 Zoom in
//Use plugin functions in the callback function
mouseTool.rectZoomIn({
strokeColor: "#80d8ff",
fillColor: "#80d8ff",
fillOpacity: 0.3,
//Same as the Option Settings of Polygon
});4
1.4 Zoom Out
//Using Plugin Functions in Callback Functions
mouseTool.rectZoomOut({
strokeColor: "#80d8ff",
fillColor: "#80d8ff",
fillOpacity: 0.3,
//Same as the Option Settings of Polygon
});5
1.5 Close Box Zoom
//Using Plugin Functions in Callback Functions
mouseTool.close();Prompt
The mouseTool.close(ifClear) method is used to close the mouse tool. The ifClear parameter is optional (default is false). When set to true, it closes the tool and clears all overlay objects edited and drawn by the mouse tool on the map; when set to false, it only closes the tool and retains the overlays.