| | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.bean.db.CenterPointBean; |
| | | import com.dayu.pipirrapp.bean.net.CenterPointResult; |
| | | import com.dayu.pipirrapp.bean.net.MarkerResult; |
| | | import com.dayu.pipirrapp.dao.DaoSingleton; |
| | | import com.dayu.pipirrapp.databinding.FragmentMapBinding; |
| | | import com.dayu.pipirrapp.js.MyWebViewInterface; |
| | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | |
| | | |
| | | WebView mWebView; |
| | | CenterPointBean centerPointBean; |
| | | String jsonData; |
| | | |
| | | @Override |
| | | public void onAttach(@NonNull Context context) { |
| | |
| | | mWebView.loadUrl("file:///android_asset/index.html"); |
| | | getCenterPoint(); |
| | | initView(); |
| | | initData(); |
| | | getMarkerData(); |
| | | //开启定位 |
| | | // Intent location = new Intent(this.getActivity(), MyLocationService.class); |
| | | // location.putExtra("isSingle", false); |
| | |
| | | } |
| | | |
| | | private void initData() { |
| | | jumpCenterPoint(); |
| | | } |
| | | |
| | | /** |
| | | * 跳转地图中心点 |
| | | */ |
| | | public void jumpCenterPoint() { |
| | | |
| | | centerPointBean = DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().findFirst(); |
| | | if (centerPointBean!=null){ |
| | | Log.d(TAG, "jumpCenterPoint>>>>>>>>>>>>>>>>>>>" + centerPointBean.getLng() + "\",\"" + centerPointBean.getLat()); |
| | | mWebView.evaluateJavascript("javascript:setCenterAndZoom(\"" + centerPointBean.getLng() + "\",\"" + centerPointBean.getLat() + "\")", value -> { |
| | | }); |
| | | } |
| | | } |
| | | |
| | | public void setMapMarker(){ |
| | | Log.i("mWebView", "addMarker????????????" + jsonData); |
| | | mWebView.evaluateJavascript("javascript:addMarker(\"" + jsonData + "\")", new ValueCallback<String>() { |
| | | @Override |
| | | public void onReceiveValue(String value) { |
| | | Log.i("mWebView", "addMarker!!!!!!!!!" + value); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | private void getMarkerData() { |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + ":8085/project/intake/all", MarkerResult.class, null, new SubscriberListener<BaseResponse<MarkerResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<MarkerResult> t) { |
| | | if (t.isSuccess()) { |
| | | if (t.isSuccess()) { |
| | | if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | stringBuilder.append("["); |
| | | for (int i = 0; i < t.getContent().getObj().size(); i++) { |
| | | stringBuilder.append("["); |
| | | stringBuilder.append(t.getContent().getObj().get(i).getLng()); |
| | | stringBuilder.append(","); |
| | | stringBuilder.append(t.getContent().getObj().get(i).getLat()); |
| | | stringBuilder.append(",\"" + t.getContent().getObj().get(i).getName() + "\"]"); |
| | | if (i != t.getContent().getObj().size() - 1) { |
| | | stringBuilder.append(","); |
| | | } |
| | | } |
| | | stringBuilder.append("]"); |
| | | jsonData = stringBuilder.toString().replace("\\", "\\\\").replace("\"", "\\\""); |
| | | |
| | | } |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg()); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | stringBuilder.append("[116.417854,39.921988,\"235取水口\"]]"); |
| | | String jsonData = stringBuilder.toString().replace("\\", "\\\\").replace("\"", "\\\""); |
| | | // String jsonData = "[[116.417854,39.921988,\"235取水口\"],[116.406605,39.921585,\"237取水口\"],[116.412222,39.912345,\"236取水口\"]]"; |
| | | Log.i("mWebView", "addMarker????????????" + jsonData); |
| | | mWebView.evaluateJavascript("javascript:addMarker(\"" + jsonData + "\")", new ValueCallback<String>() { |
| | | @Override |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onResume() { |
| | |
| | | * 获取地图中心点 |
| | | */ |
| | | private void getCenterPoint() { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("token", MyApplication.myApplication.token); |
| | | |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.SUCCESS + "8080/base/dict_item/map_center", CenterPointResult.class, data, new SubscriberListener<BaseResponse<CenterPointResult>>() { |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + ":8080/base/dict_item/map_center", CenterPointResult.class, null, new SubscriberListener<BaseResponse<CenterPointResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<CenterPointResult> t) { |
| | | if (t.isSuccess()) { |
| | |
| | | } |
| | | centerPointBean.setLat(t.getContent().getLat()); |
| | | centerPointBean.setLng(t.getContent().getLng()); |
| | | DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().update(centerPointBean); |
| | | DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().insert(centerPointBean); |
| | | jumpCenterPoint(); |
| | | } else { |
| | | ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg()); |
| | | } |