<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>覆盖物事件</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<style>
html,
body,
#container {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="input-card" style="width:18rem">
<h4>覆盖物拖拽事件的绑定与解绑</h4>
<div>
<div class="input-item">
<button id="clickOn" class="btn" style="margin-right:1rem;" onclick="clickOn()">绑定事件</button>
<button id="clickOff" class="btn">解绑事件</button>
</div>
</div>
</div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
<script type="text/javascript">
var map = new AMap.Map("container", {
resizeEnable: true
});
var marker = new AMap.Marker({
map: map,
icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [116.405467, 39.907761],
draggable: false
});
map.setFitView();
function clickOn () {
alert('绑定事件')
marker.setDraggable(true)
marker.on('dragging', showInfoM);
}
function showInfoM (e) {
console.log(e)
}
</script>
</body>
</html>
|