管灌系统巡查员智能手机App
zuoxiao
2025-01-10 c2c902a3bf998632ffffa9c1508aceba7b5a7b45
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;
@@ -38,7 +37,6 @@
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 +44,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 +338,6 @@
        MyLog.i(data);
        MarkerBean markerBean = markerBeanSet.get(data);
        if (markerBean != null) {
            setWebViewParams(false);
            getInstakeDetail(markerBean);
        }
@@ -398,6 +396,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 +428,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 +556,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 +580,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 +729,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 +756,10 @@
        });
    }
    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);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver);
    }
}