QinGang_interested/assets/map/map.html

92 lines
2.9 KiB
HTML
Raw Permalink Normal View History

2025-12-12 09:11:30 +08:00
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>地图</title>
</head>
2026-04-21 17:08:31 +08:00
<script src="https://api.tianditu.gov.cn/api?v=4.0&tk=e8a16137fd226a62a23cc7ba5c9c78ce" type="text/javascript">
</script>
<script src="./js/uni.webview.1.5.4.js"></script>
<body onLoad="onLoad()">
<div id="mapDiv" style="position:absolute;width:100vw; height:100vh"></div>
2025-12-12 09:11:30 +08:00
</body>
2026-04-21 17:08:31 +08:00
<style>
* {
margin: 0;
padding: 0;
2025-12-12 09:11:30 +08:00
}
2026-04-21 17:08:31 +08:00
</style>
<script type="text/javascript">
const userAgent = navigator.userAgent
if (/miniProgram/i.test(userAgent) && /micromessenger/i.test(userAgent)) {
document.write('<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"><\/script>');
}
</script>
<script>
var map;
var zoom = 14;
2025-12-12 09:11:30 +08:00
2026-04-21 17:08:31 +08:00
function getUrlParam(name) {
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
const r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return "";
}
2025-12-12 09:11:30 +08:00
2026-04-21 17:08:31 +08:00
function onLoad() {
var imageURL = "https://t0.tianditu.gov.cn/img_w/wmts?" +
"SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
"&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e8a16137fd226a62a23cc7ba5c9c78ce";
lay = new T.TileLayer(imageURL, {minZoom: 1, maxZoom: 18});
var config = {layers: [lay]};
map = new T.Map("mapDiv", config);
map.centerAndZoom(new T.LngLat(getUrlParam('longitude'), getUrlParam('latitude')), zoom);
map.enableScrollWheelZoom();
if (getUrlParam('point')) {
var point = JSON.parse(decodeURIComponent(getUrlParam('point')));
for (let i = 0; i < point.length; i++) {
var icon = new T.Icon({
iconUrl: point[i].iconPath.replaceAll('/static', './'),
iconSize: point[i].iconPath.indexOf('50.png') ? new T.Point(25, 27) : new T.Point(23, 25),
iconAnchor: new T.Point(10, 25)
});
var marker = new T.Marker(new T.LngLat(point[i].longitude, point[i].latitude), {icon: icon});
map.addOverLay(marker);
2025-12-12 09:11:30 +08:00
}
2026-04-21 17:08:31 +08:00
} else {
addMapClick()
2025-12-12 09:11:30 +08:00
}
2026-04-21 17:08:31 +08:00
}
2025-12-12 09:11:30 +08:00
2026-04-21 17:08:31 +08:00
function addMapClick() {
map.addEventListener("click", MapClick);
}
2025-12-12 09:11:30 +08:00
2026-04-21 17:08:31 +08:00
function MapClick(event) {
var marker = new T.Marker(new T.LngLat(event.lnglat.getLng(), event.lnglat.getLat()));
map.clearOverLays();
map.addOverLay(marker);
uni.getEnv(function (res) {
if (res.plus) {
uni.postMessage({
data: {
"longitue": event.lnglat.getLng(),
"latitude": event.lnglat.getLat(),
2025-12-12 09:11:30 +08:00
}
2026-04-21 17:08:31 +08:00
})
}else {
wx.miniProgram.navigateBack()
wx.miniProgram.postMessage({
data: {
"longitue": event.lnglat.getLng(),
"latitude": event.lnglat.getLat(),
2025-12-12 09:11:30 +08:00
}
2026-04-21 17:08:31 +08:00
})
2025-12-12 09:11:30 +08:00
}
2026-04-21 17:08:31 +08:00
});
2025-12-12 09:11:30 +08:00
2026-04-21 17:08:31 +08:00
}
2025-12-12 09:11:30 +08:00
</script>
</html>