uni-app?app引入天地圖簡單代碼示例
話不多說代碼來了
<template> <view> <div class="mapBox" style="width: 100%; height: 100vh;background: #ddc0c0;" id="mapId" > </div> </view> </template> <script module="test" lang="renderjs"> var map export default { created() { const charset = 'utf-8' const script = document.createElement('script') script.setAttribute('type','text/javascript') script.setAttribute('charset',charset) script.setAttribute('src','http://api.tianditu.gov.cn/api?v=4.0&tk=xxxxxxxxxxxxxxxxxxxxxxxxxx') document.getElementsByTagName('head')[0].appendChild(script) setTimeout(() => { this.initMap(); }, 500) }, methods: { //初始化地圖 initMap() { const a = new Promise((resolve, reject) => { if (window.T) { console.log('地圖腳本初始化成功...'); resolve(window.T); } }); map = new window.T.Map('mapId'); map.centerAndZoom(new window.T.LngLat( 102.682491, 25.051102), [12]); map.setMapType(window.TMAP_HYBRID_MAP); // 設(shè)置地圖位地星混合圖層 }, } } </script>
重點:
1.module=“test” lang=“renderjs” 必須加上,否則報Error in created hook: "TypeError: Cannot read property ‘createElement’ of undefined,TypeError: Cannot read property ‘createElement’ of undefined錯誤。加上后手機瀏覽器也可以使用,目前沒打包,不知道打包會不會出錯。
2.你天地圖申請的key
目前存在的問題:
1.一根手指頭沒法滑動地圖,需要兩根筷子
2.會出現(xiàn):Uncaught TypeError: Cannot read property ‘x’ of undefined at http://api.tianditu.gov.cn/api?v=4.0&tk=xxxxxxxxxxx
3.等遇到在補充八哈
結(jié)果:
補充一下:數(shù)據(jù)交互有的沒法在兩個之間進(jìn)行,不過可以借助vuex和監(jiān)聽來實現(xiàn)。
總結(jié)
到此這篇關(guān)于uni-app app引入天地圖的文章就介紹到這了,更多相關(guān)uni-app app引入天地圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript基礎(chǔ)知識之方法匯總結(jié)
本文給大家分享了javascript基礎(chǔ)知識,包括數(shù)組的方法,函數(shù)的方法,數(shù)字的方法,對象的方法,字符串的方法,常規(guī)方法,正則表達(dá)式方法,本文介紹的非常詳細(xì),具有參考價值特此分享供大家參考2016-01-01jquery插件bootstrapValidator數(shù)據(jù)驗證詳解
這篇文章主要為大家詳細(xì)介紹了jquery插件bootstrapValidator數(shù)據(jù)驗證使用教程,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11批量下載對路網(wǎng)圖片并生成html的實現(xiàn)方法
下面小編就為大家?guī)硪黄肯螺d對路網(wǎng)圖片并生成html的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考2016-06-06