低代码平台-宜搭 如何调用高德平台API地图

高德地图API作为第三方API在宜搭中不能直接调用,需要使用引用语句引入第三方JSAPI

简单的来说我们在引入第三方API后,需要在页面加载动作中去调用此方法,然后展示到HTML组件中.

调用详情见JS代码:

export function didMount() {
 
  
   
  this.loadAssets();
   
   

  
}
export function loadScript(src, callback) {
  if (!src) {
    return;
  }
  const node = document.createElement('script');
  node.crossOrigin = 'crossOrigin';
  node.src = src;
  node.addEventListener('load', callback, false);
  document.head.appendChild(node);
}

export function loadAssets() {
  this.loadScript('https://webapi.amap.com/loader.js', () => {
    // your code 
    AMapLoader.load({ //首次调用 load
      key: 'xxxxxxx',//首次load key为必填
      version: '2.0',
      plugins: ['AMap.Scale', 'AMap.ToolBar']
    }).then((AMap) => {
     var map = new AMap.Map('container');
      map.addControl(new AMap.Scale())
      map.addControl(new AMap.ToolBar())
      map.add(new AMap.Marker({
        position: map.getCenter()
      }));
    }).catch((e) => {
      console.error(e);
    });
  });
}

HTML代码:

<html lang="en">

<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>AMap JSAPI Loader</title>
	<style type="text/css">
		body,
		html,
		#container {
			width: 100%;
			height: 500px;
			margin: 0px
		}
	</style>
</head>
<body>
<div id="container" tabindex="0">
	
</div>
</body>
	</html>

最后请大家查看展示效果:

 

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值