package safeluck.drive.evaluation.fragment; import android.content.Context; import android.graphics.Color; import android.os.Bundle; 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.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.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 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); } } }; 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(); addGraphicLayer(0,startX,startY); // mHandler.sendEmptyMessageDelayed(MSG_CAR,1000); 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/"; // 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); } } }); final ListenableFuture 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 = ExamPlatformData.getInstance().getCarModelPath(); 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); GisCarModel gisCarModel= new Gson().fromJson(buffer,GisCarModel.class); List carNew=Utils.getCarPoint(0,yaw,new safeluck.drive.evaluation.bean.Point(x,y)); List bodys =gisCarModel.getBody(); for (int i = 0; i { 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(); } CEventCenter.onBindEvent(false,icEventListener, Constant.BIND_RTK_INFO_MAP); super.onDetach(); } @Override public void onAttach(Context context) { super.onAttach(context); CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTK_INFO_MAP); } }