引入:
项目build.gradle添加
repositories {
google()
jcenter()
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://esri.bintray.com/arcgis' }
}
}
app下的build.gradle中
implementation 'com.esri.arcgisruntime:arcgis-android:100.2.0'
在AndroidManifest.xml中添加权限
构建成功,开始使用。(ps:最开始引入的是android studio 2.3.3,一样的做法,但是不成功,可能有版本的原因)
去除水印
String licenseCode = "runtimelite,1000,rud7659408794,none,ZZ0RJAY3FY0GEBZNR002";
ArcGISRuntimeEnvironment.setLicense(licenseCode);
去除logo
mMapView.setAttributionTextVisible(false);
使用:使用的是切片地图
布局文件:
activity中:
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mMapView = findViewById(R.id.map);
//去除水印
String licenseCode = "runtimelite,1000,rud7659408794,none,ZZ0RJAY3FY0GEBZNR002";
ArcGISRuntimeEnvironment.setLicense(licenseCode);
//去除logo
mMapView.setAttributionTextVisible(false);
String dynamicMapUrl = "http://10.10.9.131:6080/arcgis/rest/services/cgxt/GXCGTile/MapServer";
ArcGISMapImageLayer mainMapImageLayer = new ArcGISMapImageLayer(dynamicMapUrl);
Basemap basemap = new Basemap(mainMapImageLayer);
ArcGISMap arcGISMap = new ArcGISMap(basemap);
Viewpoint vp = new Viewpoint(28.6947965376, 115.8439087642, 72223.819286);
arcGISMap.setInitialViewpoint(vp);
mMapView.setMap(arcGISMap);
}
引入成功,未完待续。
点击事件
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onSingleTapConfirmed(MotionEvent v) {
//移除符号
mMapView.getGraphicsOverlays().clear();
android.graphics.Point screenPoint = new android.graphics.Point(Math.round(v.getX()), Math.round(v.getY()));
Point clickPoint = mMapView.screenToLocation(screenPoint);
GraphicsOverlay mGraphicsOverlay = new GraphicsOverlay();
BitmapDrawable pinStarBlueDrawable = (BitmapDrawable) ContextCompat.getDrawable(getApplicationContext(), R.drawable.map);
PictureMarkerSymbol pinStarBlueSymbol = new PictureMarkerSymbol(pinStarBlueDrawable);
pinStarBlueSymbol.setHeight(30);
pinStarBlueSymbol.setWidth(30);
pinStarBlueSymbol.setOffsetY(11);
pinStarBlueSymbol.loadAsync();
Graphic pointGraphic = new Graphic(clickPoint, pinStarBlueSymbol);
mGraphicsOverlay.getGraphics().add(pointGraphic);
mMapView.getGraphicsOverlays().add(mGraphicsOverlay);
String mail = "经度" + v.getX() + "纬度" + v.getY();
Toast.makeText(MapRealSceneActivity.this, mail, Toast.LENGTH_SHORT).show();
return true;
}
});
隐藏背景格网
BackgroundGrid mainBackgroundGrid = new BackgroundGrid();
mainBackgroundGrid.setColor(0xffffffff);
mainBackgroundGrid.setGridLineColor(0xffffffff);
mainBackgroundGrid.setGridLineWidth(0);
mMapView.setBackgroundGrid(mainBackgroundGrid);
//添加图标
GraphicsOverlay mGraphicsOverlay = new GraphicsOverlay();
mMapView.getGraphicsOverlays().add(mGraphicsOverlay);
BitmapDrawable pinStarBlueDrawable = (BitmapDrawable) ContextCompat.getDrawable(getApplicationContext(), R.drawable.map);
final PictureMarkerSymbol pinStarBlueSymbol = new PictureMarkerSymbol(pinStarBlueDrawable);
pinStarBlueSymbol.setHeight(30);
pinStarBlueSymbol.setWidth(30);
pinStarBlueSymbol.setOffsetY(11);
pinStarBlueSymbol.loadAsync();
Point pinStarBluePoint = new Point(lon, lat, SpatialReferences.getWgs84());
//Point pinStarBluePoint = new Point(115.995476, 28.707612, SpatialReferences.getWgs84());
Graphic pinStarBlueGraphic = new Graphic(pinStarBluePoint, pinStarBlueSymbol);
mGraphicsOverlay.getGraphics().add(pinStarBlueGraphic);
加载离线地图tpk
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/layers/GXCGTile.tpk";
TileCache titleCache = new TileCache(path);
ArcGISTiledLayer arcGISTiledLayer = new ArcGISTiledLayer(titleCache);
Basemap basemap = new Basemap(arcGISTiledLayer);
ArcGISMap mArcGISMap = new ArcGISMap(basemap);
Viewpoint vp = new Viewpoint(28.69378, 115.980678, 100223.819286);
mArcGISMap.setInitialViewpoint(vp);
mMapView.setMap(mArcGISMap);