html,
body,
#container {
width: 100%;
height: 100%;
}
请用鼠标拖拽地图试试
地图拖拽相关事件
绑定事件
解绑事件
//初始化地图对象,加载地图
var map = new AMap.Map("container", {
resizeEnable: true
});
function showInfoDragstart(e){
var text = '开始拖拽地图!'
document.querySelector("#text").innerText = text;
}
function showInfoDragging(e){
var text = '正在拖拽地图!'
document.querySelector("#text").innerText = text;
}
function showInfoDragend(){
var text = '拖拽地图结束!'
document.querySelector("#text").innerText = text;
}
// 事件绑定
function clickOn(){
log.success("绑定事件!");
map.on('dragstart', showInfoDragstart);
map.on('dragging', showInfoDragging);
map.on('dragend', showInfoDragend);
}
// 解绑事件
function clickOff(){
log.success("解除事件绑定!");
map.off('dragstart', showInfoDragstart);
map.off('dragging', showInfoDragging);
map.off('dragend', showInfoDragend);
}
// 给按钮绑定事件
document.getElementById("clickOn").onclick = clickOn;
document.getElementById("clickOff").onclick = clickOff;