From ec6193939600ca7930193b1d5942b1700baf9e06 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期五, 21 二月 2025 09:20:15 +0800 Subject: [PATCH] 1.巡检记录列表页的实现 2.巡检记录地图展示路径的详情页。 3.处理巡检记录详情页因打开同一个网址导致的webView不显示问题。 4.实现地图页搜索后的地图跳转功能。 5.巡检记录详情页数据加载的优化,默认加载本地数据,当本地没有数据时从服务端获取数据。 --- app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java | 431 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 352 insertions(+), 79 deletions(-) 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 39ec637..82ab38e 100644 --- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java +++ b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import androidx.lifecycle.Observer; import com.dayu.pipirrapp.MyApplication; @@ -31,7 +32,9 @@ 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.PipeNetWorkDataBean; import com.dayu.pipirrapp.bean.db.PipeNetworkBean; +import com.dayu.pipirrapp.bean.db.PipeNetworkDataCoordinateBean; import com.dayu.pipirrapp.bean.net.CenterPointResult; import com.dayu.pipirrapp.bean.net.DivideListResult; import com.dayu.pipirrapp.bean.net.DivideResult; @@ -39,7 +42,6 @@ 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; @@ -61,7 +63,9 @@ import com.dayu.pipirrapp.utils.ToastUtil; import com.dayu.pipirrapp.utils.WebViewUtils; import com.dayu.pipirrapp.view.ConfirmDialog; +import com.dayu.pipirrapp.view.SearchResultDialog; import com.dayu.pipirrapp.view.TipUtil; +import com.example.expand_button.ExpandButton; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; @@ -78,6 +82,7 @@ import java.util.stream.Collectors; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; +import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.schedulers.Schedulers; /** @@ -106,6 +111,7 @@ //web鍔犺浇鏃剁綉椤佃繕娌″姞杞藉畬鏃剁殑鏁版嵁 List<MarkerBean> webNoFinishMarkerData = new ArrayList<>(); List<DivideBean> webNoFinishDivideData = new ArrayList<>(); + List<PipeNetworkBean> webNoFinishPipeNetworkData = new ArrayList<>(); //鎵�鏈夌殑Marker鏁版嵁閿负marker鐨処d Map<String, MarkerBean> markerBeanSet = new HashMap<>(); //鎵�鏈夊垎姘存埧 @@ -115,6 +121,12 @@ public double centerLat; MarkerBean mMarkerBean; + + //鏄惁鏄剧ずMarker + boolean isShowMarker, isShowPipeNetwork, isShowDivide; + + // 娣诲姞CompositeDisposable鏉ョ鐞嗘墍鏈夎闃� + private CompositeDisposable compositeDisposable = new CompositeDisposable(); @Override public void onAttach(@NonNull Context context) { @@ -130,6 +142,14 @@ setRetainInstance(true); Log.i(TAG, "onCreate"); mInspectionState = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.inspectionState, 0); + + // 娣诲姞鍒锋柊鏁版嵁鐨勭洃鍚� + LiveEventBus.get(CommonKeyName.refreshData).observe(this, o -> { + getCenterPoint(); + getMarkerData(); + getDivideList(); + getPipeNetworkList(); + }); } @Override @@ -142,7 +162,6 @@ @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - binding = FragmentMapBinding.inflate(inflater, container, false); mapFragmenObserver.setmWebView(binding.webView); Log.i("MapFragment", "onCreateView"); @@ -151,15 +170,112 @@ MyWebViewInterface myWebViewInterface = new MyWebViewInterface(MapFragment.this); mWebView.addJavascriptInterface(myWebViewInterface, "Android"); mWebView.loadUrl("file:///android_asset/index.html"); - getCenterPoint(); + + // 寮傛鍔犺浇鏈湴鏁版嵁 + loadLocalData(); + initView(); initWeb(); - getMarkerData(); - getDivideList(); - chageInspecState(mInspectionState); return binding.getRoot(); + } + + /** + * 寮傛鍔犺浇鏈湴鏁版嵁 + */ + private void loadLocalData() { + + + // 寮傛鍔犺浇涓績鐐规暟鎹� + compositeDisposable.add( + DaoSingleton.getAsynchInstance(this.getContext()).centerPointDao().findFirst() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + centerPointBean = result; + if (centerPointBean == null) { + getCenterPoint(); + } else { + jumpCenterPoint(); + } + }, throwable -> { + Log.e(TAG, "Load centerPoint error: " + throwable); + getCenterPoint(); + }, () -> { + // 褰揗aybe涓虹┖鏃惰皟鐢� + getCenterPoint(); + }) + ); + isShowMarker = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.markerKeyIsShow, true); + // 寮傛鍔犺浇鍙栨按鍙f暟鎹� + compositeDisposable.add( + DaoSingleton.getAsynchInstance(this.getContext()).markerDao().getAll() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(markers -> { + if (markers == null || markers.isEmpty()) { + getMarkerData(); + } else { + for (MarkerBean marker : markers) { + markerBeanSet.put(marker.getId(), marker); + setMapMarker(marker); + } + } + }, throwable -> { + Log.e(TAG, "Load markers error: " + throwable.getMessage()); + getMarkerData(); + }, () -> { + // 褰揗aybe涓虹┖鏃惰皟鐢� + getMarkerData(); + }) + ); + isShowDivide = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.divideIsShow, true); + // 寮傛鍔犺浇鍒嗘按鎴挎暟鎹� + compositeDisposable.add( + DaoSingleton.getAsynchInstance(this.getContext()).divideDao().getAll() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(divides -> { + if (divides == null || divides.isEmpty()) { + getDivideList(); + } else { + for (DivideBean divide : divides) { + divideBeanMap.put(divide.getId(), divide); + setMapDivide(divide); + } + } + }, throwable -> { + Log.e(TAG, "Load divides error: " + throwable.getMessage()); + getDivideList(); + }, () -> { + // 褰揗aybe涓虹┖鏃惰皟鐢� + getDivideList(); + }) + ); + + isShowPipeNetwork = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.pipeNetworkIsShow, true); + //寮傛鍔犺浇绠$綉鏁版嵁 + compositeDisposable.add( + DaoSingleton.getAsynchInstance(this.getContext()).pipeNetDao().getAll() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(pipeNetworkBeans -> { + if (pipeNetworkBeans == null || pipeNetworkBeans.isEmpty()) { + getPipeNetworkList(); + } else { + for (PipeNetworkBean pipeNetworkBean : pipeNetworkBeans) { + setMapPipe(pipeNetworkBean); + } + } + }, throwable -> { + Log.e(TAG, "Load PipeNetworkBean error: " + throwable.getMessage()); + getPipeNetworkList(); + }, () -> { + // 褰揗aybe涓虹┖鏃惰皟鐢� + getPipeNetworkList(); + }) + ); } private void initWeb() { @@ -232,9 +348,10 @@ * web鍔犺浇瀹屽垵濮嬪寲鏈湴鏁版嵁 */ public void webFinishInitLocalData() { - //璺宠浆涓績鐐� - centerPointBean = DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().findFirst(); - jumpCenterPoint(); + // 鍙湪鏈湴娌℃湁鏁版嵁鏃惰幏鍙栦腑蹇冪偣 + if (centerPointBean != null) { + jumpCenterPoint(); + } //娣诲姞鍥爓ebview娌℃湁鍔犺浇瀹屾垚瀵艰嚧娌℃湁娣诲姞鐨勫湴鍥炬爣娉� if (!webNoFinishMarkerData.isEmpty()) { for (MarkerBean bean : webNoFinishMarkerData) { @@ -246,6 +363,12 @@ setMapDivide(bean); } } + if (!webNoFinishPipeNetworkData.isEmpty()) { + for (PipeNetworkBean bean : webNoFinishPipeNetworkData) { + setMapPipe(bean); + } + } + //鏄剧ず鎵�鏈夊彇姘村彛 MarkerUtils.showLocoMarks(MapFragment.this); //鏄剧ず宸℃鐘舵�佸苟涓旀樉绀哄洜鎰忓鍏抽棴鐨勫巻鍙叉暟鎹� @@ -284,19 +407,23 @@ 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()); - }); + // 浣跨敤 CompositeDisposable 绠$悊鏁版嵁搴撴彃鍏ユ搷浣� + compositeDisposable.add( + DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).markerDao().insertAll(markerBeans) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + () -> { + // 鎻掑叆鎴愬姛 + Log.i("mWebView", "鏁版嵁鎻掑叆鎴愬姛"); + }, + throwable -> { + // 鎻掑叆澶辫触 + Log.e("mWebView", "鏁版嵁鎻掑叆澶辫触: " + throwable.getMessage()); + } + ) + ); } } else { @@ -313,7 +440,7 @@ //宸℃鎸夐挳 binding.inspectButton.setOnClickListener(v -> { if (XXPermissions.isGranted(MapFragment.this.getContext(), Permission.ACCESS_BACKGROUND_LOCATION)) { - new ConfirmDialog(MapFragment.this.getActivity(), (confirmDialog, v1) -> { + new ConfirmDialog(MapFragment.this.getActivity(), "纭寮�濮嬪贰妫�鍚楋紵",(confirmDialog, v1) -> { chageInspecState(InspectionUtils.STAT_INSPECTION_ONCLICK); confirmDialog.dismiss(); }).show(); @@ -345,9 +472,88 @@ Intent issue = new Intent(MapFragment.this.getActivity(), AddIssueActivity.class); MapFragment.this.getActivity().startActivity(issue); }); + binding.expandButton.setLegendsArray(new ExpandButton.Quadruple( + ContextCompat.getDrawable(requireContext(), R.drawable.marker_blue), + ContextCompat.getDrawable(requireContext(), R.drawable.marker_unselected), + "鍙栨按鍙�", isShowMarker + ), + new ExpandButton.Quadruple( + ContextCompat.getDrawable(requireContext(), R.drawable.divide_home_blue), + ContextCompat.getDrawable(requireContext(), R.drawable.divide_home_unselected), + "鍒嗘按鎴�", isShowDivide + ), + new ExpandButton.Quadruple( + ContextCompat.getDrawable(requireContext(), R.drawable.ic_pipenetwork_line), + ContextCompat.getDrawable(requireContext(), R.drawable.ic_pipenetwork_line_unselected), + "绠$綉", isShowPipeNetwork + ) + ); + binding.expandButton.setOnLegendItemClickListener((position, isSelected) -> { + switch (position) { + case 0: + showMarkers(isSelected); + SharedPreferencesHelper.getInstance(this.getContext()).put(CommonKeyName.markerKeyIsShow, isSelected); + break; + case 1: + showDivideMarkers(isSelected); + SharedPreferencesHelper.getInstance(this.getContext()).put(CommonKeyName.divideIsShow, isSelected); + break; + case 2: + showPipeLine(isSelected); + SharedPreferencesHelper.getInstance(this.getContext()).put(CommonKeyName.pipeNetworkIsShow, isSelected); + break; - + } + }); + binding.searchButton.setOnSearchClickListener(s -> { + if (s != null && !s.isEmpty()) { + SearchResultDialog searchDialog = new SearchResultDialog(requireContext()); + searchDialog.setOnItemClickListener(item -> { + // 鏍规嵁绫诲瀷澶勭悊鐐瑰嚮浜嬩欢 +// if ("marker".equals(item.getType())) { +// MarkerBean markerBean = new MarkerBean(); +// markerBean.setId(item.getId()); +// getInstakeDetail(markerBean); +// } else { +// DivideBean divideBean = new DivideBean(); +// divideBean.setDivideId(item.getId()); +// getDivideDetail(divideBean); +// } + // 璺宠浆鍒伴�夋嫨鐨勪綅缃� + mWebView.evaluateJavascript( + String.format("javascript:setCenterAndZoom(\"%s\",\"%s\",\"17\")", + item.getLng(), + item.getLat()), + null + ); + }); + + // 鎵ц鎼滅储 + compositeDisposable.add( + DaoSingleton.getAsynchInstance(requireContext()) + .divideDao() + .searchAllByKeyword(s) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + results -> { + if (results != null && !results.isEmpty()) { + searchDialog.setData(results); + searchDialog.show(); + } else { + ToastUtil.showToast(requireContext(), "鏈壘鍒扮浉鍏崇粨鏋�"); + } + }, + throwable -> { + ToastUtil.showToast(requireContext(), "鎼滅储澶辫触锛�" + throwable.getMessage()); + } + ) + ); + } + return null; + }); } + /** * 鏄剧ず鍙栨按鍙h鎯� @@ -392,6 +598,7 @@ centerPointBean.setLat(t.getContent().getLat()); centerPointBean.setLng(t.getContent().getLng()); centerPointBean.setZoomMp(t.getContent().getZoomMp()); + DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().deleteAll(); DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().insert(centerPointBean); jumpCenterPoint(); } else { @@ -585,13 +792,13 @@ } /** - * 娣诲姞鏍囨敞鐐� + * 娣诲姞鍙栨按鍙� */ public void setMapMarker(MarkerBean markerBean) { if (markerBean != null) { if (webViewIsFinished) { if (!TextUtils.isEmpty(markerBean.getLng()) && !TextUtils.isEmpty(markerBean.getLat())) { - mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() { + mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\",\"" + isShowMarker + "\")", new ValueCallback<String>() { @Override public void onReceiveValue(String value) { } @@ -607,13 +814,13 @@ } /** - * 娣诲姞鍙栨按鍙f爣娉� + * 娣诲姞鍒嗘按鎴� */ 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>() { + mWebView.evaluateJavascript("javascript:addDivide(\"" + divide.getId() + "\",\"" + divide.getLng() + "\",\"" + divide.getLat() + "\",\"" + divide.getDivideName() + "\",\"" + isShowDivide + "\")", new ValueCallback<String>() { @Override public void onReceiveValue(String value) { } @@ -629,26 +836,26 @@ } /** - * 娣诲姞鍙栨按鍙f爣娉� + * 娣诲姞绠$綉鏍囨敞 */ - 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); -// } -// } + public void setMapPipe(PipeNetworkBean pipeNetworkBean) { + if (pipeNetworkBean != null) { + if (webViewIsFinished) { + boolean isfrist = true; + for (PipeNetworkDataCoordinateBean data : pipeNetworkBean.getData().getCoordinates()) { + if (!TextUtils.isEmpty(data.getLat()) && !TextUtils.isEmpty(data.getLng())) { + mWebView.evaluateJavascript("javascript:addPipeNetwork(\"" + data.getLng() + "\",\"" + data.getLat() + "\",\"" + isfrist + "\",\"" + isShowPipeNetwork +"\")", new ValueCallback<String>() { + @Override + public void onReceiveValue(String value) { + } + }); + isfrist = false; + } + } + } else { + webNoFinishPipeNetworkData.add(pipeNetworkBean); + } + } } /** @@ -917,27 +1124,30 @@ 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()); - }); + DaoSingleton.getInstance(MapFragment.this.getContext()).divideDao().deleteAll(); + // 浣跨敤 CompositeDisposable 绠$悊鏁版嵁搴撴彃鍏ユ搷浣� + compositeDisposable.add( + DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).divideDao().insertAll(divideBeans) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + () -> { + // 鎻掑叆鎴愬姛 + Log.i("mWebView", "鏁版嵁鎻掑叆鎴愬姛"); + }, + throwable -> { + // 鎻掑叆澶辫触 + Log.e("mWebView", "鏁版嵁鎻掑叆澶辫触: " + throwable.getMessage()); + } + ) + ); } - - } else { ToastUtil.showToastLong(MapFragment.this.getContext(), t.getMsg()); } @@ -946,7 +1156,6 @@ CrashReport.postCatchedException(e); } } - }); } @@ -954,30 +1163,48 @@ * 鑾峰彇绠$綉 */ private void getPipeNetworkList() { - ApiManager.getInstance().requestGetHideLoading(MapFragment.this.getContext(), BASE_URL + "/project/network/all", PipeNetworkListResult.class, null, new SubscriberListener<BaseResponse<PipeNetworkListResult>>() { + ApiManager.getInstance().requestGetHideLoading(MapFragment.this.getContext(), BASE_URL + "/project/network/all", PipeNetworkResult.class, null, new SubscriberListener<BaseResponse<List<PipeNetworkResult>>>() { @Override - public void onNext(BaseResponse<PipeNetworkListResult> t) { + public void onNext(BaseResponse<List<PipeNetworkResult>> t) { try { if (t.isSuccess()) { - if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) { + if (t.getContent() != null && t.getContent().size() > 0) { - List<DivideBean> divideBeans = new ArrayList<>(); - for (PipeNetworkResult divideResult : t.getContent().getObj()) { - PipeNetworkBean divideBean = getPipeNetworkBean(divideResult); - setMapDivide(divideBean); -// divideBeans.add(divideBean); + List<PipeNetworkBean> pipeNetBeans = new ArrayList<>(); + + for (PipeNetworkResult pipeNetworkResult : t.getContent()) { + PipeNetworkBean pipeNetBean = new PipeNetworkBean(); + pipeNetBean.setNetworkId(pipeNetworkResult.getNetworkId()); + pipeNetBean.setType(pipeNetworkResult.getType()); + PipeNetWorkDataBean data = new PipeNetWorkDataBean(); + data.setType(pipeNetworkResult.getData().getType()); + List<PipeNetworkDataCoordinateBean> coordinates = new ArrayList<>(); + for (PipeNetworkResult.Data.Coordinate dataBean : pipeNetworkResult.getData().getCoordinates()) { + PipeNetworkDataCoordinateBean coordinate = new PipeNetworkDataCoordinateBean(); + coordinate.setLat(dataBean.getLat()); + coordinate.setLng(dataBean.getLng()); + coordinates.add(coordinate); + } + data.setCoordinates(coordinates); + pipeNetBean.setData(data); + setMapPipe(pipeNetBean); + pipeNetBeans.add(pipeNetBean); } + + DaoSingleton.getInstance(MapFragment.this.getContext()).pipeNetDao().deleteAll(); // 浣跨敤 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()); - }); + compositeDisposable.add( + DaoSingleton.getAsynchInstance(MapFragment.this.getContext()).pipeNetDao().insertAll(pipeNetBeans) + .subscribeOn(Schedulers.io()) // 鍦� IO 绾跨▼涓婃墽琛� + .observeOn(AndroidSchedulers.mainThread()) // 鍦ㄤ富绾跨▼涓婅瀵� + .subscribe(() -> { + // 鎻掑叆鎴愬姛 + Log.i("mWebView", "鏁版嵁鎻掑叆鎴愬姛"); + }, throwable -> { + // 鎻掑叆澶辫触 + Log.e("mWebView", "鏁版嵁鎻掑叆澶辫触: " + throwable.getMessage()); + }) + ); } @@ -1031,6 +1258,10 @@ @Override public void onDestroy() { super.onDestroy(); + // 娓呯悊鎵�鏈夎闃� + if (compositeDisposable != null && !compositeDisposable.isDisposed()) { + compositeDisposable.dispose(); + } LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); if (mWebView != null) { mWebView.destroy(); @@ -1064,4 +1295,46 @@ mWebView.restoreState(savedInstanceState); } } + + /** + * 鏄剧ず鎴栭殣钘忓湴鍥句笂鐨勫彇姘村彛 + * + * @param isShow + */ + private void showMarkers(boolean isShow) { + if (isShow) { + mWebView.evaluateJavascript("javascript:showAllWaterIntakes()", value -> { + }); + } else { + mWebView.evaluateJavascript("javascript:hideAllWaterIntakes()", value -> { + }); + } + + } + + /** + * 鏄剧ず鎴栭殣钘忓湴鍥句笂鐨勫垎姘存埧 + * + * @param isShow + */ + private void showDivideMarkers(boolean isShow) { + if (isShow) { + mWebView.evaluateJavascript("javascript:showAllDivides()", value -> { + }); + } else { + mWebView.evaluateJavascript("javascript:hideAllDivides()", value -> { + }); + } + } + + private void showPipeLine(boolean isSelected) { + if (isSelected) { + mWebView.evaluateJavascript("javascript:showAllPipeLines()", value -> { + }); + } else { + mWebView.evaluateJavascript("javascript:hideAllPipeLines()", value -> { + }); + } + } + } -- Gitblit v1.8.0