| | |
| | | import com.dayu.pipirrapp.R; |
| | | import com.dayu.pipirrapp.activity.AddIssueActivity; |
| | | import com.dayu.pipirrapp.bean.db.CenterPointBean; |
| | | import com.dayu.pipirrapp.bean.db.DivideBean; |
| | | import com.dayu.pipirrapp.bean.db.InspectionBean; |
| | | import com.dayu.pipirrapp.bean.db.InspectionLocationBean; |
| | | import com.dayu.pipirrapp.bean.db.LatLonBean; |
| | | import com.dayu.pipirrapp.bean.db.MarkerBean; |
| | | import com.dayu.pipirrapp.bean.db.PipeNetworkBean; |
| | | import com.dayu.pipirrapp.bean.net.CenterPointResult; |
| | | import com.dayu.pipirrapp.bean.net.DivideListResult; |
| | | 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.bean.net.PipeNetworkListResult; |
| | | import com.dayu.pipirrapp.bean.net.PipeNetworkResult; |
| | | import com.dayu.pipirrapp.dao.DaoSingleton; |
| | | import com.dayu.pipirrapp.databinding.FragmentMapBinding; |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | |
| | | List<InspectionLocationBean> aginShowlocationBeans; |
| | | //web加载时网页还没加载完时的数据 |
| | | List<MarkerBean> webNoFinishMarkerData = new ArrayList<>(); |
| | | List<DivideBean> webNoFinishDivideData = new ArrayList<>(); |
| | | //所有的Marker数据键为marker的Id |
| | | Map<String, MarkerBean> markerBeanSet = new HashMap<>(); |
| | | //所有分水房 |
| | | Map<String, DivideBean> divideBeanMap = new HashMap<>(); |
| | | //中心点坐标 |
| | | public double centerLng; |
| | | public double centerLat; |
| | |
| | | getCenterPoint(); |
| | | initView(); |
| | | initWeb(); |
| | | |
| | | getMarkerData(); |
| | | getDivideList(); |
| | | |
| | | chageInspecState(mInspectionState); |
| | | return binding.getRoot(); |
| | |
| | | super.onPageFinished(view, url); |
| | | //页面加载完成 |
| | | webViewIsFinished = true; |
| | | initLocalData(); |
| | | webFinishInitLocalData(); |
| | | aginShowLocation(null); |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 初始化本地数据 |
| | | * web加载完初始化本地数据 |
| | | */ |
| | | public void initLocalData() { |
| | | public void webFinishInitLocalData() { |
| | | //跳转中心点 |
| | | centerPointBean = DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().findFirst(); |
| | | jumpCenterPoint(); |
| | |
| | | if (!webNoFinishMarkerData.isEmpty()) { |
| | | for (MarkerBean bean : webNoFinishMarkerData) { |
| | | setMapMarker(bean); |
| | | } |
| | | } |
| | | if (!webNoFinishDivideData.isEmpty()) { |
| | | for (DivideBean bean : webNoFinishDivideData) { |
| | | setMapDivide(bean); |
| | | } |
| | | } |
| | | //显示所有取水口 |
| | |
| | | @Override |
| | | public void onNext(BaseResponse<MarkerListResult> t) { |
| | | if (t.isSuccess()) { |
| | | |
| | | if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) { |
| | | |
| | | List<MarkerBean> markerBeans = t.getContent().getObj().stream() |
| | | .map(result -> { |
| | | MarkerBean markerBean = new MarkerBean(); |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 显示分水房详情 |
| | | * |
| | | * @param data |
| | | */ |
| | | public void showDivideDetail(String data) { |
| | | MyLog.i(data); |
| | | DivideBean markerBean = divideBeanMap.get(data); |
| | | if (markerBean != null) { |
| | | binding.bottomLL.setVisibility(View.GONE); |
| | | getDivideDetail(markerBean); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取地图中心点 |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加取水口标注 |
| | | */ |
| | | public void setMapDivide(DivideBean divide) { |
| | | if (divide != null) { |
| | | if (webViewIsFinished) { |
| | | if (!TextUtils.isEmpty(divide.getLng()) && !TextUtils.isEmpty(divide.getLat())) { |
| | | mWebView.evaluateJavascript("javascript:addDivide(\"" + divide.getId() + "\",\"" + divide.getLng() + "\",\"" + divide.getLat() + "\",\"" + divide.getDivideName() + "\")", new ValueCallback<String>() { |
| | | @Override |
| | | public void onReceiveValue(String value) { |
| | | } |
| | | }); |
| | | divideBeanMap.put(divide.getId(), divide); |
| | | } else { |
| | | MyLog.d("setMapDivide>" + divide.getDivideName() + "经纬度为空"); |
| | | } |
| | | } else { |
| | | webNoFinishDivideData.add(divide); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加取水口标注 |
| | | */ |
| | | public void setMapDivide(PipeNetworkBean pipeNetworkBean) { |
| | | // if (divide != null) { |
| | | // if (webViewIsFinished) { |
| | | // for () |
| | | // if (!TextUtils.isEmpty(divide.getLng()) && !TextUtils.isEmpty(divide.getLat())) { |
| | | // mWebView.evaluateJavascript("javascript:addDivide(\"" + divide.getId() + "\",\"" + divide.getLng() + "\",\"" + divide.getLat() + "\",\"" + divide.getDivideName() + "\")", new ValueCallback<String>() { |
| | | // @Override |
| | | // public void onReceiveValue(String value) { |
| | | // } |
| | | // }); |
| | | // divideBeanMap.put(divide.getId(), divide); |
| | | // } else { |
| | | // MyLog.d("setMapDivide>" + divide.getDivideName() + "经纬度为空"); |
| | | // } |
| | | // } else { |
| | | // webNoFinishDivideData.add(divide); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * 开始巡检的相关逻辑 |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 显示取水口详情 |
| | | */ |
| | | private void getDivideDetail(DivideBean divideBean) { |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + "/project/divide/getone/" + divideBean.getDivideId(), DivideResult.class, null, new SubscriberListener<BaseResponse<DivideResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<DivideResult> t) { |
| | | if (t.isSuccess()) { |
| | | DivideBean divideBean = getDivideBean(t.getContent()); |
| | | showDivideMarker(divideBean); |
| | | } else { |
| | | ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg()); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 显示取水口详情 |
| | | */ |
| | | private void showMarker(MarkerBean markerBean) { |
| | | binding.bottomLL.setVisibility(View.VISIBLE); |
| | | binding.phoneLL.setVisibility(View.GONE); |
| | | binding.headerLL.setVisibility(View.GONE); |
| | | binding.editePoint.setVisibility(View.VISIBLE); |
| | | binding.markerAddress.setText(markerBean.getAddress()); |
| | | binding.markerName.setText(markerBean.getName()); |
| | | binding.markerBlockName.setText(markerBean.getBlockName()); |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 显示分水房详情 |
| | | * |
| | | * @param divideBean |
| | | */ |
| | | private void showDivideMarker(DivideBean divideBean) { |
| | | binding.bottomLL.setVisibility(View.VISIBLE); |
| | | binding.phoneLL.setVisibility(View.VISIBLE); |
| | | binding.headerLL.setVisibility(View.VISIBLE); |
| | | binding.editePoint.setVisibility(View.GONE); |
| | | binding.markerAddress.setText(divideBean.getAddress()); |
| | | binding.markerName.setText(divideBean.getDivideName()); |
| | | binding.markerBlockName.setText(divideBean.getBlockName()); |
| | | binding.phone.setText(divideBean.getPhone()); |
| | | binding.header.setText(divideBean.getHeader()); |
| | | binding.lat.setText(divideBean.getLat()); |
| | | binding.lng.setText(divideBean.getLng()); |
| | | //修改经纬度 |
| | | binding.editePoint.setOnClickListener(v -> { |
| | | |
| | | mWebView.evaluateJavascript("javascript:showPin(\"" + divideBean.getLng() + "\",\"" + divideBean.getLat() + "\")", value -> { |
| | | binding.pointRL.setVisibility(View.VISIBLE); |
| | | binding.pointCenterImg.setVisibility(View.VISIBLE); |
| | | MyLog.d("showPin>>" + value); |
| | | }); |
| | | |
| | | }); |
| | | //取消修改经纬度 |
| | | 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 getDivideList() { |
| | | ApiManager.getInstance().requestGetHideLoading(MapFragment.this.getContext(), BASE_URL + "/project/divide/getDivides", DivideListResult.class, null, new SubscriberListener<BaseResponse<DivideListResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<DivideListResult> t) { |
| | | try { |
| | | if (t.isSuccess()) { |
| | | if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) { |
| | | |
| | | List<DivideBean> divideBeans = new ArrayList<>(); |
| | | for (DivideResult divideResult : t.getContent().getObj()) { |
| | | DivideBean divideBean = getDivideBean(divideResult); |
| | | setMapDivide(divideBean); |
| | | divideBeans.add(divideBean); |
| | | } |
| | | // 使用 RxJava 异步插入数据 |
| | | DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).divideDao().insertAll(divideBeans) |
| | | .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); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取管网 |
| | | */ |
| | | private void getPipeNetworkList() { |
| | | ApiManager.getInstance().requestGetHideLoading(MapFragment.this.getContext(), BASE_URL + "/project/network/all", PipeNetworkListResult.class, null, new SubscriberListener<BaseResponse<PipeNetworkListResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<PipeNetworkListResult> t) { |
| | | try { |
| | | if (t.isSuccess()) { |
| | | if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) { |
| | | |
| | | List<DivideBean> divideBeans = new ArrayList<>(); |
| | | for (PipeNetworkResult divideResult : t.getContent().getObj()) { |
| | | PipeNetworkBean divideBean = getPipeNetworkBean(divideResult); |
| | | setMapDivide(divideBean); |
| | | // divideBeans.add(divideBean); |
| | | } |
| | | // 使用 RxJava 异步插入数据 |
| | | DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).divideDao().insertAll(divideBeans) |
| | | .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); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * @param divideResult |
| | | * @return |
| | | */ |
| | | private static @NonNull DivideBean getDivideBean(DivideResult divideResult) { |
| | | DivideBean divideBean = new DivideBean(); |
| | | divideBean.setAddress(divideResult.getAddress()); |
| | | divideBean.setBlockId(divideResult.getBlockId()); |
| | | divideBean.setBlockName(divideResult.getBlockName()); |
| | | divideBean.setDivideId(divideResult.getDivideId()); |
| | | if (!TextUtils.isEmpty(divideResult.getDivideName())) { |
| | | divideBean.setDivideName(divideResult.getDivideName()); |
| | | } else { |
| | | divideBean.setDivideName(divideResult.getName()); |
| | | } |
| | | |
| | | divideBean.setHeader(divideResult.getHeader()); |
| | | divideBean.setId(divideResult.getId()); |
| | | divideBean.setLat(divideResult.getLat()); |
| | | divideBean.setLng(divideResult.getLng()); |
| | | divideBean.setOperateDt(divideResult.getOperateDt()); |
| | | divideBean.setOperator(divideResult.getOperator()); |
| | | divideBean.setPhone(divideResult.getPhone()); |
| | | divideBean.setRemarks(divideResult.getRemarks()); |
| | | divideBean.setVillages(divideResult.getVillages()); |
| | | divideBean.setArea(divideResult.getArea()); |
| | | return divideBean; |
| | | } |
| | | |
| | | private static @NonNull PipeNetworkBean getPipeNetworkBean(PipeNetworkResult divideResult) { |
| | | PipeNetworkBean pipeNetworkBean = new PipeNetworkBean(); |
| | | |
| | | return pipeNetworkBean; |
| | | } |
| | | |
| | | @Override |
| | | public void onDestroy() { |