From e5659a16092dc90fd7b06f3659158ddae6e1edd3 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期一, 06 七月 2020 17:06:34 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java | 388 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 387 insertions(+), 1 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 2c09199..454809f 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
@@ -1,16 +1,71 @@
package safeluck.drive.evaluation.fragment;
+import android.graphics.Color;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
import android.view.LayoutInflater;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
+import com.esri.arcgisruntime.arcgisservices.ArcGISMapServiceInfo;
+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.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.R;
+import safeluck.drive.evaluation.app;
+import safeluck.drive.evaluation.bean.GisCarModel;
+import safeluck.drive.evaluation.util.CThreadPoolExecutor;
+import safeluck.drive.evaluation.util.FileUtil;
+import safeluck.drive.evaluation.util.Utils;
/**椹炬牎淇℃伅UI
* MyApplication2
@@ -22,13 +77,344 @@
public static SupportFragment newInstance(){
return new JiaXiaoFragment();
}
+ private static final String TAG = JiaXiaoFragment.class.getSimpleName();
+ 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_jiaxiao_info,container,false);
+ View view = inflater.inflate(R.layout.layout_arc_gis,container,false);
+ mMapView = view.findViewById(R.id.mapView);
+ setupMap();
+ addTrailheadsLayer();
+// addImageLayer();
+
+ mHandler.sendEmptyMessageDelayed(MSG_CAR,1000);
+
+// drawPolygon();
return view;
}
+ 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/";
+ 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--) {
+ ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(url+String.valueOf(i));
+
+ FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
+ ArcGISMap map = mMapView.getMap();
+ map.getOperationalLayers().add(featureLayer);
+ }
+ }
+ });
+
+
+
+
+
+ }
+
+ 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));
+ CThreadPoolExecutor.runInBackground(new Runnable() {
+ @Override
+ public void run() {
+ StringBuffer buffer= FileUtil.readAssetTxtFile(app.getAppContext(),"giscar.json");
+ Log.i(TAG,"giscar="+buffer.toString());
+ GisCarModel gisCarModel= new Gson().fromJson(buffer.toString(),GisCarModel.class);
+// List<safeluck.drive.evaluation.bean.Point> carNew=Utils.getCarPoint(0,45,new safeluck.drive.evaluation.bean.Point(-8633.77199999988,14471.793700000271));
+ 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));
+
+ }
+ });
+
+
+ }
+
+
+ });
+ }
+
+ 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);
+ }
+
+ 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());
+
+ List<Integer> frontCLs = new ArrayList<>();
+ frontCLs.addAll(gisCarModel.getLeft_front_glass());
+ frontCLs.addAll(gisCarModel.getRight_front_glass());
+ drawGlses(carNew, simpleFillSymbol, points, frontCLs);
+
+ frontCLs.clear();
+ frontCLs.addAll(gisCarModel.getLeft_rear_glass());
+ frontCLs.addAll(gisCarModel.getRight_rear_glass());
+ drawGlses(carNew, simpleFillSymbol, 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/manager/service.html?name=SampleWorldCities.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();
+ }
+ super.onDetach();
+ }
}
--
Gitblit v1.8.0