From e7df063a027c0f066317da4437d01cf3f3bc8d31 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 13 十一月 2024 17:28:31 +0800
Subject: [PATCH] 地图添加巡检定位功能
---
app/src/main/assets/js/map.js | 37 +++++++++++++++++++++++++++++++------
1 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/app/src/main/assets/js/map.js b/app/src/main/assets/js/map.js
index cdd6aef..760cee6 100644
--- a/app/src/main/assets/js/map.js
+++ b/app/src/main/assets/js/map.js
@@ -24,13 +24,22 @@
};
// 鍒濆鍖栧湴鍥�
function initMap() {
+ // 褰卞儚搴曞浘
var imageURL = "http://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=d8beed89b43160a9a185e5aff431f85d";
//鍒涘缓鑷畾涔夊浘灞傚璞�
- var lay = new T.TileLayer(imageURL, { minZoom: 1, maxZoom: 18 });
- var config = { layers: [lay] };
+ //褰卞儚娉ㄨ锛堝湴鍥句笂鐨勫湴鍧�锛�
+ var imgURL2 ="http://t0.tianditu.gov.cn/cia_w/wmts?" +"SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
+ "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" +
+ "&tk=d8beed89b43160a9a185e5aff431f85d";
+ var lay = new T.TileLayer(imageURL, { minZoom: 6, maxZoom: 18 });
+ var lay2 = new T.TileLayer(imgURL2, { minZoom: 6, maxZoom: 18 });
+ var config = { layers: [lay,lay2] };
map = new T.Map("mapDiv", config);
+ var scale = new T.Control.Scale();
+ //娣诲姞姣斾緥灏烘帶浠�
+ map.addControl(scale);
map.centerAndZoom(new T.LngLat(116.40769, 39.89945), zoom); //鍦板浘鐨勫垵濮嬪寲涓績鐐癸紝姝や负鍖椾含鐨勭粡绾害
map.addEventListener("click", closeWaterIntakeDetail);
}
@@ -131,21 +140,21 @@
// 鎵嬫満鑾峰彇鍒板畾浣嶅悗鏄剧ず瀹氫綅
function locationOverLay(lng, lag) {
console.log("function銆嬨�嬨�嬨�嬨�媗ocationOverLay");
- map.centerAndZoom(new T.LngLat(lng, lag), 18);
+ map.centerAndZoom(new T.LngLat(lng, lag), map.getZoom());
let icon = new T.Icon({
iconUrl: locationIMGPath,
iconSize: new T.Point(27, 27),
iconAnchor: new T.Point(10, 25)
});
-
let marker = new T.Marker(new T.LngLat(lng, lag), { icon: icon });
map.addOverLay(marker);
}
//璁剧疆鍦板浘涓績鐐�
- function setCenterAndZoom(lng, lat) {
+ function setCenterAndZoom(lng, lat,thiszoom) {
+ zoom=thiszoom;
console.log("function銆嬨�嬨�嬨�嬨�媠etCenterAndZoom>>>>lng:" + lng + ",lat:" + lat);
map.centerAndZoom(new T.LngLat(lng, lat), zoom);
}
@@ -157,6 +166,7 @@
window.showToast = showToast;
window.addMarker = addMarker;
window.setCenterAndZoom = setCenterAndZoom;
+ window.updateLocation=updateLocation;
}
// 璋冪敤鍘熺敓瀹夊崜鏂规硶鏄剧ず鍙栨按鍙h鎯�
@@ -250,7 +260,7 @@
position: marker.getLngLat(),
offset: new T.Point(-35, 8), // 璁剧疆鏍囨敞鏂囧瓧鐨勪綅缃�
opacity: 1, // 璁剧疆鏂囨湰鐨勬樉绀轰笉閫忔槑搴︼紙鑼冨洿0-1锛�
- });
+ });
label.setBorderLine(0); // 璁剧疆鏂囨湰鐨勮竟妗嗙嚎瀹�
label.setBackgroundColor("transparent"); // 璁剧疆鏂囨湰鐨勮儗鏅壊锛堥�忔槑鑹诧級
label.setFontColor("#0000FF");
@@ -259,6 +269,21 @@
});
return "addMarker鍔犺浇鎴愬姛"
}
+ //淇濆瓨瀹氫綅鍧愭爣鐢熸垚杞ㄨ抗
+ var path=[];
+ function updateLocation(lat,log){
+ var newPoint = new T.LatLng(latitude, longitude);
+ path.push(newPoint);
+ var polyline = new T.Polyline({
+ path: path, // 杞ㄨ抗鍧愭爣
+ strokeColor: "#FF0000", // 杞ㄨ抗棰滆壊
+ strokeWeight: 6, // 杞ㄨ抗绾垮
+ strokeOpacity: 0.7 // 杞ㄨ抗閫忔槑搴�
+ });
+ map.addOverlay(polyline);
+ // 绉诲姩鍦板浘瑙嗚鍒版渶鍚庝竴涓綅缃�
+ map.panTo(newPoint);
+ }
})();
--
Gitblit v1.8.0