ArcGis for Android在地图上添加自定义图标
2020-07-28 本文已影响0人
HMZZS
- 导包在项目目录下build.gradle内添加
maven {url 'https://esri.bintray.com/arcgis'}
- 导包在app目录下的build.gradle内添加
implementation 'com.esri.arcgisruntime:arcgis-android:100.8.0'
- 在onCreate中调用地图的setOnTouchListener函数具体代码如下
mMapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
showImageAtMap(R.drawable.map_start, motionEvent);
return false;
}
});
private void showImageAtMap(int res, MotionEvent e) {
BitmapDrawable startDrawable = (BitmapDrawable) ContextCompat.getDrawable(getContext(), res);
final PictureMarkerSymbol pinSourceSymbol;
try {
pinSourceSymbol = PictureMarkerSymbol.createAsync(startDrawable).get();
pinSourceSymbol.loadAsync();
pinSourceSymbol.addDoneLoadingListener(new Runnable() {
@Override
public void run() {
//添加新图形
Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
Graphic pinSourceGraphic = new Graphic(point, pinSourceSymbol);
mGraphicsOverlay.getGraphics().add(pinSourceGraphic);
}
});
pinSourceSymbol.setOffsetY(20);
} catch (InterruptedException | ExecutionException ex) {
ex.printStackTrace();
}
}
单击地图即可在所点击的位置进行添加图片
-
如图所示
GIF.gif