第一步:创建 map.html文件
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>百度地图</title>
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0px;
padding: 0px
}
#mapPage {
height: 100%;
position: relative;
}
#container {
height: 100%
}
.conter {
width: 30%;
height: 60px;
line-height: 60px;
background: rgba(255, 255, 255, 0.20);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(4.5px);
-webkit-backdrop-filter: blur(4.5px);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.18);
position: absolute;
right: 6px;
text-align: center;
font-weight: bold;
z-index: 1000;
}
.normal {
top: 40px;
color: #19be6b;
}
.warn {
top: 110px;
color: #ff9900;
}
.error {
top: 180px;
color: #fa3534;
}
</style>
</head>
<body>
<div id='mapPage'>
<div id='container'></div>
</div>
</body>
<!-- 微信 JS-SDK 如果不需要兼容小程序,则无需引用此 JS 文件 -->
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<!-- uni 的 SDK -->
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js">
</script>
<!-- 百度地图 -->
<script type="text/javascript"
src="https://api.map.baidu.com/api?v=3.0&&type=webgl&ak=XxNPnEwtZydqXQyXcNhDXNSOo6WgzZdh"></script>
<!-- 引入jquery -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script type="text/javascript">
document.addEventListener('UniAppJSBridgeReady', function() {
let arr = window.location.href.split('?')
let data = decodeURIComponent(arr[1]);
let lng = data.split('&')[0];
let lat = data.split('&')[1];
var map = new BMapGL.Map("container");
var point = new BMapGL.Point(lng, lat);
map.centerAndZoom(point, 17);
map.enableScrollWheelZoom(true);
var scaleCtrl = new BMapGL.ScaleControl();
map.addControl(scaleCtrl);
var zoomCtrl = new BMapGL.ZoomControl();
map.addControl(zoomCtrl);
var cityCtrl = new BMapGL.CityListControl();
map.addControl(cityCtrl);
var marker = new BMapGL.Marker(point);
map.addOverlay(marker);
});
</script>
</html>
第二步:创建map.vue文件 并将map.html嵌入
<template>
<view class="alarmManagement">
<!-- Map -->
<view class="map"><web-view :src="url"></web-view></view>
</view>
</template>
<script>
export default {
data(){
return{
url:`/static/html/map.html?`,
}
},
onLoad(option){
this.url += encodeURIComponent(`${option.longitude}&${option.latitude}`)
},
}
</script>
<style>
.map {
width: 90%;
height: 90%;
}
</style>
|