首先自定義兩個按鈕,用於創建點擊事件
<span class="tool-small" id="btn_small"><span>縮小</span></span> <span class="tool-big" id="btn_big"><span>放大</span></span>
然后就是對事件的書寫
注意,在使用放大縮小工具前需要引入Zoom類
import Zoom from "@arcgis/core/widgets/Zoom";
// 自定義放大縮小按鈕********************************************************************** mapView.ui.remove("zoom"); //清除默認的放大縮小按鈕 var zoom = new Zoom({ view: mapView, }); // 放大 const btn_big = document.getElementById("btn_big"); btn_big.addEventListener("click", function () { click_big(); }); function click_big() { // alert("big"); zoom.zoomIn(); } // 縮小 const btn_small = document.getElementById("btn_small"); btn_small.addEventListener("click",function(){ click_small(); }); function click_small(){ zoom.zoomOut(); } // 放大縮小功能結束*********************************************************************