From 14b0c8eaf92ab602696870aff4a4c338a3a41179 Mon Sep 17 00:00:00 2001 From: endian11 <Dana_Lee1016@126.com> Date: 星期三, 09 九月 2020 17:09:04 +0800 Subject: [PATCH] 修改ArcGis android ,解决车模型频繁闪烁的问题 --- /dev/null | 539 ---------------------------- app/src/main/java/safeluck/drive/evaluation/fragment/ArcGisMapFragment.java | 519 +++++++++++++++++++++++++++ app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java | 8 app/src/main/java/safeluck/drive/evaluation/adapter/SimpleFragmentAdapter.java | 3 app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java | 11 app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java | 12 6 files changed, 532 insertions(+), 560 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/adapter/SimpleFragmentAdapter.java b/app/src/main/java/safeluck/drive/evaluation/adapter/SimpleFragmentAdapter.java index 8d3dc6d..94c2871 100644 --- a/app/src/main/java/safeluck/drive/evaluation/adapter/SimpleFragmentAdapter.java +++ b/app/src/main/java/safeluck/drive/evaluation/adapter/SimpleFragmentAdapter.java @@ -10,9 +10,6 @@ import me.yokeyword.fragmentation.SupportFragment; import safeluck.drive.evaluation.fragment.BaseDatasFragment; import safeluck.drive.evaluation.fragment.GpsInfoFragment; -import safeluck.drive.evaluation.fragment.RTKConfigFragment; -import safeluck.drive.evaluation.fragment.JiaXiaoFragment; -import safeluck.drive.evaluation.fragment.SetArgumentsFragment; /** diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/ArcGisMapFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/ArcGisMapFragment.java new file mode 100644 index 0000000..baa85fd --- /dev/null +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/ArcGisMapFragment.java @@ -0,0 +1,519 @@ +package safeluck.drive.evaluation.fragment; + +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; + +import android.os.Environment; +import android.os.Handler; +import android.os.Message; +import android.text.TextUtils; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.anyun.basecommonlib.MyLog; +import com.esri.arcgisruntime.geometry.Point; +import com.esri.arcgisruntime.geometry.PointCollection; +import com.esri.arcgisruntime.geometry.Polygon; +import com.esri.arcgisruntime.geometry.Polyline; +import com.esri.arcgisruntime.geometry.SpatialReference; +import com.esri.arcgisruntime.layers.ArcGISMapImageLayer; +import com.esri.arcgisruntime.mapping.ArcGISMap; +import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener; +import com.esri.arcgisruntime.mapping.view.Graphic; +import com.esri.arcgisruntime.mapping.view.GraphicsOverlay; +import com.esri.arcgisruntime.mapping.view.MapView; +import com.esri.arcgisruntime.symbology.SimpleFillSymbol; +import com.esri.arcgisruntime.symbology.SimpleLineSymbol; +import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol; +import com.google.gson.Gson; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; + +import me.yokeyword.fragmentation.SupportFragment; +import safeluck.drive.evaluation.Constant; +import safeluck.drive.evaluation.R; +import safeluck.drive.evaluation.bean.GisCarModel; +import safeluck.drive.evaluation.bean.RTKInfoBean; +import safeluck.drive.evaluation.cEventCenter.CEventCenter; +import safeluck.drive.evaluation.cEventCenter.ICEventListener; +import safeluck.drive.evaluation.util.CThreadPoolExecutor; +import safeluck.drive.evaluation.util.FileUtil; +import safeluck.drive.evaluation.util.Utils; + +/**椹炬牎淇℃伅UI + * MyApplication2 + * Created by lzw on 2019/3/20. 11:22:39 + * 閭锛�632393724@qq.com + * All Rights Saved! Chongqing AnYun Tech co. LTD + */ +public class ArcGisMapFragment extends SupportFragment { + + private static final String TAG = ArcGisMapFragment.class.getSimpleName(); + + private LinkedBlockingQueue queue = new LinkedBlockingQueue(100); + private ExecutorService consumer = Executors.newSingleThreadExecutor(); + private ExecutorService producer = Executors.newSingleThreadExecutor(); + SimpleLineSymbol lineSymbolGls = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 0.5f); + + + PointCollection points = new PointCollection(SpatialReference.create(4544)); + private Gson gson = new Gson(); + private ICEventListener icEventListener = new ICEventListener() { + @Override + public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { + + + + + producer.execute(()->{ + String json = (String)obj; + Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),json)); + RTKInfoBean rtkInfoBean = gson.fromJson(json,RTKInfoBean.class); + queue.offer(rtkInfoBean); + }); + +// MyLog.i(TAG,"澶勭悊瀹�11.鏃堕棿="+Utils.formatTimeYYMMDDHHmmSSSSS(System.currentTimeMillis())); + + + } + }; + + public static SupportFragment newInstance(String s){ + ArcGisMapFragment jiaXiaoFragment = new ArcGisMapFragment(); + Bundle bundle = new Bundle(); + bundle.putString("arcgis_url",s); + jiaXiaoFragment.setArguments(bundle); + return jiaXiaoFragment; + } + + + private MapView mMapView ; + private static final int MSG_CAR = 100; + double yaw = 0; + + GraphicsOverlay mGraphicsOverlay; + GraphicsOverlay mGraphicsOverlay_body; + private double startY = 428882,startX = 3291858; + private Handler mHandler = new Handler(){ + @Override + public void handleMessage(Message msg) { + switch (msg.what){ + case MSG_CAR: + + List<safeluck.drive.evaluation.bean.Point> newCarPoints = (List<safeluck.drive.evaluation.bean.Point>) msg.obj; + Log.i(TAG,"handle message newcarPoints.size="+newCarPoints.size()); + drawGlses(newCarPoints,gisCarModel); + + break; + } + } + }; + + PointCollection mPointCollection = new PointCollection(SpatialReference.create(4544)); + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + + + View view = inflater.inflate(R.layout.layout_arc_gis,container,false); + mMapView = view.findViewById(R.id.mapView); + Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),"onCreateView")); + url = getArguments().getString("arcgis_url"); + CThreadPoolExecutor.runInBackground(()->{ + + readGisCar(); + + + }); + consumer.execute(new CalRunnable()); + + setupMap(); + + + addTrailheadsLayer(); + return view; + } + + + + RTKInfoBean rtkInfoBean; + boolean flag = true; + class CalRunnable implements Runnable{ + + @Override + public void run() { + while (flag){ + + + rtkInfoBean = (RTKInfoBean)queue.poll(); + if (rtkInfoBean != null){ + Log.i(TAG,String.format("鍙栧嚭涓�涓紝queue.size=%d,rtkinfo=%s,绾跨▼鍙�=%d",queue.size(),rtkInfoBean.toString(),Thread.currentThread().getId())); + yaw = rtkInfoBean.getHeading(); + startX = rtkInfoBean.getCoord_y(); + startY = rtkInfoBean.getCoord_x(); + + + addGraphicLayer(yaw,startX,startY); + + + + } + + } + + } + } + + + + + + + + + private void setupMap() { + if (mMapView != null) { + + + mGraphicsOverlay = addGraphicsOverlay(mMapView); + + } + } +String url ; + private void addTrailheadsLayer() { + if (!TextUtils.isEmpty(url)){ + final ArcGISMapImageLayer mapImageLayer = new ArcGISMapImageLayer(url); + // create an empty map instance + ArcGISMap map = new ArcGISMap(); + Log.i(TAG,String.format("map.getMiniScale=%f",map.getMinScale())); + map.setMinScale(1000.0); + // add map image layer as operational layer + map.getOperationalLayers().add(mapImageLayer); + mMapView.setMap(map); + }else{ + Toast.makeText(_mActivity, "url涓虹┖", Toast.LENGTH_SHORT).show(); + } + + + + } + + + + GisCarModel gisCarModel; + boolean once =true; + private void addGraphicLayer(double yaw,double x,double y){ + Log.i(TAG,"addgraphicLayer寮�濮�"); + long time = System.currentTimeMillis(); + + + + if (gisCarModel != null){ + + + long qudianTime = System.currentTimeMillis(); + List<safeluck.drive.evaluation.bean.Point> carNew =Utils.getCarPoint(0,yaw,new safeluck.drive.evaluation.bean.Point(x,y),gisCarModel); + Log.i(TAG,String.format("鍙栧埌鐐硅�楁椂=%d姣,绾跨▼鍙�=%d",System.currentTimeMillis()-qudianTime,Thread.currentThread().getId())); + if (carNew == null) return; + if (once){ + Message message = Message.obtain(); + message.what = MSG_CAR; + + message.obj = carNew; + mHandler.sendMessage(message); + + } + + + + + + + } + + + long period= System.currentTimeMillis()-time; + Log.i(TAG,"鎵цaddGraphicLayer鏂规硶锛岃�楁椂="+period); + + + + } + + private GraphicsOverlay addGraphicsOverlay(MapView mapView){ + //create the graphics overlay + GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); + mGraphicsOverlay_body = new GraphicsOverlay(); + //add the overlay to the map view + mapView.getGraphicsOverlays().add(mGraphicsOverlay_body); + mapView.getGraphicsOverlays().add(graphicsOverlay); + return graphicsOverlay; + } + private void readGisCar() { + + String carFilePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+_mActivity.getPackageName()+"/giscar.json"; + if (TextUtils.isEmpty(carFilePath)){ + MyLog.i (TAG, "GISCar杞﹁締妯″瀷鏂囦欢涓嶅瓨鍦�"); + return ; + } + byte[] fileContentBytes= FileUtil.readFile(carFilePath); + String buffer= new String(fileContentBytes); + gisCarModel = new Gson().fromJson(buffer, GisCarModel.class); + + } + + + + PointCollection points1 = new PointCollection(SpatialReference.create(4544)); + PointCollection points2 = new PointCollection(SpatialReference.create(4544)); + PointCollection points3 = new PointCollection(SpatialReference.create(4544)); + PointCollection points4 = new PointCollection(SpatialReference.create(4544)); + SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(232,0,0), 0.5f); + SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.argb(255,232,0,0), lineSymbol); + + SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.WHITE, 5); + SimpleFillSymbol simpleFillSymbolGls = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.argb(255,0,0,0), lineSymbolGls); + private void drawGlses(List<safeluck.drive.evaluation.bean.Point> carNew, GisCarModel gisCarModel) { + + long beginTime = System.currentTimeMillis(); + + +/**==============================car body=========================================*/ + + List<Integer> bodys =gisCarModel.getBody(); + points.clear(); + for (int i = 0; i <bodys.size(); i++) { + points.add(carNew.get(bodys.get(i)).getX(),carNew.get(bodys.get(i)).getY()); + } + + Polygon polygon = new Polygon(points); + + Graphic graphic = new Graphic(polygon,simpleFillSymbol); + + + + /**===============================car body end========================================*/ + + +/**==============================鐢诲ぉ绾�=========================================*/ + + +// Graphic graphicAnt = new Graphic(new Point(startX,startY), simpleMarkerSymbol); + + /**==============================鐢诲ぉ绾跨粨鏉� END=========================================*/ + + + + List<Integer> leftCenterGls = gisCarModel.getLeft_center_glass(); + points1.clear(); + for (int i = 0; i < leftCenterGls.size(); i++) { + int pos = leftCenterGls.get(i); + points1.add(carNew.get(pos).getX(), carNew.get(pos).getY()); + + } + List<Integer> rightCenterGls = gisCarModel.getRight_center_glass(); + points2.clear(); + for (int i = 0; i < leftCenterGls.size(); i++) { + int pos = rightCenterGls.get(i); + points2.add(carNew.get(pos).getX(), carNew.get(pos).getY()); + + } + + + List<Integer> frontCLs = new ArrayList<>(); + frontCLs.addAll(gisCarModel.getLeft_front_glass()); + frontCLs.addAll(gisCarModel.getRight_front_glass()); + + + points3.clear(); + for (int i = 0; i < frontCLs.size(); i++) { + int pos = frontCLs.get(i); + points3.add(carNew.get(pos).getX(), carNew.get(pos).getY()); + + } + frontCLs.clear(); + frontCLs.addAll(gisCarModel.getLeft_rear_glass()); + frontCLs.addAll(gisCarModel.getRight_rear_glass()); + points4.clear(); + for (int i = 0; i < frontCLs.size(); i++) { + int pos = frontCLs.get(i); + points4.add(carNew.get(pos).getX(), carNew.get(pos).getY()); + + } + Polygon polygon1 = new Polygon(points1); + Polygon polygon2 = new Polygon(points2); + Polygon polygon3 = new Polygon(points3); + Polygon polygon4 = new Polygon(points4); + + + //create graphics + + Graphic buoyGraphic1 = new Graphic(polygon1, simpleFillSymbolGls); + Graphic buoyGraphic2 = new Graphic(polygon2, simpleFillSymbolGls); + Graphic buoyGraphic3 = new Graphic(polygon3, simpleFillSymbolGls); + Graphic buoyGraphic4 = new Graphic(polygon4, simpleFillSymbolGls); + //add the graphics to the graphics overlay + /**==============================娓呴櫎GraphicsOverlay涓婃墍鏈塯raphic=========================================*/ + long clearTime = System.currentTimeMillis(); + + + mGraphicsOverlay.getGraphics().clear(); + Log.i(TAG,"clear鏂规硶鏃堕棿+"+(System.currentTimeMillis()-clearTime)); + /**==============================娓呴櫎GraphicsOverlay涓婃墍鏈塯raphic END=========================================*/ + + mGraphicsOverlay.getGraphics().add(buoyGraphic1); + mGraphicsOverlay.getGraphics().add(buoyGraphic2); + mGraphicsOverlay.getGraphics().add(buoyGraphic3); + mGraphicsOverlay.getGraphics().add(buoyGraphic4); + mGraphicsOverlay_body.getGraphics().clear(); + mGraphicsOverlay_body.getGraphics().add(graphic); +// mGraphicsOverlay.getGraphics().add(graphicAnt); + Log.i(TAG,"GraphicsOverLay add graphic瀹屾垚"+(System.currentTimeMillis()-beginTime)); + if (mMapView != null){ + mMapView.setViewpointCenterAsync(new Point(startX,startY)); + } + + + + + } + + /** + * 缁樺埗闈� + */ + private void drawPolygon() { +// List<Point> points = new ArrayList<>(); +// points.add(new Point(21.21,21.32, SpatialReference.create("4544"))); +// PointCollection pointCollection = new PointCollection(points); + + mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(_mActivity, mMapView) { + @Override + public boolean onSingleTapConfirmed(MotionEvent e) { + + mGraphicsOverlay.getGraphics().clear(); + Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()))); + mPointCollection.add(point); + + Polygon polygon = new Polygon(mPointCollection); + + if (mPointCollection.size() == 1) { + SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10); + Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol); + mGraphicsOverlay.getGraphics().add(pointGraphic); + } + + SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 3.0f); + SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.parseColor("#33e97676"), lineSymbol); + Graphic graphic = new Graphic(polygon, simpleFillSymbol); + mGraphicsOverlay.getGraphics().add(graphic); + + return super.onSingleTapConfirmed(e); + } + }); + } + + /** + * 缁樺埗鐐� + */ + private void drawPoint() { + mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(_mActivity, mMapView) { + @Override + public boolean onSingleTapConfirmed(MotionEvent e) { + Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()))); + SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 20); + Graphic graphic = new Graphic(clickPoint, simpleMarkerSymbol); + //娓呴櫎涓婁竴涓偣 + mGraphicsOverlay.getGraphics().clear(); + mGraphicsOverlay.getGraphics().add(graphic); + + //浣跨敤娓叉煋鍣� + // Graphic graphic1 = new Graphic(clickPoint); + // SimpleRenderer simpleRenderer = new SimpleRenderer(simpleMarkerSymbol); + // mGraphicsOverlay.setRenderer(simpleRenderer); + // mGraphicsOverlay.getGraphics().clear(); + // mGraphicsOverlay.getGraphics().add(graphic1); + + return super.onSingleTapConfirmed(e); + } + }); + } + + /** + * 缁樺埗绾� + */ + private void drawPolyline() { + mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(_mActivity, mMapView) { + @Override + public boolean onSingleTapConfirmed(MotionEvent e) { + Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()))); + mPointCollection.add(point); + + Polyline polyline = new Polyline(mPointCollection); + + //鐐� + SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10); + Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol); + mGraphicsOverlay.getGraphics().add(pointGraphic); + + //绾� + SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 3); + Graphic graphic = new Graphic(polyline, simpleLineSymbol); + mGraphicsOverlay.getGraphics().add(graphic); + + return super.onSingleTapConfirmed(e); + } + }); + } + + + + @Override + public void onPause() { + if (mMapView != null) { + mMapView.pause(); + } + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + if (mMapView != null) { + mMapView.resume(); + } + } + + @Override + public void onDetach() { + super.onDetach(); + if (mMapView != null) { + mMapView.dispose(); + } + Log.i(TAG,"娓呯┖闃熷垪"); + flag = false; + producer.shutdown(); + consumer .shutdown(); + queue.clear(); + CEventCenter.onBindEvent(false,icEventListener, Constant.BIND_RTK_INFO_MAP); + + + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTK_INFO_MAP); + } + +} diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java index a01f0a6..ca8b992 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java @@ -130,11 +130,9 @@ myDialog.show(getFragmentManager(),"mydialog"); -// JiaXiaoFragment jiaXiaoFragment = findFragment(JiaXiaoFragment.class); -// if (jiaXiaoFragment == null) { -// jiaXiaoFragment = (JiaXiaoFragment) JiaXiaoFragment.newInstance(); -// } -// start(jiaXiaoFragment); + + + break; case R.id.system_setting: diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java deleted file mode 100644 index 883f06a..0000000 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java +++ /dev/null @@ -1,539 +0,0 @@ -package safeluck.drive.evaluation.fragment; - -import android.content.Context; -import android.graphics.Color; -import android.os.Bundle; - -import android.os.Environment; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.anyun.basecommonlib.MyLog; -import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; -import com.esri.arcgisruntime.arcgisservices.ArcGISMapServiceInfo; -import com.esri.arcgisruntime.concurrent.ListenableFuture; -import com.esri.arcgisruntime.data.ServiceFeatureTable; -import com.esri.arcgisruntime.geometry.Point; -import com.esri.arcgisruntime.geometry.PointCollection; -import com.esri.arcgisruntime.geometry.Polygon; -import com.esri.arcgisruntime.geometry.Polyline; -import com.esri.arcgisruntime.geometry.SpatialReference; -import com.esri.arcgisruntime.geometry.SpatialReferences; -import com.esri.arcgisruntime.layers.ArcGISMapImageLayer; -import com.esri.arcgisruntime.layers.ArcGISMapImageSublayer; -import com.esri.arcgisruntime.layers.ArcGISSublayer; -import com.esri.arcgisruntime.layers.ArcGISTiledLayer; -import com.esri.arcgisruntime.layers.ArcGISVectorTiledLayer; -import com.esri.arcgisruntime.layers.FeatureLayer; -import com.esri.arcgisruntime.layers.MobileBasemapLayer; -import com.esri.arcgisruntime.layers.SublayerList; -import com.esri.arcgisruntime.loadable.LoadStatus; -import com.esri.arcgisruntime.loadable.LoadStatusChangedEvent; -import com.esri.arcgisruntime.loadable.LoadStatusChangedListener; -import com.esri.arcgisruntime.mapping.ArcGISMap; -import com.esri.arcgisruntime.mapping.Basemap; -import com.esri.arcgisruntime.mapping.Viewpoint; -import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener; -import com.esri.arcgisruntime.mapping.view.Graphic; -import com.esri.arcgisruntime.mapping.view.GraphicsOverlay; -import com.esri.arcgisruntime.mapping.view.MapView; -import com.esri.arcgisruntime.portal.Portal; -import com.esri.arcgisruntime.portal.PortalItem; -import com.esri.arcgisruntime.symbology.LineSymbol; -import com.esri.arcgisruntime.symbology.SimpleFillSymbol; -import com.esri.arcgisruntime.symbology.SimpleLineSymbol; -import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol; -import com.esri.arcgisruntime.util.ListenableList; -import com.google.gson.Gson; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import me.yokeyword.fragmentation.SupportFragment; -import safeluck.drive.evaluation.Constant; -import safeluck.drive.evaluation.R; -import safeluck.drive.evaluation.app; -import safeluck.drive.evaluation.arcgis.MapSingleTapListener; -import safeluck.drive.evaluation.bean.ExamPlatformData; -import safeluck.drive.evaluation.bean.GisCarModel; -import safeluck.drive.evaluation.bean.RTKInfoBean; -import safeluck.drive.evaluation.cEventCenter.CEventCenter; -import safeluck.drive.evaluation.cEventCenter.ICEventListener; -import safeluck.drive.evaluation.util.CThreadPoolExecutor; -import safeluck.drive.evaluation.util.FileUtil; -import safeluck.drive.evaluation.util.Utils; - -/**椹炬牎淇℃伅UI - * MyApplication2 - * Created by lzw on 2019/3/20. 11:22:39 - * 閭锛�632393724@qq.com - * All Rights Saved! Chongqing AnYun Tech co. LTD - */ -public class JiaXiaoFragment extends SupportFragment { - - private static final String TAG = JiaXiaoFragment.class.getSimpleName(); - - private LinkedBlockingQueue queue = new LinkedBlockingQueue(100); - private ExecutorService consumer = Executors.newSingleThreadExecutor(); - private ExecutorService producer = Executors.newSingleThreadExecutor(); - - private Gson gson = new Gson(); - private ICEventListener icEventListener = new ICEventListener() { - @Override - public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { - - - - - producer.execute(()->{ - String json = (String)obj; - Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),json)); - RTKInfoBean rtkInfoBean = gson.fromJson(json,RTKInfoBean.class); - queue.offer(rtkInfoBean); - }); - -// MyLog.i(TAG,"澶勭悊瀹�11.鏃堕棿="+Utils.formatTimeYYMMDDHHmmSSSSS(System.currentTimeMillis())); - - - } - }; - - public static SupportFragment newInstance(){ - return new JiaXiaoFragment(); - } - - - private MapView mMapView ; - private static final int MSG_CAR = 100; - double yaw = 0; - - GraphicsOverlay mGraphicsOverlay; - private int count =0; - private double startX = -8647.003,startY = 14590.7213; - private Handler mHandler = new Handler(){ - @Override - public void handleMessage(Message msg) { - switch (msg.what){ - case MSG_CAR: - count++; - yaw +=count; - addGraphicLayer(yaw,startX+count,startY+count); - sendEmptyMessageDelayed(MSG_CAR,1000); - break; - } - } - }; - - PointCollection mPointCollection = new PointCollection(SpatialReference.create(4544)); - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - - - View view = inflater.inflate(R.layout.layout_arc_gis,container,false); - mMapView = view.findViewById(R.id.mapView); - Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),"onCreateView")); -// setupMap(); -// addTrailheadsLayer(); - -addImageLayer(); -// addtiledLayer(); - - -// addGraphicLayer(0,startX,startY); - -// mHandler.sendEmptyMessageDelayed(MSG_CAR,1000); - -// consumer.execute(new CalRunnable()); - return view; - } - - - - - - boolean flag = true; - class CalRunnable implements Runnable{ - - @Override - public void run() { - while (flag){ - - - RTKInfoBean rtkInfoBean = (RTKInfoBean) queue.poll(); - if (rtkInfoBean != null){ - Log.i(TAG,String.format("鍙栧嚭涓�涓紝queue.size=%d,rtkinfo=%s",queue.size(),rtkInfoBean.toString())); - yaw = rtkInfoBean.getHeading(); - startX = rtkInfoBean.getCoord_y(); - startY = rtkInfoBean.getCoord_x(); - addGraphicLayer(yaw,startX,startY); - }else{ - Log.i(TAG,String.format("鍙栧嚭涓�涓负绌猴紝queue.size=%d",queue.size())); - } - - } - - } - } - - - - - - - private SublayerList mSublayersList; - private void setupMap() { - if (mMapView != null) { - ArcGISMap map = new ArcGISMap(); - mMapView.setMap(map); - - mGraphicsOverlay= new GraphicsOverlay(); - mMapView.getGraphicsOverlays().add(mGraphicsOverlay); - - } - } - private void addTrailheadsLayer() { - -//涓�瀹氫笉鑳藉皯浜嗘渶鍚庣殑 / - -// String url = "http://192.168.0.47:6080/arcgis/rest/services/%E5%9C%9F%E4%B8%BB%E8%80%83%E5%9C%BA/MapServer/"; -// String url = "http://192.168.0.47:6080/arcgis/rest/services/%E7%A7%91%E4%B8%89%E5%9C%B0%E5%9B%BE/MapServer/"; - String url = "http://192.168.0.47:6080/arcgis/rest/services/%E7%A7%91%E4%BA%8C%E5%9C%B0%E5%9B%BE/MapServer/"; -// String url = "http://192.168.0.47:6080/arcgis/rest/services/test/MapServer/"; -// String url = "http://192.168.0.47:6080/arcgis/rest/services/Testmap_3/MapServer/"; - ArcGISMapImageLayer arcGISMapImageLayer = new ArcGISMapImageLayer(url); - arcGISMapImageLayer.loadAsync(); - arcGISMapImageLayer.addLoadStatusChangedListener(loadStatusChangedEvent -> { - if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.LOADED){ - SublayerList tables = arcGISMapImageLayer.getSublayers(); - - Log.i(TAG,"ServiceFeatureTables size = "+tables.size()); - for (int i = tables.size()-1; i >=0; i--) { -// for (int i =0; i < tables.size(); i++) { - ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(url+String.valueOf(i)); - FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable); - ArcGISMap map = mMapView.getMap(); - map.getOperationalLayers().add(featureLayer); - } - } - }); - - -//鏃嬭浆90搴� 閫嗘椂閽� -// final ListenableFuture<Boolean> viewPointSetFuture = mMapView.setViewpointRotationAsync(90); -// viewPointSetFuture.addDoneListener(() -> { -// try{ -// boolean completed = viewPointSetFuture.get(); -// if (completed){ -// Log.i(TAG,"Rotation completed successfully"); -// } -// }catch (InterruptedException e){ -// Log.i(TAG,"Rotation Interrupted"); -// }catch (ExecutionException e){ -// -// } -// }); - - - mMapView.setOnTouchListener(new MapSingleTapListener(getContext(),mMapView)); - - - } - - private void addGraphicLayer(double yaw,double x,double y){ - - SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(232,0,0), 0.5f); - SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.argb(255,232,0,0), lineSymbol); - PointCollection points = new PointCollection(SpatialReference.create(4544)); - String carFilePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+_mActivity.getPackageName()+"/giscar.json"; - if (TextUtils.isEmpty(carFilePath)){ - Toast.makeText(_mActivity, "杞﹁締妯″瀷鏂囦欢涓嶅瓨鍦�", Toast.LENGTH_SHORT).show(); - return; - } - - byte[] fileContentBytes=FileUtil.readFile(carFilePath); - String buffer= new String(fileContentBytes); -// Log.i(TAG,"giscar="+buffer); - GisCarModel gisCarModel= new Gson().fromJson(buffer,GisCarModel.class); - List<safeluck.drive.evaluation.bean.Point> carNew=Utils.getCarPoint(0,yaw,new safeluck.drive.evaluation.bean.Point(x,y)); - List<Integer> bodys =gisCarModel.getBody(); - for (int i = 0; i <bodys.size(); i++) { -// Log.i(TAG,String.format("杞﹁韩鐐逛綅缃細%d",bodys.get(i))); -// Log.i(TAG,"鏂板潗鏍�"+carNew.get(bodys.get(i)).getX()+" Y="+carNew.get(bodys.get(i)).getY()); - points.add(carNew.get(bodys.get(i)).getX(),carNew.get(bodys.get(i)).getY()); - } - - CThreadPoolExecutor.runOnMainThread(new Runnable() { - @Override - public void run() { - Polygon polygon = new Polygon(points); - - Graphic graphic = new Graphic(polygon,simpleFillSymbol); - mGraphicsOverlay.getGraphics().clear(); - mGraphicsOverlay.getGraphics().add(graphic); - - drawrightCenterGls(gisCarModel,carNew); - - drawPoint(new Point(x,y)); - - if (mMapView != null){ - mMapView.setViewpointCenterAsync(new Point(x,y)); - } - } - }); - - - - - - } - - private void drawPoint(Point point) { - SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.WHITE, 5); - - Graphic graphic = new Graphic(point, simpleMarkerSymbol); - mGraphicsOverlay.getGraphics().add(graphic); - } - SimpleLineSymbol lineSymbolGls = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 0.5f); - - SimpleFillSymbol simpleFillSymbolGls = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.argb(255,0,0,0), lineSymbolGls); - PointCollection points = new PointCollection(SpatialReference.create(4544)); - - private void drawrightCenterGls(GisCarModel gisCarModel, List<safeluck.drive.evaluation.bean.Point> carNew) { - - - drawGlses(carNew, simpleFillSymbolGls, points, gisCarModel.getRight_center_glass()); - drawGlses(carNew, simpleFillSymbolGls, points, gisCarModel.getLeft_center_glass()); - - List<Integer> frontCLs = new ArrayList<>(); - frontCLs.addAll(gisCarModel.getLeft_front_glass()); - frontCLs.addAll(gisCarModel.getRight_front_glass()); - drawGlses(carNew, simpleFillSymbolGls, points, frontCLs); - - frontCLs.clear(); - frontCLs.addAll(gisCarModel.getLeft_rear_glass()); - frontCLs.addAll(gisCarModel.getRight_rear_glass()); - drawGlses(carNew, simpleFillSymbolGls, points, frontCLs); - - - } - - private void drawGlses(List<safeluck.drive.evaluation.bean.Point> carNew, SimpleFillSymbol simpleFillSymbol, PointCollection points, List<Integer> left_center_glass) { - List<Integer> leftCenterGls = left_center_glass; - points.clear(); - for (int i = 0; i < leftCenterGls.size(); i++) { - int pos = leftCenterGls.get(i); - points.add(carNew.get(pos).getX(), carNew.get(pos).getY()); - - } - - Polygon polygon1 = new Polygon(points); - Graphic graphic1 = new Graphic(polygon1, simpleFillSymbol); - mGraphicsOverlay.getGraphics().add(graphic1); - } - - /** - * 缁樺埗闈� - */ - private void drawPolygon() { -// List<Point> points = new ArrayList<>(); -// points.add(new Point(21.21,21.32, SpatialReference.create("4544"))); -// PointCollection pointCollection = new PointCollection(points); - - mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(_mActivity, mMapView) { - @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - - mGraphicsOverlay.getGraphics().clear(); - Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()))); - mPointCollection.add(point); - - Polygon polygon = new Polygon(mPointCollection); - - if (mPointCollection.size() == 1) { - SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10); - Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol); - mGraphicsOverlay.getGraphics().add(pointGraphic); - } - - SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 3.0f); - SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.parseColor("#33e97676"), lineSymbol); - Graphic graphic = new Graphic(polygon, simpleFillSymbol); - mGraphicsOverlay.getGraphics().add(graphic); - - return super.onSingleTapConfirmed(e); - } - }); - } - - /** - * 缁樺埗鐐� - */ - private void drawPoint() { - mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(_mActivity, mMapView) { - @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()))); - SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 20); - Graphic graphic = new Graphic(clickPoint, simpleMarkerSymbol); - //娓呴櫎涓婁竴涓偣 - mGraphicsOverlay.getGraphics().clear(); - mGraphicsOverlay.getGraphics().add(graphic); - - //浣跨敤娓叉煋鍣� - // Graphic graphic1 = new Graphic(clickPoint); - // SimpleRenderer simpleRenderer = new SimpleRenderer(simpleMarkerSymbol); - // mGraphicsOverlay.setRenderer(simpleRenderer); - // mGraphicsOverlay.getGraphics().clear(); - // mGraphicsOverlay.getGraphics().add(graphic1); - - return super.onSingleTapConfirmed(e); - } - }); - } - - /** - * 缁樺埗绾� - */ - private void drawPolyline() { - mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(_mActivity, mMapView) { - @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()))); - mPointCollection.add(point); - - Polyline polyline = new Polyline(mPointCollection); - - //鐐� - SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10); - Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol); - mGraphicsOverlay.getGraphics().add(pointGraphic); - - //绾� - SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 3); - Graphic graphic = new Graphic(polyline, simpleLineSymbol); - mGraphicsOverlay.getGraphics().add(graphic); - - return super.onSingleTapConfirmed(e); - } - }); - } - -private void addImageLayer(){ - String url = "http://192.168.0.47:6080/arcgis/rest/services/%E5%9C%9F%E4%B8%BB%E8%80%83%E5%9C%BA/MobileServer/"; - // create a MapImageLayer with dynamically generated map images - final ArcGISMapImageLayer mapImageLayer = new ArcGISMapImageLayer(url); -// mapImageLayer.loadAsync(); - // Add a listener that is invoked when layer loading has completed. - mapImageLayer.addDoneLoadingListener(() -> { - if (mapImageLayer.getLoadStatus() == LoadStatus.LOADED) { - ArcGISMapServiceInfo mapServiceInfo = mapImageLayer.getMapServiceInfo(); - - Log.i(TAG, "addImageLayer: 鍔犺浇瀹屾垚銆傘�傘��"); - - // work with map service info here - } - }); - // create an empty map instance - ArcGISMap map = new ArcGISMap(); - // add map image layer as operational layer - map.getOperationalLayers().add(mapImageLayer); - // set the map to be displayed in this view - mMapView.setMap(map); -} - -private void addtiledLayer(){ -// String url = "http://192.168.0.47:6080/arcgis/rest/services/%E5%9C%9F%E4%B8%BB%E8%80%83%E5%9C%BA/MapServer"; - String url = "http://192.168.0.47:6080/arcgis/rest/services/%E7%A7%91%E4%BA%8C%E5%9C%B0%E5%9B%BE/MapServer"; - // create a MapImageLayer with dynamically generated map images - final ArcGISTiledLayer arcGISTiledLayer = new ArcGISTiledLayer(url); - // Add a listener that is invoked when layer loading has completed. - arcGISTiledLayer.addDoneLoadingListener(() -> { - if (arcGISTiledLayer.getLoadStatus() == LoadStatus.LOADED) { - // work with map service info here - Log.i(TAG,"ArcGISTiledLayer鍔犺浇瀹屾垚"); - } - }); - Basemap basemap = new Basemap(arcGISTiledLayer); - // create a map with the basemap - ArcGISMap arcGISMap = new ArcGISMap(basemap); - // set the map to be displayed in this view - mMapView.setMap(arcGISMap); - -} -private void addVectorTiledLayer(){ - String url = "http://192.168.0.47:6080/arcgis/rest/services/%E5%9C%9F%E4%B8%BB%E8%80%83%E5%9C%BA/MapServer"; - // create a MapImageLayer with dynamically generated map images - final ArcGISVectorTiledLayer mVectorTiledLayer = new ArcGISVectorTiledLayer(url); - // Add a listener that is invoked when layer loading has completed. - mVectorTiledLayer.addDoneLoadingListener(() -> { - if (mVectorTiledLayer.getLoadStatus() == LoadStatus.LOADED) { - // work with map service info here - Log.i(TAG,"ArcGISTiledLayer鍔犺浇瀹屾垚"); - } - }); - Basemap basemap = new Basemap(mVectorTiledLayer); - // create a map with the basemap - ArcGISMap arcGISMap = new ArcGISMap(basemap); - - Viewpoint vp = new Viewpoint(47.606726, -122.335564, 72223.819286); - arcGISMap.setInitialViewpoint(vp); - - // set the map to be displayed in this view - mMapView.setMap(arcGISMap); - -} - - @Override - public void onPause() { - if (mMapView != null) { - mMapView.pause(); - } - super.onPause(); - } - - @Override - public void onResume() { - super.onResume(); - if (mMapView != null) { - mMapView.resume(); - } - } - - @Override - public void onDetach() { - if (mMapView != null) { - mMapView.dispose(); - } -// CEventCenter.onBindEvent(false,icEventListener, Constant.BIND_RTK_INFO_MAP); - producer.shutdown(); - consumer .shutdown(); - super.onDetach(); - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); -// CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTK_INFO_MAP); - } -} diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java index af77c99..b69f76e 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java @@ -7,7 +7,6 @@ import android.graphics.Paint; import android.graphics.Path; import android.os.Bundle; -import android.os.Handler; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -51,7 +50,6 @@ import safeluck.drive.evaluation.bean.RealTimeCarPos; import safeluck.drive.evaluation.cEventCenter.CEventCenter; import safeluck.drive.evaluation.cEventCenter.ICEventListener; -import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; import safeluck.drive.evaluation.util.Utils; @@ -453,13 +451,15 @@ case R.id.btn_change_map: MapInfoHead mapInfoHead = ExamPlatformData.getInstance().getMapInfoHeads().get(BaseDataUIBean.TYPE_.yard); - String url = mapInfoHead.getGps_moinitor_url(); + String url = mapInfoHead.getArcgis_url(); Log.i(TAG,"map head lulao gps url="+url); - VPFragment jiaXiaoFragment = findFragment(VPFragment.class); + + ArcGisMapFragment jiaXiaoFragment = findFragment(ArcGisMapFragment.class); if (jiaXiaoFragment == null) { - jiaXiaoFragment = (VPFragment) VPFragment.newInstance(url); + jiaXiaoFragment = (ArcGisMapFragment) ArcGisMapFragment.newInstance(url); } - start(jiaXiaoFragment); + startWithPop(jiaXiaoFragment); + break; } } diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java b/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java index 447aa4d..934a11d 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java @@ -17,7 +17,6 @@ import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; import android.widget.Toast; import androidx.annotation.NonNull; @@ -31,7 +30,6 @@ import org.json.JSONException; import org.json.JSONObject; -import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; import java.math.BigDecimal; @@ -54,7 +52,6 @@ import safeluck.drive.evaluation.bean.RoadExamMap2; import safeluck.drive.evaluation.cEventCenter.CEventCenter; import safeluck.drive.evaluation.cEventCenter.ICEventListener; -import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; import safeluck.drive.evaluation.util.Utils; @@ -1497,13 +1494,13 @@ break; case R.id.btn_change_map: MapInfoHead mapInfoHead = ExamPlatformData.getInstance().getMapInfoHeads().get(BaseDataUIBean.TYPE_.road); - String url = mapInfoHead.getGps_moinitor_url(); + String url = mapInfoHead.getArcgis_url(); Log.i(TAG,"map head lulao gps url="+url); - VPFragment jiaXiaoFragment = findFragment(VPFragment.class); + ArcGisMapFragment jiaXiaoFragment = findFragment(ArcGisMapFragment.class); if (jiaXiaoFragment == null) { - jiaXiaoFragment = (VPFragment) VPFragment.newInstance(url); + jiaXiaoFragment = (ArcGisMapFragment) ArcGisMapFragment.newInstance(url); } - start(jiaXiaoFragment); + startWithPop(jiaXiaoFragment); break; } } -- Gitblit v1.8.0