管灌系统巡查员智能手机App
zuoxiao
2025-01-13 50f9b82ac862652e88444d727a32e0da1d824e9e
app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
@@ -17,7 +17,6 @@
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -32,13 +31,13 @@
import com.dayu.pipirrapp.bean.db.LatLonBean;
import com.dayu.pipirrapp.bean.db.MarkerBean;
import com.dayu.pipirrapp.bean.net.CenterPointResult;
import com.dayu.pipirrapp.bean.net.DivideResult;
import com.dayu.pipirrapp.bean.net.InsectionResult;
import com.dayu.pipirrapp.bean.net.InspectionRequest;
import com.dayu.pipirrapp.bean.net.MarkerListResult;
import com.dayu.pipirrapp.bean.net.MarkerResult;
import com.dayu.pipirrapp.dao.DaoSingleton;
import com.dayu.pipirrapp.databinding.FragmentMapBinding;
import com.dayu.pipirrapp.tool.MyWebViewInterface;
import com.dayu.pipirrapp.net.ApiManager;
import com.dayu.pipirrapp.net.BaseResponse;
import com.dayu.pipirrapp.net.Constants;
@@ -46,6 +45,7 @@
import com.dayu.pipirrapp.observer.MapFragmenObserver;
import com.dayu.pipirrapp.tool.InspectionUtils;
import com.dayu.pipirrapp.tool.MarkerUtils;
import com.dayu.pipirrapp.tool.MyWebViewInterface;
import com.dayu.pipirrapp.utils.CommonData;
import com.dayu.pipirrapp.utils.CommonKeyName;
import com.dayu.pipirrapp.utils.DateUtils;
@@ -339,7 +339,6 @@
        MyLog.i(data);
        MarkerBean markerBean = markerBeanSet.get(data);
        if (markerBean != null) {
            setWebViewParams(false);
            getInstakeDetail(markerBean);
        }
@@ -398,6 +397,7 @@
                try {
                    if (t.isSuccess()) {
                        if (t.getContent() != null) {
                            MyLog.d("InspectId:" + String.valueOf(t.getContent().get(0).getInspectId()));
                            mInspectionBean.setInspectId(String.valueOf(t.getContent().get(0).getInspectId()));
                            InspectionUtils.upataInspectionData(MapFragment.this.getContext(), mInspectionBean);
                        }
@@ -429,6 +429,7 @@
                    lastLatLonBean = latLonBean;
                    Log.i("chageInspecState", "lat:" + latLonBean.getLatitude() + ",log:" + latLonBean.getLongitude());
                    InspectionLocationBean inspectionLocationBean = InspectionUtils.createInspectionLocation(latLonBean, mInspectionBean);
                    //添加巡检记录坐标
                    InspectionUtils.addInspectionLocationData(MapFragment.this.getContext(), inspectionLocationBean);
                    //更新到地图
                    mWebView.evaluateJavascript("javascript:updateInspectionLocation(\"" + latLonBean.getLongitude() + "\",\"" + latLonBean.getLatitude() + "\")", value -> {
@@ -556,13 +557,16 @@
    public void setMapMarker(MarkerBean markerBean) {
        if (markerBean != null) {
            if (webViewIsFinished) {
                mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                    }
                });
                markerBeanSet.put(markerBean.getId(), markerBean);
                if (!TextUtils.isEmpty(markerBean.getLng()) && !TextUtils.isEmpty(markerBean.getLat())) {
                    mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() {
                        @Override
                        public void onReceiveValue(String value) {
                        }
                    });
                    markerBeanSet.put(markerBean.getId(), markerBean);
                } else {
                    MyLog.d("setMapMarker>" + markerBean.getName() + "经纬度为空");
                }
            } else {
                webNoFinishMarkerData.add(markerBean);
            }
@@ -577,7 +581,7 @@
     */
    private void startLocation() {
        //获取定位服务传过来的坐标点
        LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver);
        LiveEventBus.get(CommonKeyName.locationData).observe(this, locationObserver);
        binding.inspectRL.setVisibility(View.VISIBLE);
        binding.inspectButton.setVisibility(View.GONE);
        binding.inspectPause.setText("暂停");
@@ -726,17 +730,20 @@
        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);
                MyLog.d("showPin>>" + 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 -> {
                    });
                }
        );
@@ -750,14 +757,45 @@
        });
    }
    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);
    /**
     * 获取分水房
     */
    private void getDivideList() {
        ApiManager.getInstance().requestPost(MapFragment.this.getContext(), BASE_URL + "/project/divide/getDivides", DivideResult.class, null, new SubscriberListener<BaseResponse<DivideResult>>() {
            @Override
            public void onNext(BaseResponse<DivideResult> t) {
                try {
                    if (t.isSuccess()) {
//                       if (t.getContent().)
//
//
//                        // 使用 RxJava 异步插入数据
//                        DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).markerDao().insertAll()
//                                .subscribeOn(Schedulers.io()) // 在 IO 线程上执行
//                                .observeOn(AndroidSchedulers.mainThread()) // 在主线程上观察
//                                .subscribe(() -> {
//                                    // 插入成功
//                                    Log.i("mWebView", "数据插入成功");
//                                }, throwable -> {
//                                    // 插入失败
//                                    Log.e("mWebView", "数据插入失败: " + throwable.getMessage());
//                                });
                    } else {
                        ToastUtil.showToastLong(MapFragment.this.getContext(), t.getMsg());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    CrashReport.postCatchedException(e);
                }
            }
        });
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver);
    }
}