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 | 18 +++++++++++++++++- app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java | 18 +++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/js/map.js b/app/src/main/assets/js/map.js index 130aa4b..760cee6 100644 --- a/app/src/main/assets/js/map.js +++ b/app/src/main/assets/js/map.js @@ -166,6 +166,7 @@ window.showToast = showToast; window.addMarker = addMarker; window.setCenterAndZoom = setCenterAndZoom; + window.updateLocation=updateLocation; } // 璋冪敤鍘熺敓瀹夊崜鏂规硶鏄剧ず鍙栨按鍙h鎯� @@ -259,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"); @@ -268,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); + } })(); diff --git a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java index d5a7925..ebc3cd1 100644 --- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java +++ b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java @@ -41,6 +41,7 @@ import com.dayu.pipirrapp.utils.SharedPreferencesHelper; import com.dayu.pipirrapp.utils.ToastUtil; import com.dayu.pipirrapp.utils.WebViewUtils; +import com.dayu.pipirrapp.view.ConfirmDialog; import com.jeremyliao.liveeventbus.LiveEventBus; import java.io.File; @@ -106,7 +107,7 @@ @Override public void onChanged(Object o) { LatLonBean latLonBean = (LatLonBean) o; - mWebView.evaluateJavascript("javascript:locationOverLay(\"" + latLonBean.getLongitude() + "\",\"" + latLonBean.getLatitude() + "\")", value -> { + mWebView.evaluateJavascript("javascript:updateLocation(\"" + latLonBean.getLatitude()+ "\",\"" + latLonBean.getLongitude()+ "\")", value -> { }); } }); @@ -345,8 +346,19 @@ }); //宸℃鎸夐挳 binding.inspectButton.setOnClickListener(v -> { - isStartInspec = !isStartInspec; - chageInspecState(); + if (isStartInspec){ + ConfirmDialog confirmDialog=new ConfirmDialog(MapFragment.this.getActivity(), "鎻愮ず", "纭鍏抽棴宸℃鍚楋紵", new View.OnClickListener() { + @Override + public void onClick(View v) { + isStartInspec = !isStartInspec; + chageInspecState(); + } + }); + }else { + isStartInspec = !isStartInspec; + chageInspecState(); + } + }); } -- Gitblit v1.8.0