覆盖物状态改变时触发的事件
mousemove mouseover mouseout
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>map</title> <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=ce3b1a3a7e67fc75810ce1ba1f83c01a"></script> <style> *{margin:0;padding:0;list-style: none;} #container {width:100%; height: 100%;top:0;left:0;position: absolute; } #panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;} </style> </head> <body> <div id="container"></div> <div id="panel"></div> <script> var map=new AMap.Map("container",{ zoom:11, center:[121.549792,29.868388], resizeEnable:true//不开启则无法触发resize事件 }); var txt=new AMap.Text({ text:"覆盖物事件", position:[121.549792,29.868388] }).on("mouseover",function(){ console.log("覆盖物移入"); }).on("mouseout",function(){ console.log("覆盖物移出"); }).on("mousemove",function(){ console.log("覆盖物上移动中"); }) txt.setMap(map); </script> </body> </html>
show hide
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>map</title> <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=ce3b1a3a7e67fc75810ce1ba1f83c01a"></script> <style> *{margin:0;padding:0;list-style: none;} #container {width:100%; height: 100%;top:0;left:0;position: absolute; } #panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;} </style> </head> <body> <div id="container"></div> <div id="panel"></div> <script> var map=new AMap.Map("container",{ zoom:11, center:[121.549792,29.868388], resizeEnable:true//不开启则无法触发resize事件 }); //矢量图--圆 var circle=new AMap.Circle({ center:[121.549792,29.868388], radius:1000 }) circle.setMap(map); //矢量图--方 var rect=new AMap.Rectangle({ bounds:new AMap.Bounds(new AMap.LngLat(121.549792,29.868388),new AMap.LngLat(121.569792,29.848388)) }) rect.setMap(map); setTimeout(function(){ circle.hide(); },2000) setTimeout(function(){ rect.hide(); },4000) setTimeout(function(){ circle.show(); },6000) setTimeout(function(){ rect.show(); },8000) </script> </body> </html>
open() close()
ContextMenu指的是右键
map.zoomIn() map.zoomOut()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>map</title> <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=ce3b1a3a7e67fc75810ce1ba1f83c01a"></script> <style> *{margin:0;padding:0;list-style: none;} #container {width:100%; height: 100%;top:0;left:0;position: absolute; } #panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;} </style> </head> <body> <div id="container"></div> <div id="panel"></div> <script> var map=new AMap.Map("container",{ zoom:11, center:[121.549792,29.868388], resizeEnable:true//不开启则无法触发resize事件 }); var cm=new AMap.ContextMenu(); cm.addItem("放大一级",function(){ map.zoomIn();//放大一级map的级别 },0) cm.addItem("缩小一级",function(){ map.zoomOut();//缩小一级map的级别 },1) map.on("rightclick",function(e){ console.log(e.lnglat); cm.open(map,e.lnglat); //右键3秒后关闭 setTimeout(function(){ cm.close(); },3000) }) </script> </body> </html>