- 积分
 - 3625
 
	- 贡献
 -  
 
	- 精华
 
	- 在线时间
 -  小时
 
	- 注册时间
 - 2014-10-21
 
	- 最后登录
 - 1970-1-1
 
 
 
 
 
 
 | 
	
 
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册 
 
 
 
x
 
高德地图调用与交互跟一般GUI是一样的,先做按钮、然后调接口的函数,绑定函数到组件,OK 
 
 
<!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"> 
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" /> 
    <title>新建地图</title> 
    <style> 
        html, 
        body, 
        #container { 
          width: 100%; 
          height: 100%; 
        } 
    </style> 
</head> 
 
<body> 
<div id="container"></div> 
<!--组件/控件--> 
<div class="input-card" style="width:16rem"> 
<h4>新建、销毁地图</h4> 
<div id="btns"> 
<div class="input-item"> 
<!--按钮--> 
<button id="create-btn" class="btn" style="margin-right:1rem;">新建地图</button> 
<button id="destroy-btn" class="btn">销毁地图</button> 
</div></div></div> 
 
<!--初始化地图需要:--> 
<script 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> 
var map=null; 
//新建地图函数: 
function createMap(){ 
map = new AMap.Map('container', { 
        resizeEnable: true, //是否监控地图容器尺寸变化 
        zoom:11, //初始化地图层级 
        center: [116.397428, 39.90923] //初始化地图中心点 
    }); 
        log.success("地图加载完成!"); 
} 
//销毁地图函数: 
function destroyMap(){ 
map && map.destroy(); 
log.info("地图已销毁"); 
} 
 
 
//初始化地图: 
createMap(); 
 
//事件绑定给按钮: 
document.querySelector("#create-btn").onclick=createMap 
document.querySelector("#destroy-btn").onclick=destroyMap 
 
</script> 
</body> 
</html> 
 
 |   
 
 
 
 |