From 32275aa66faa5371467e291b7d19a5e782f8aade Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 18 十二月 2024 16:47:18 +0800
Subject: [PATCH] 1.修改取水口坐标相关代码

---
 app/src/main/res/layout/fragment_map.xml                             |   62 +++++-
 app/src/main/assets/js/map.js                                        |  125 +++++++-----
 app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java     |   10 
 app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java      |    5 
 app/src/main/java/com/dayu/pipirrapp/bean/net/InspectionRequest.java |   19 +
 app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java       |  233 ++++++++++++++++++-----
 app/src/main/java/com/dayu/pipirrapp/tool/MarkerUtils.java           |    2 
 app/src/main/java/com/dayu/pipirrapp/tool/MyWebViewInterface.java    |   18 +
 app/src/main/java/com/dayu/pipirrapp/net/MqttManager.java            |  118 +++++++----
 9 files changed, 418 insertions(+), 174 deletions(-)

diff --git a/app/src/main/assets/js/map.js b/app/src/main/assets/js/map.js
index 3b54c66..8309b68 100644
--- a/app/src/main/assets/js/map.js
+++ b/app/src/main/assets/js/map.js
@@ -23,6 +23,8 @@
         window.updateInspectionLocation = updateInspectionLocation;
         window.cleanLoclLay = cleanLoclLay;
         window.showPin = showPin;
+        window.cancelPin = cancelPin;
+        window.refreshMarker = refreshMarker;
 
     }
 
@@ -34,11 +36,7 @@
         mountMethodToWindow();
 
     });
-    // window.onload = function () {
-    //     console.log(window.onload);  // 鎵撳嵃鏁扮粍鏁版嵁
-    //     //鍔犺浇鍧愭爣鐐�
-    //     window.Android.loadMarker();
-    // };
+
     // 鍒濆鍖栧湴鍥�
     function initMap() {
         //    褰卞儚搴曞浘
@@ -146,30 +144,36 @@
 
     // 璋冪敤鍘熺敓瀹夊崜鏂规硶闅愯棌鍙栨按鍙h鎯�
     function closeWaterIntakeDetail(data) {
-        if (lastClickedMarker !== null) {
-            // 濡傛灉鏈夌偣鍑诲彇姘村彛鍒欏皢鍙栨按鍙f仮澶嶆垚榛戣壊
-            // 涓婃鐐瑰嚮鐨勬爣娉ㄦ敼涓洪粦鑹�
-            var defaulticon = new T.Icon({
-                iconUrl: markerBluePath,
-                iconSize: new T.Point(28, 28),
-                iconAnchor: new T.Point(14, 28)
-            });
-            lastClickedMarker.setIcon(defaulticon);
+        if (!isShowCenterPin) {
+            if (lastClickedMarker !== null) {
+                // 濡傛灉鏈夌偣鍑诲彇姘村彛鍒欏皢鍙栨按鍙f仮澶嶆垚榛戣壊
+                // 涓婃鐐瑰嚮鐨勬爣娉ㄦ敼涓洪粦鑹�
+                var defaulticon = new T.Icon({
+                    iconUrl: markerBluePath,
+                    iconSize: new T.Point(28, 28),
+                    iconAnchor: new T.Point(14, 28)
+                });
+                lastClickedMarker.setIcon(defaulticon);
+            }
+            if (isShowWaterIntakeDetail) {
+                // 鍋囧鏄剧ず浜嗗彇姘村彛璇︽儏鍒欓殣钘忓彇姘村彛璇︽儏
+                isShowWaterIntakeDetail = false;
+                window.Android.closeWaterIntakeView();
+            } else {
+                // 鍋囧娌℃湁鏄剧ず鍙栨按鍙e垯娣诲姞鐐瑰嚮鐨勫潗鏍�
+                getLngLat(data.lnglat);
+            }
         }
-        if (isShowWaterIntakeDetail) {
-            // 鍋囧鏄剧ず浜嗗彇姘村彛璇︽儏鍒欓殣钘忓彇姘村彛璇︽儏
-            isShowWaterIntakeDetail = false;
-            window.Android.closeWaterIntakeView();
-        } else {
-            // 鍋囧娌℃湁鏄剧ず鍙栨按鍙e垯娣诲姞鐐瑰嚮鐨勫潗鏍�
-            getLngLat(data.lnglat);
-        }
+
     }
 
     // 鐐瑰嚮鏍囨敞鐨勪簨浠�
     function addMarkerListener(id, data) {
-        chageMarkerIcon(data);
-        showWaterIntakeDetail(id);
+        if (!isShowCenterPin) {
+            chageMarkerIcon(data);
+            showWaterIntakeDetail(id);
+        }
+
     }
 
     // 淇敼鐐瑰嚮鏍囨敞鐨勫浘鏍�
@@ -196,6 +200,7 @@
             }
         }
         lastClickedMarker = data.target;
+        map.panTo(currentMarker.getLngLat());
     }
     //璋冨畨鍗撳師鐢�
     function showToast() {
@@ -206,12 +211,21 @@
     function isEqualsLngLat(data1, data2) {
         return data1.lat === data2.lat && data1.lng === data2.lng;
     }
-    //娣诲姞浠庡師鐢熶紶杩囨潵鐨勫潗鏍囧苟鏄剧ず鍦ㄥ湴鍥句笂
     function addMarker(id, lng, lat, name) {
-        console.log("function銆嬨�嬨�嬨�嬨�媋ddMarker");
+        addMarker(id, lng, lat, name, false)
+    }
+    //娣诲姞浠庡師鐢熶紶杩囨潵鐨勫潗鏍囧苟鏄剧ず鍦ㄥ湴鍥句笂
+    function addMarker(id, lng, lat, name, isRed) {
+        console.log("function銆嬨�嬨�嬨�嬨�媋ddMarker>>>id:" + id);
 
+        var iconUrl;
+        if (isRed) {
+            iconUrl = markerRedPath;
+        } else {
+            iconUrl = markerBluePath;
+        }
         var icon = new T.Icon({
-            iconUrl: markerBluePath,
+            iconUrl: iconUrl,
             iconSize: new T.Point(28, 28),
             iconAnchor: new T.Point(14, 28)
         });
@@ -222,7 +236,7 @@
         marker.addEventListener("click", (data) => {
             addMarkerListener(id, data)
         });
-        map.addOverLay(marker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
+
         let label = new T.Label({
             text: `<div style='position:absolute;left:-50%;transform: translateX(-50%);'>${name}<div>`,
             position: marker.getLngLat(),
@@ -233,8 +247,13 @@
         label.setBackgroundColor("transparent"); // 璁剧疆鏂囨湰鐨勮儗鏅壊锛堥�忔槑鑹诧級
         label.setFontColor("#FFFFFF");
         label.setFontSize(10);
+        marker.label = label;
+        if (isRed){
+            lastClickedMarker=marker;
+        }
         map.addOverLay(label);
-        return "addMarker鍔犺浇鎴愬姛"
+        map.addOverLay(marker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
+        return "addMarker鍔犺浇鎴愬姛 id:" + id
     }
     //鏇存柊瀹氫綅鍧愭爣
     function updateLocation(log, lat) {
@@ -300,36 +319,34 @@
         }
     }
 
+    //鏄惁鏄剧ず浜嗗湴鍥句腑蹇冪殑閽堢敤鏉ヤ慨鏀瑰潗鏍�
+    var isShowCenterPin;
+    //寮�濮嬭幏鍙栧睆骞曚腑闂村畾浣�
+    function showPin(lng, lat) {
+        var newPoint = new T.LngLat(lng, lat);
+        map.panTo(newPoint);
+        isShowCenterPin = true;
+        map.addEventListener("moveend", mapMoveEnd);
+        window.Android.refreshCenter(map.getCenter().getLng(), map.getCenter().getLat());
 
-
-    //鍦ㄥ湴鍥句笂鏄剧ず涓績鐐�
-    var pinMarker;
-    function showPin() {
-        var icon = new T.Icon({
-            iconUrl: centerPin,
-            iconSize: new T.Point(28, 28),
-            iconAnchor: new T.Point(14, 28)
-        });
-        pinMarker = new T.Marker(
-            new T.LngLat(map.getCenter().getLng(), map.getCenter().getLat()) // 鍒涘缓鏍囨敞
-            , { icon: icon });
-        map.addOverLay(pinMarker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
-        map.addEventListener("moveend", MapMoveend);
+    }
+    //鍙栨秷淇敼瀹氫綅
+    function cancelPin() {
+        isShowCenterPin = false;
     }
 
-    function MapMoveend(e) {
-        map.removeOverLay(pinMarker);
-        var icon = new T.Icon({
-            iconUrl: centerPin,
-            iconSize: new T.Point(28, 28),
-            iconAnchor: new T.Point(14, 28)
-        });
+    //鎴愬姛淇敼鍙栨按鍙g粡绾害鍚庡埛鏂板彇姘村彛浣嶇疆
+    function refreshMarker(id, lng, lat, name) {
+        map.removeOverLay(lastClickedMarker.label);
+        map.removeOverLay(lastClickedMarker);
+        addMarker(id, lng, lat, name, true);
+    }
+
+
+    function mapMoveEnd(e) {
         var center = e.target.getCenter();
         console.log("lng:" + center.getLng() + "   lat:" + center.getLat())
-        pinMarker = new T.Marker(
-            new T.LngLat(center.getLng(), center.getLat()) // 鍒涘缓鏍囨敞
-            , { icon: icon });
-        map.addOverLay(pinMarker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
+        window.Android.refreshCenter(center.getLng(), center.getLat());
     }
 
 })();
diff --git a/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java b/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java
index 767a6b9..fd57d07 100644
--- a/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java
+++ b/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java
@@ -59,7 +59,6 @@
             e.printStackTrace();
         }
         mqttManager = new MqttManager(this, this);
-        mqttManager.connect();
         LiveEventBus.get(CommonKeyName.NetworkCallback).observeForever(new Observer<Object>() {
             @Override
             public void onChanged(Object o) {
@@ -74,6 +73,7 @@
                 }
             }
         });
+
         registNetCallBack();
     }
 
@@ -120,8 +120,9 @@
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        //鍏抽棴MQ
+
         try {
+            //鍏抽棴MQ
             mqttManager.disconnect();
             unregisterNetworkCallback();
         } catch (Exception e) {
diff --git a/app/src/main/java/com/dayu/pipirrapp/bean/net/InspectionRequest.java b/app/src/main/java/com/dayu/pipirrapp/bean/net/InspectionRequest.java
index 8e11af7..333645b 100644
--- a/app/src/main/java/com/dayu/pipirrapp/bean/net/InspectionRequest.java
+++ b/app/src/main/java/com/dayu/pipirrapp/bean/net/InspectionRequest.java
@@ -10,12 +10,26 @@
  * @version 1.0
  * @since 2024-12-02
  */
-public class InspectionRequest extends BaseRequest{
+public class InspectionRequest extends BaseRequest {
+    private static InspectionRequest inspectionRequest;
+
+    public static InspectionRequest getInstance() {
+        if (inspectionRequest == null) {
+            inspectionRequest = new InspectionRequest();
+        }
+        inspectionRequest.setStartTime("");
+        inspectionRequest.setStopTime("");
+        inspectionRequest.setInspectId("");
+        inspectionRequest.setInspectorId("");
+        inspectionRequest.getTracks().clear();
+        return inspectionRequest;
+    }
+
     private String inspectorId;
     private String inspectId;
     private String startTime;
     private String stopTime;
-    private List<Track> tracks=new ArrayList<>();
+    private List<Track> tracks = new ArrayList<>();
 
 
     public String getInspectorId() {
@@ -64,7 +78,6 @@
         }
         tracks.add(track);
     }
-
 
 
     // Track 鏁版嵁绫�
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 61e1fa0..9266ffb 100644
--- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
+++ b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
@@ -17,11 +17,13 @@
 import android.webkit.WebResourceResponse;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
+import android.widget.RelativeLayout;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.lifecycle.Observer;
 
+import com.dayu.pipirrapp.MyApplication;
 import com.dayu.pipirrapp.R;
 import com.dayu.pipirrapp.activity.AddIssueActivity;
 import com.dayu.pipirrapp.bean.db.CenterPointBean;
@@ -68,6 +70,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
 import io.reactivex.rxjava3.schedulers.Schedulers;
@@ -90,9 +93,8 @@
     MapFragmenObserver mapFragmenObserver;
     //褰撳墠宸℃璁板綍鐨勭浉鍏充俊鎭�
     public InspectionBean mInspectionBean;
+    //鏈�鍚庝竴娆″畾浣嶇殑鍧愭爣
     LatLonBean lastLatLonBean;
-    InspectionRequest inspectionRequest;
-    //    volatile boolean isHaseAginData = false;
     //web鏄惁鍔犺浇瀹屾垚
     volatile boolean webViewIsFinished = false;
     List<InspectionLocationBean> aginShowlocationBeans;
@@ -100,6 +102,9 @@
     List<MarkerBean> webNoFinishMarkerData = new ArrayList<>();
     //鎵�鏈夌殑Marker鏁版嵁閿负marker鐨処d
     Map<String, MarkerBean> markerBeanSet = new HashMap<>();
+    //涓績鐐瑰潗鏍�
+    public double centerLng;
+    public double centerLat;
 
     @Override
     public void onAttach(@NonNull Context context) {
@@ -242,41 +247,43 @@
             @Override
             public void onNext(BaseResponse<MarkerListResult> t) {
                 if (t.isSuccess()) {
-                    if (t.isSuccess()) {
-                        if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) {
-                            List<MarkerBean> markerBeans = new ArrayList<>();
-                            for (int i = 0; i < t.getContent().getObj().size(); i++) {
-                                MarkerResult result = t.getContent().getObj().get(i);
-                                //淇濆瓨鏁版嵁
-                                MarkerBean markerBean = new MarkerBean();
-                                markerBean.setId(result.getId());
-                                markerBean.setLng(result.getLng());
-                                markerBean.setLat(result.getLat());
-                                markerBean.setBlockId(result.getBlockId());
-                                markerBean.setName(result.getName());
-                                markerBean.setRemarks(result.getRemarks());
-                                markerBean.setTownId(result.getTownId());
-                                markerBean.setVillageId(result.getVillageId());
-                                markerBean.setCountyId(result.getCountyId());
-                                markerBean.setAddress(result.getAddress());
-                                markerBean.setBlockName(result.getBlockName());
-                                markerBeans.add(markerBean);
-                                setMapMarker(markerBean);
-                            }
-                            DaoSingleton.getInstance(MapFragment.this.getContext()).markerDao().deleteAll();
-                            // 浣跨敤 RxJava 寮傛鎻掑叆鏁版嵁
-                            DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).markerDao().insertAll(markerBeans)
-                                    .subscribeOn(Schedulers.io()) // 鍦� IO 绾跨▼涓婃墽琛�
-                                    .observeOn(AndroidSchedulers.mainThread()) // 鍦ㄤ富绾跨▼涓婅瀵�
-                                    .subscribe(() -> {
-                                        // 鎻掑叆鎴愬姛
-                                        Log.i("mWebView", "鏁版嵁鎻掑叆鎴愬姛");
-                                    }, throwable -> {
-                                        // 鎻掑叆澶辫触
-                                        Log.e("mWebView", "鏁版嵁鎻掑叆澶辫触: " + throwable.getMessage());
-                                    });
-                        }
+
+                    if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) {
+
+                        List<MarkerBean> markerBeans = t.getContent().getObj().stream()
+                                .map(result -> {
+                                    MarkerBean markerBean = new MarkerBean();
+                                    markerBean.setId(result.getId());
+                                    markerBean.setLng(result.getLng());
+                                    markerBean.setLat(result.getLat());
+                                    markerBean.setBlockId(result.getBlockId());
+                                    markerBean.setName(result.getName());
+                                    markerBean.setRemarks(result.getRemarks());
+                                    markerBean.setTownId(result.getTownId());
+                                    markerBean.setVillageId(result.getVillageId());
+                                    markerBean.setCountyId(result.getCountyId());
+                                    markerBean.setAddress(result.getAddress());
+                                    markerBean.setBlockName(result.getBlockName());
+                                    markerBean.setDivideId(result.getDivideId());
+                                    setMapMarker(markerBean);
+                                    return markerBean;
+                                })
+                                .collect(Collectors.toList());
+
+                        DaoSingleton.getInstance(MapFragment.this.getContext()).markerDao().deleteAll();
+                        // 浣跨敤 RxJava 寮傛鎻掑叆鏁版嵁
+                        DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).markerDao().insertAll(markerBeans)
+                                .subscribeOn(Schedulers.io()) // 鍦� IO 绾跨▼涓婃墽琛�
+                                .observeOn(AndroidSchedulers.mainThread()) // 鍦ㄤ富绾跨▼涓婅瀵�
+                                .subscribe(() -> {
+                                    // 鎻掑叆鎴愬姛
+                                    Log.i("mWebView", "鏁版嵁鎻掑叆鎴愬姛");
+                                }, throwable -> {
+                                    // 鎻掑叆澶辫触
+                                    Log.e("mWebView", "鏁版嵁鎻掑叆澶辫触: " + throwable.getMessage());
+                                });
                     }
+
                 } else {
                     ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg());
                 }
@@ -287,7 +294,6 @@
 
 
     void initView() {
-
 
         //宸℃鎸夐挳
         binding.inspectButton.setOnClickListener(v -> {
@@ -333,16 +339,8 @@
         MyLog.i(data);
         MarkerBean markerBean = markerBeanSet.get(data);
         if (markerBean != null) {
-            binding.bottomLL.setVisibility(View.VISIBLE);
-            binding.markerAddress.setText(markerBean.getAddress());
-            binding.markerName.setText(markerBean.getName());
-            binding.markerBlockName.setText(markerBean.getBlockName());
-            binding.lat.setText(markerBean.getLat());
-            binding.lng.setText(markerBean.getLng());
-            binding.editePoint.setOnClickListener(v -> {
-                mWebView.evaluateJavascript("javascript:showPin()", value -> {
-                });
-            });
+            setWebViewParams(false);
+            getInstakeDetail(markerBean);
         }
 
     }
@@ -352,7 +350,7 @@
      * 鑾峰彇鍦板浘涓績鐐�
      */
     private void getCenterPoint() {
-        ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + "/base/dict_item/map_center", CenterPointResult.class, null, new SubscriberListener<BaseResponse<CenterPointResult>>() {
+        ApiManager.getInstance().requestGetHideLoading(this.getContext(), Constants.BASE_URL + "/base/dict_item/map_center", CenterPointResult.class, null, new SubscriberListener<BaseResponse<CenterPointResult>>() {
             @Override
             public void onNext(BaseResponse<CenterPointResult> t) {
                 if (t.isSuccess()) {
@@ -380,6 +378,7 @@
      * 涓婃姤宸℃璁板綍
      */
     private void pushLocationData(InspectionLocationBean inspectionLocationBean) {
+        InspectionRequest inspectionRequest = InspectionRequest.getInstance();
         inspectionRequest.setInspectId(inspectionLocationBean.getInspectId());
         inspectionRequest.setInspectorId(mInspectionBean.getInspectorId());
         if (mInspectionBean != null) {
@@ -392,7 +391,6 @@
         track.setLat(inspectionLocationBean.getLat());
         track.setLng(inspectionLocationBean.getLng());
         track.setLocateTime(inspectionLocationBean.getLocateTime());
-        inspectionRequest.getTracks().clear();
         inspectionRequest.addTracks(track);
         ApiManager.getInstance().requestPostHideLoading(MapFragment.this.getContext(), BASE_URL + "/app/inspect/save", InsectionResult.class, inspectionRequest.toMap(inspectionRequest), new SubscriberListener<BaseResponse<List<InsectionResult>>>() {
             @Override
@@ -558,7 +556,6 @@
     public void setMapMarker(MarkerBean markerBean) {
         if (markerBean != null) {
             if (webViewIsFinished) {
-                Log.i("mWebView", "addMarker????????????");
                 mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() {
                     @Override
                     public void onReceiveValue(String value) {
@@ -586,7 +583,6 @@
         binding.inspectPause.setText("鏆傚仠");
         binding.stateText.setText("宸插紑鍚贰妫�");
         binding.inspectRL.setBackgroundColor(this.getContext().getResources().getColor(R.color.base_blue));
-        inspectionRequest = new InspectionRequest();
         SharedPreferencesHelper.getInstance(this.getContext()).put(CommonKeyName.inspectionState, InspectionUtils.STAT_INSPECTION);
         ServiceUtils.startLocationService(MapFragment.this.getContext(), false);
     }
@@ -629,4 +625,139 @@
             e.printStackTrace();
         }
     }
+
+    /**
+     * 鎺ユ敹js浼犳潵鐨勪腑蹇冪偣鍧愭爣
+     *
+     * @param lng
+     * @param lat
+     */
+    public void refreshCenterPoint(double lng, double lat) {
+        centerLng = lng;
+        centerLat = lat;
+        binding.pointText.setText(centerLng + "锛�" + centerLat);
+    }
+
+    /**
+     * 淇敼缁忕含搴�
+     *
+     * @param markerBean
+     */
+    private void updataInstake(MarkerBean markerBean) {
+        String lng = String.valueOf(centerLng);
+        String lat = String.valueOf(centerLat);
+        Map<String, Object> params = new HashMap<>();
+        params.put("id", markerBean.getId());
+        params.put("lng", lng);
+        params.put("lat", lat);
+        params.put("operator", MyApplication.myApplication.userId);
+
+        ApiManager.getInstance().requestPost(MapFragment.this.getContext(), BASE_URL + "/project/intake/updateIntakeLngLat", Boolean.class, params, new SubscriberListener<BaseResponse<Boolean>>() {
+            @Override
+            public void onNext(BaseResponse<Boolean> t) {
+                try {
+                    if (t.isSuccess()) {
+                        mWebView.evaluateJavascript("javascript:refreshMarker(\"" + markerBean.getId() + "\",\"" + centerLng + "\",\"" + centerLat + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() {
+                            @Override
+                            public void onReceiveValue(String value) {
+                            }
+                        });
+                        binding.pointCenterImg.setVisibility(View.GONE);
+                        binding.pointRL.setVisibility(View.GONE);
+                        binding.lng.setText(lng);
+                        binding.lat.setText(lat);
+                        mWebView.evaluateJavascript("javascript:cancelPin()", value -> {
+                        });
+                        ToastUtil.showToastLong(MapFragment.this.getContext(), "淇敼鎴愬姛锛�");
+
+                    } else {
+                        ToastUtil.showToastLong(MapFragment.this.getContext(), t.getMsg());
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    CrashReport.postCatchedException(e);
+                }
+
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇鍙栨按鍙h鎯�
+     *
+     * @param markerBean
+     */
+    private void getInstakeDetail(MarkerBean markerBean) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("id", markerBean.getId());
+        ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + "/project/intake/one", MarkerResult.class, params, new SubscriberListener<BaseResponse<MarkerResult>>() {
+            @Override
+            public void onNext(BaseResponse<MarkerResult> t) {
+                if (t.isSuccess()) {
+                    MarkerResult result = t.getContent();
+                    MarkerBean markerBean = new MarkerBean();
+                    markerBean.setId(result.getId());
+                    markerBean.setLng(result.getLng());
+                    markerBean.setLat(result.getLat());
+                    markerBean.setBlockId(result.getBlockId());
+                    markerBean.setName(result.getName());
+                    markerBean.setRemarks(result.getRemarks());
+                    markerBean.setTownId(result.getTownId());
+                    markerBean.setVillageId(result.getVillageId());
+                    markerBean.setCountyId(result.getCountyId());
+                    markerBean.setAddress(result.getAddress());
+                    markerBean.setBlockName(result.getBlockName());
+                    markerBean.setDivideId(result.getDivideId());
+                    showMarker(markerBean);
+                } else {
+                    ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg());
+                }
+            }
+
+        });
+    }
+
+    private void showMarker(MarkerBean markerBean) {
+        binding.bottomLL.setVisibility(View.VISIBLE);
+        binding.markerAddress.setText(markerBean.getAddress());
+        binding.markerName.setText(markerBean.getName());
+        binding.markerBlockName.setText(markerBean.getBlockName());
+        binding.lat.setText(markerBean.getLat());
+        binding.lng.setText(markerBean.getLng());
+        //淇敼缁忕含搴�
+        binding.editePoint.setOnClickListener(v -> {
+            mWebView.evaluateJavascript("javascript:showPin(\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\")", value -> {
+            });
+            binding.pointRL.setVisibility(View.VISIBLE);
+            binding.pointCenterImg.setVisibility(View.VISIBLE);
+            setWebViewParams(true);
+        });
+        //鍙栨秷淇敼缁忕含搴�
+        binding.pointCancel.setOnClickListener(v -> {
+                    binding.pointCenterImg.setVisibility(View.GONE);
+                    binding.pointRL.setVisibility(View.GONE);
+                    mWebView.evaluateJavascript("javascript:cancelPin()", value -> {
+                    });
+                }
+        );
+        //纭淇敼缁忕含搴�
+        binding.pointEdt.setOnClickListener(v -> {
+            ConfirmDialog confirmDialog = new ConfirmDialog(MapFragment.this.getActivity(), "纭淇敼鍒拌浣嶇疆鍚楋紵", (confirmDialog1, v1) -> {
+                confirmDialog1.dismiss();
+                updataInstake(markerBean);
+            });
+            confirmDialog.show();
+        });
+    }
+
+    private void setWebViewParams(boolean isAbove) {
+        RelativeLayout.LayoutParams paramsAnotherView = new RelativeLayout.LayoutParams(
+                RelativeLayout.LayoutParams.MATCH_PARENT,
+                RelativeLayout.LayoutParams.MATCH_PARENT);
+        if (isAbove) {
+            paramsAnotherView.addRule(RelativeLayout.ABOVE, binding.bottomLL.getId());
+        }
+        binding.webViewRL.setLayoutParams(paramsAnotherView);
+    }
+
 }
diff --git a/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java b/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java
index 377837d..d2a83e8 100644
--- a/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java
+++ b/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java
@@ -12,6 +12,7 @@
 import androidx.activity.result.contract.ActivityResultContracts;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.lifecycle.Observer;
 import androidx.recyclerview.widget.LinearLayoutManager;
 
 import com.dayu.pipirrapp.MyApplication;
@@ -93,10 +94,13 @@
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         binding = FragmentOrderBinding.inflate(inflater, container, false);
         initView();
-        //鑾峰彇瀹氫綅鏈嶅姟浼犺繃鏉ョ殑鍧愭爣鐐�
-        LiveEventBus.get(CommonKeyName.MQTTData).observeForever(o -> {
-        });
+        //mq浼犳潵鐨勬秷鎭�
+        LiveEventBus.get(CommonKeyName.MQTTData).observeForever(new Observer<Object>() {
+            @Override
+            public void onChanged(Object o) {
 
+            }
+        });
         return binding.getRoot();
     }
 
diff --git a/app/src/main/java/com/dayu/pipirrapp/net/MqttManager.java b/app/src/main/java/com/dayu/pipirrapp/net/MqttManager.java
index ec1c035..4776cc2 100644
--- a/app/src/main/java/com/dayu/pipirrapp/net/MqttManager.java
+++ b/app/src/main/java/com/dayu/pipirrapp/net/MqttManager.java
@@ -6,7 +6,9 @@
 import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.Observer;
 
+import com.dayu.pipirrapp.MyApplication;
 import com.dayu.pipirrapp.utils.CommonKeyName;
+import com.dayu.pipirrapp.utils.MyJsonParser;
 import com.dayu.pipirrapp.utils.MyLog;
 import com.dayu.pipirrapp.utils.NetUtils;
 import com.jeremyliao.liveeventbus.LiveEventBus;
@@ -19,6 +21,7 @@
 import org.eclipse.paho.client.mqttv3.MqttMessage;
 import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
 
+import java.util.HashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -31,14 +34,16 @@
  */
 public class MqttManager {
 
-//    private static final String MQTT_BROKER_URL = "tcp://115.236.153.170:30764"; // 淇敼涓轰綘鐨� broker 鍦板潃
-private static final String MQTT_BROKER_URL = "tcp://192.168.10.52:1883";
+    //    private static final String MQTT_BROKER_URL = "tcp://115.236.153.170:30764"; // 淇敼涓轰綘鐨� broker 鍦板潃
+    private static final String MQTT_BROKER_URL = "tcp://192.168.10.52:1883";
     private static final String CLIENT_ID = "mqttx_a7a9fe73";
     private static final String TOPIC = "workOrder"; // 璁㈤槄鐨勪富棰�
 
     private MqttClient mqttClient;
     private MqttConnectOptions connectOptions;
     boolean isHasNet = true;
+    //鏄惁杩炴帴鎴愬姛杩囦竴娆★紝娌℃湁鐨勮瘽鑱旂綉鍚庨噸杩�
+    boolean isConnet = false;
     private ExecutorService executorService = Executors.newSingleThreadExecutor();
 
     public MqttManager(Context context, LifecycleOwner lifecycleOwner) {
@@ -50,6 +55,31 @@
             connectOptions.setCleanSession(false);
             connectOptions.setKeepAliveInterval(60); // 璁剧疆淇濇寔杩炴帴鐨勬椂闂�
             connectOptions.setAutomaticReconnect(true);  // 鍚敤鑷姩閲嶈繛
+            connectOptions.setConnectionTimeout(30);// 璁剧疆杩炴帴瓒呮椂鏃堕棿锛屽崟浣嶄负绉�
+            mqttClient.setCallback(new MqttCallback() {
+                @Override
+                public void connectionLost(Throwable cause) {
+                    Log.d("MqttManager", "杩炴帴涓㈠け锛�" + cause.getMessage());
+                    // 澶勭悊杩炴帴涓㈠け锛屽彲浠ュ皾璇曢噸鏂拌繛鎺�
+                    reconnect();
+                }
+
+                @Override
+                public void messageArrived(String topic, MqttMessage message) throws Exception {
+                    Log.d("MqttManager", "messageArrived鏀跺埌鐨勬秷:" + new String(message.getPayload()));
+                    // 澶勭悊鏀跺埌鐨勬秷鎭�
+                }
+
+                @Override
+                public void deliveryComplete(IMqttDeliveryToken token) {
+                    // 澶勭悊娑堟伅鍙戦�佸畬鎴�
+                    try {
+                        Log.d("MqttManager", "鍙戦�佸畬鎴愶細" + new String(token.getMessage().toString()));
+                    } catch (MqttException e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
             LiveEventBus.get(CommonKeyName.NetworkCallback).observe(lifecycleOwner, new Observer<Object>() {
                 @Override
                 public void onChanged(Object o) {
@@ -58,12 +88,14 @@
                             case NetUtils.Available:
                                 MyLog.i("MqttManager>>>Available");
                                 isHasNet = true;
-                                reconnect();
+                                if (!isConnet) {
+                                    reconnect();
+                                }
                                 break;
                             case NetUtils.Lost:
                                 MyLog.i("MqttManager>>>Lost");
                                 isHasNet = false;
-                                disconnect();
+//                                disconnect();
                                 break;
                         }
                     }
@@ -83,30 +115,6 @@
                     Log.d("MqttManager", "connect寮�濮嬭繛鎺sHasNet:" + isHasNet);
                     if (isHasNet) {
                         Log.d("MqttManager", "connect寮�濮嬭繛鎺�");
-                        mqttClient.setCallback(new MqttCallback() {
-                            @Override
-                            public void connectionLost(Throwable cause) {
-                                Log.d("MqttManager", "杩炴帴涓㈠け锛�" + cause.getMessage());
-                                // 澶勭悊杩炴帴涓㈠け锛屽彲浠ュ皾璇曢噸鏂拌繛鎺�
-                                reconnect();
-                            }
-
-                            @Override
-                            public void messageArrived(String topic, MqttMessage message) throws Exception {
-                                Log.d("MqttManager", "鏀跺埌鐨勬秷:" + new String(message.getPayload()));
-                                // 澶勭悊鏀跺埌鐨勬秷鎭�
-                            }
-
-                            @Override
-                            public void deliveryComplete(IMqttDeliveryToken token) {
-                                // 澶勭悊娑堟伅鍙戦�佸畬鎴�
-                                try {
-                                    Log.d("MqttManager", "鍙戦�佸畬鎴愶細" + new String(token.getMessage().toString()));
-                                } catch (MqttException e) {
-                                    e.printStackTrace();
-                                }
-                            }
-                        });
                         mqttClient.connect(connectOptions);
                         if (mqttClient.isConnected()) {
                             Log.d("MqttManager", "connect杩炴帴鎴愬姛");
@@ -129,11 +137,16 @@
     // 璁㈤槄涓婚
     private void subscribeToTopic() {
         try {
+            isConnet = true;
             mqttClient.subscribe(TOPIC, (topic, message) -> {
-                // 鏀跺埌娑堟伅鏃剁殑澶勭悊閫昏緫
-                Log.d("MqttManager", "鏀跺埌娑堟伅锛�" + new String(message.getPayload()));
+                // 鍦ㄥ瓙绾跨▼鏀跺埌娑堟伅鏃剁殑澶勭悊閫昏緫
+                Log.d("MqttManager", "subscribe鏀跺埌娑堟伅锛�" + new String(message.getPayload()));
                 //浼犻�扢Q鏀跺埌鐨勪俊鎭�
-                LiveEventBus.get(CommonKeyName.locationData).post(message.getPayload());
+                HashMap<String, Object> data= MyJsonParser.getMapFromJson(new String(message.getPayload()));
+                //鍒ゆ柇鏄惁鏄綋鍓嶇敤鎴�
+                if (data.get("inspectorId").equals(MyApplication.myApplication.userId)){
+                    LiveEventBus.get(CommonKeyName.MQTTData).post(message.getPayload());
+                }
             });
 
         } catch (MqttException e) {
@@ -161,27 +174,36 @@
             }
         } catch (MqttException e) {
             e.printStackTrace();
+        } finally {
+            executorService.shutdown();
         }
     }
 
     // 鑷姩閲嶈繛鏂规硶
     private void reconnect() {
-//        executorService.execute(() -> {
-//            try {
-//                MyLog.d("MqttManager>>>>寮�濮嬮噸杩�+isHasNet:" + isHasNet + ">>>mqttClient.isConnected():" + mqttClient.isConnected());
-//                while (!mqttClient.isConnected() && isHasNet) {
-//                    MyLog.d("MqttManager>>>>寮�濮嬭繛鎺�");
-//                    mqttClient.connect(connectOptions);
-//                    if (mqttClient.isConnected()) {
-//                        MyLog.d("MqttManager>>>杩炴帴鎴愬姛");
-//                        subscribeToTopic();
-//                        break;
-//                    }
-//                    Thread.sleep(5000);  // 姣�5绉掗噸璇曚竴娆�
-//                }
-//            } catch (MqttException | InterruptedException e) {
-//                MyLog.e("MqttManager>>>Reconnection failed" + e.toString());
-//            }
-//        });
+        executorService.execute(() -> {
+            int reconnectAttempts = 0;
+            while (!mqttClient.isConnected() && isHasNet) {
+                try {
+                    MyLog.d("MqttManager>>>>寮�濮嬮噸杩�");
+                    mqttClient.connect(connectOptions);
+                    if (mqttClient.isConnected()) {
+                        MyLog.d("MqttManager>>>杩炴帴鎴愬姛");
+                        subscribeToTopic();
+                        break;
+                    }
+                    // 鎸囨暟閫�閬�
+                    long backoff = Math.min((1L << reconnectAttempts) * 1000, 30000);
+                    Thread.sleep(backoff);
+                    reconnectAttempts++;
+                } catch (MqttException e) {
+                    MyLog.e("MqttManager>>>Reconnection failed" + e.getMessage());
+                    // 鍙互鍦ㄨ繖閲屽鍔犻噸杩炲皾璇曟鏁扮殑闄愬埗
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt(); // 淇濈暀涓柇鐘舵��
+                    return;
+                }
+            }
+        });
     }
 }
diff --git a/app/src/main/java/com/dayu/pipirrapp/tool/MarkerUtils.java b/app/src/main/java/com/dayu/pipirrapp/tool/MarkerUtils.java
index 281cb2c..cf38887 100644
--- a/app/src/main/java/com/dayu/pipirrapp/tool/MarkerUtils.java
+++ b/app/src/main/java/com/dayu/pipirrapp/tool/MarkerUtils.java
@@ -25,7 +25,7 @@
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread()).subscribe(markerBeans -> {
                     for (MarkerBean bean : markerBeans) {
-                        fragment.setMapMarker(bean);
+//                        fragment.setMapMarker(bean);
                     }
                 });
         return disposable;
diff --git a/app/src/main/java/com/dayu/pipirrapp/tool/MyWebViewInterface.java b/app/src/main/java/com/dayu/pipirrapp/tool/MyWebViewInterface.java
index 525bd15..fb6fd97 100644
--- a/app/src/main/java/com/dayu/pipirrapp/tool/MyWebViewInterface.java
+++ b/app/src/main/java/com/dayu/pipirrapp/tool/MyWebViewInterface.java
@@ -11,7 +11,7 @@
  * author: zuo
  * Date: 2024-01-18
  * Time: 9:14
- * 澶囨敞锛氫緵Vue璋冪敤鍘熺敓
+ * 澶囨敞锛氫緵js璋冪敤鍘熺敓
  */
 public class MyWebViewInterface {
 
@@ -81,5 +81,21 @@
         }
     }
 
+    /**
+     * 鍒锋柊鍦板浘涓績鐐瑰潗鏍�
+     */
+    @JavascriptInterface
+    public void refreshCenter(double lng, double lat) {
+        if (myContext instanceof MapFragment) {
+            new Handler(Looper.getMainLooper()).post(new Runnable() {
+                @Override
+                public void run() {
+                    // 鍦ㄤ富绾跨▼涓婃墽琛孶I鎿嶄綔
+                    // 鏇存柊鎴栨搷浣淯I鍏冪礌鐨勪唬鐮�
+                    myContext.refreshCenterPoint(lng, lat);
 
+                }
+            });
+        }
+    }
 }
diff --git a/app/src/main/res/layout/fragment_map.xml b/app/src/main/res/layout/fragment_map.xml
index c2f0355..a897113 100644
--- a/app/src/main/res/layout/fragment_map.xml
+++ b/app/src/main/res/layout/fragment_map.xml
@@ -9,9 +9,10 @@
     <!--        android:layout_height="match_parent" />-->
 
     <RelativeLayout
+        android:id="@+id/webViewRL"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_above="@+id/bottomLL">
+        >
 
 
         <WebView
@@ -20,12 +21,14 @@
             android:layout_height="match_parent" />
 
         <ImageView
+            android:id="@+id/pointCenterImg"
             android:layout_width="26dp"
             android:layout_height="52dp"
             android:layout_centerHorizontal="true"
             android:layout_centerVertical="true"
             android:paddingBottom="26dp"
-            android:src="@drawable/ic_center_pin" />
+            android:src="@drawable/ic_center_pin"
+            android:visibility="gone" />
     </RelativeLayout>
 
     <RelativeLayout
@@ -81,7 +84,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
-        android:layout_marginTop="80dp"
+        android:layout_marginTop="60dp"
         android:layout_marginRight="15dp"
         android:background="@drawable/ic_blue_background"
         android:padding="10dp"
@@ -95,7 +98,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
-        android:layout_marginTop="140dp"
+        android:layout_marginTop="120dp"
         android:layout_marginRight="15dp"
         android:background="@drawable/ic_green_bg"
         android:padding="10dp"
@@ -105,11 +108,42 @@
 
 
     <RelativeLayout
+        android:id="@+id/pointRL"
         android:layout_width="match_parent"
         android:layout_height="35dp"
         android:layout_above="@+id/bottomLL"
-        android:background="@color/white">
+        android:background="@color/white"
+        android:visibility="gone">
 
+        <TextView
+            android:id="@+id/pointCancel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="5dp"
+            android:padding="5dp"
+            android:text="鍙栨秷"
+            android:textSize="@dimen/common_text_size_little" />
+
+        <TextView
+            android:id="@+id/pointText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerHorizontal="true"
+            android:layout_centerVertical="true"
+            android:textSize="@dimen/common_text_size_little" />
+
+        <TextView
+            android:id="@+id/pointEdt"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:layout_centerVertical="true"
+            android:layout_marginRight="5dp"
+            android:padding="5dp"
+            android:text="淇敼"
+            android:textColor="@color/base_blue"
+            android:textSize="@dimen/common_text_size_little" />
     </RelativeLayout>
 
     <LinearLayout
@@ -118,8 +152,13 @@
         android:layout_height="120dp"
         android:layout_alignParentBottom="true"
         android:background="@color/white"
-        android:orientation="horizontal"
+        android:orientation="vertical"
         android:visibility="gone">
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="2px"
+            android:background="@color/line_bg" />
 
         <ScrollView
             android:layout_width="match_parent"
@@ -136,7 +175,7 @@
 
                 <LinearLayout
                     android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
+                    android:layout_height="25dp"
                     android:gravity="center_vertical"
                     android:orientation="horizontal">
 
@@ -146,6 +185,7 @@
                         android:layout_height="25dp"
                         android:layout_centerVertical="true"
                         android:layout_marginRight="10dp"
+                        android:padding="3dp"
                         android:src="@drawable/ic_intake" />
 
                     <TextView
@@ -185,7 +225,7 @@
 
                 <LinearLayout
                     android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
+                    android:layout_height="25dp"
                     android:gravity="center_vertical"
                     android:orientation="horizontal">
 
@@ -228,15 +268,15 @@
                         android:id="@+id/editePoint"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:padding="5dp"
+                        android:padding="2dp"
                         android:src="@drawable/ic_edit_btn" />
                 </LinearLayout>
 
                 <LinearLayout
                     android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
+                    android:layout_height="25dp"
                     android:layout_marginBottom="10dp"
-                    android:gravity="start"
+                    android:gravity="center"
                     android:orientation="horizontal">
 
                     <TextView

--
Gitblit v1.8.0