當初開發的時候在網上搜索了很久,沒有看到合適的arcgis相關的資料,很多資料都是之前舊版本的arcgis,大部分的代碼也不能用,所以工作完成之後在這裏稍微總結一下
-
天地圖相關
-
arcigs相關
-
TianDiMapUtils
TileInfo參數
參數類型 參數名 解釋 備註 int DPI 分辨率 TileInfo.ImageFormat imageFormat 切片的加載方式? 不太確定 List<LevelOfDetail> levelOfDetails 主要縮放等級 Point origin 起始點 這裏在異步加載的時候,點有時候不可用,不知道什麼原因 SpatialReference spatialReference 座標系類型 int tileHeight 切片高 int tileWidth 切片寬 WebTiledLayer參數
參數類型 參數名 解釋 備註 String templateUri 地圖地址 Iterable<String> subDomains 不知道術語,見備註 天地圖WMTS服務有八個域名可以用來訪問,0~8中任何一個都可以進行切片 TileInfo tileInfo 關鍵信息 見上文 Envelope fullExtent 地圖範圍 Graphic
參數類型 參數名 解釋 備註 Geometry geometry 地圖信息 一般用Point即可 Map<String, Object> attributes 額外信息 直接放對象會報錯,不知道原因 Symbol symbol marker圖片 PictureMarkerSymbol iconPump = new PictureMarkerSymbol(new BitmapDrawable(changeSize(R.drawable.gis_ic_bengzhan))); new Graphic(point, stringStringHashMap, iconWaterStation)
-
ArcGisUtil
- 使用 Lifecycle 解決生命週期問題,把生命週期的控制抽出到工具類中
- arcgis中沒有像百度、高德中那種marker點擊事件,所以需要根據點擊座標自己實現
關鍵代碼解釋
mapView.setOnTouchListener(DefaultMapViewOnTouchListener defaultMapViewOnTouchListener,MapView mapView){ @Override public boolean onSingleTapConfirmed(MotionEvent motionEvent) { //地圖手勢處理 onClickMap(motionEvent); return true; } }
處理手勢事件
private void onClickMap(MotionEvent motionEvent) { android.graphics.Point screenPoint = new android.graphics.Point(Math.round(motionEvent.getX()), Math.round(motionEvent.getY())); // create a map point from screen point Point mapPoint = mapView.screenToLocation(screenPoint); // convert to WGS84 for lat/lon format Point wgs84Point = (Point) GeometryEngine.project(mapPoint, SpatialReferences.getWgs84()); Graphic graphicsFromLayer = getGraphicsFromLayer1(mapView.getGraphicsOverlays(), Math.round(motionEvent.getX()), Math.round(motionEvent.getY())); if (graphicsFromLayer != null) { Point point = (Point) graphicsFromLayer.getGeometry(); onClickMapListener.onClickMap(graphicsFromLayer, point); } }
從一個圖層裏裏 查找獲得 Graphics對象. x,y是屏幕座標,layer是GraphicsLayer目標圖層(要查找的)。相差的距離是50像素。
public Graphic getGraphicsFromLayer1(List<GraphicsOverlay> graphicsOverlay, double xScreen, double yScreen) { //遍歷arcgis地圖, for (GraphicsOverlay g : graphicsOverlay) { for (Graphic graphic : g.getGraphics()) { Point geometry = (Point) graphic.getGeometry(); android.graphics.Point point = mapView.locationToScreen(geometry); double x1 = point.x; double y1 = point.y; if (Math.sqrt((xScreen - x1) * (xScreen - x1) + (yScreen - y1) * (yScreen - y1)) < 50) { //觸發了點擊 return graphic; } } } return null;
展示地圖彈窗
public Callout showTextPop(String text, Point arcgisPoint) { TextView calloutContent = new TextView(mapView.getContext()); calloutContent.setTextColor(Color.BLACK); calloutContent.setSingleLine(); // format coordinates to 4 decimal places calloutContent.setText(text); return showPop(calloutContent, arcgisPoint); }
-
-
最後上代碼 代碼地址
作者:是路不是陸
鏈接:https://www.jianshu.com/p/9892a7fc5abe
來源:簡書
著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。