最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uni-app?app引入天地圖簡單代碼示例

 更新時間:2024年02月02日 10:44:11   作者:qq_28761593  
uni-app是一種基于Vue.js的跨平臺開發(fā)框架,允許開發(fā)者使用統(tǒng)一的代碼編寫多端應(yīng)用,這篇文章主要給大家介紹了關(guān)于uni-app?app引入天地圖的相關(guān)資料,需要的朋友可以參考下

話不多說代碼來了

<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)文章

最新評論

乌拉特前旗| 克山县| 龙泉市| 西平县| 邛崃市| 板桥市| 张家口市| 连云港市| 威信县| 潞西市| 宁远县| 南乐县| 荆州市| 游戏| 河北区| 桓仁| 达州市| 普定县| 夏津县| 巴彦县| 天峨县| 鄂托克前旗| 民县| 通道| 钟山县| 临夏市| 九江市| 澄江县| 沙湾县| 石台县| 子洲县| 新巴尔虎右旗| 温泉县| 绍兴市| 碌曲县| 沽源县| 明水县| 潜江市| 潮安县| 施秉县| 自贡市|