From 3be3637ae5a3e763ba99c8f6a1bb0cb144b7647f Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期二, 25 八月 2020 17:21:12 +0800
Subject: [PATCH] 查看地图改为web   新增gps_monitor_url

---
 app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java |  149 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 97 insertions(+), 52 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
index 942bbb6..883f06a 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
@@ -4,6 +4,7 @@
 import android.graphics.Color;
 import android.os.Bundle;
 
+import android.os.Environment;
 import android.os.Handler;
 import android.os.Message;
 import android.text.TextUtils;
@@ -17,6 +18,7 @@
 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;
@@ -63,6 +65,7 @@
 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;
 
@@ -90,25 +93,26 @@
 
     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) {
 
-            synchronized (JiaXiaoFragment.class){
-                String json = (String)obj;
-                Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),json));
-                RTKInfoBean rtkInfoBean = gson.fromJson(json,RTKInfoBean.class);
-                Log.i(TAG,String.format("CThreadPoolExecutor,褰撳墠绾跨▼鍙�%d,Coord_x=%f,Coord_y=%f",
-                        Thread.currentThread().getId(),rtkInfoBean.getCoord_x(),rtkInfoBean
-                                .getCoord_y()));
-                yaw = rtkInfoBean.getHeading();
-                startX = rtkInfoBean.getCoord_y();
-                startY = rtkInfoBean.getCoord_x();
-                addGraphicLayer(yaw,startX,startY);
-            }
+
+
+
+                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()));
 
 
         }
@@ -149,15 +153,54 @@
         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();
-        addGraphicLayer(0,startX,startY);
+//        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) {
@@ -173,7 +216,9 @@
 
 //涓�瀹氫笉鑳藉皯浜嗘渶鍚庣殑 /
 
-        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/%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);
@@ -183,10 +228,9 @@
                 SublayerList tables = arcGISMapImageLayer.getSublayers();
 
                 Log.i(TAG,"ServiceFeatureTables size = "+tables.size());
-                for (int i = tables.size()-1; i >= 0; i--) {
+                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);
@@ -195,19 +239,20 @@
         });
 
 
-        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){
-
-            }
-        });
+//鏃嬭浆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));
@@ -220,14 +265,12 @@
         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 = ExamPlatformData.getInstance().getCarModelPath();
+        String carFilePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+_mActivity.getPackageName()+"/giscar.json";
         if (TextUtils.isEmpty(carFilePath)){
             Toast.makeText(_mActivity, "杞﹁締妯″瀷鏂囦欢涓嶅瓨鍦�", Toast.LENGTH_SHORT).show();
             return;
         }
-        CThreadPoolExecutor.runInBackground(new Runnable() {
-            @Override
-            public void run() {
+
                 byte[] fileContentBytes=FileUtil.readFile(carFilePath);
                 String buffer= new String(fileContentBytes);
 //                Log.i(TAG,"giscar="+buffer);
@@ -235,8 +278,8 @@
                 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());
+//                    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());
                 }
 
@@ -260,10 +303,9 @@
                 });
 
 
-            }
 
 
-        });
+
     }
 
     private void drawPoint(Point point) {
@@ -272,25 +314,26 @@
         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) {
 
-        SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 0.5f);
-        SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.argb(255,0,0,0), lineSymbol);
-        PointCollection points = new PointCollection(SpatialReference.create(4544));
 
-        drawGlses(carNew, simpleFillSymbol, points, gisCarModel.getRight_center_glass());
-        drawGlses(carNew, simpleFillSymbol, points, gisCarModel.getLeft_center_glass());
+        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, simpleFillSymbol, points, frontCLs);
+        drawGlses(carNew, simpleFillSymbolGls, points, frontCLs);
 
         frontCLs.clear();
         frontCLs.addAll(gisCarModel.getLeft_rear_glass());
         frontCLs.addAll(gisCarModel.getRight_rear_glass());
-        drawGlses(carNew, simpleFillSymbol, points, frontCLs);
+        drawGlses(carNew, simpleFillSymbolGls, points, frontCLs);
 
 
     }
@@ -397,7 +440,7 @@
     }
 
 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";
+            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();
@@ -421,7 +464,7 @@
 
 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/manager/service.html?name=SampleWorldCities.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.
@@ -482,13 +525,15 @@
         if (mMapView != null) {
             mMapView.dispose();
         }
-        CEventCenter.onBindEvent(false,icEventListener, Constant.BIND_RTK_INFO_MAP);
+//        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);
+//        CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTK_INFO_MAP);
     }
 }

--
Gitblit v1.8.0