osmdroid,在一个图形页面设置自定义图标 [英] osmdroid, set a custom icon in a mapview
问题描述
我的应用程序使用的是本地服务,提供了改变位置。
这些位置将被添加到我的ArrayList:
静态列表WEG =新的ArrayList();
在'WegAnsehenActivity现在显示连接点的路径。
结果我的目标:我要改变路径上的图标,在过去的当前点
结果完成:我想改变的最后一个位置的绿色箭头
结果我的问题:我如何才能做到这一点。
my App is using a local service, that provides changing locations.
These locations are added to my ArrayList:
static List weg = new ArrayList();
The 'WegAnsehenActivity' now shows the path connecting the points.
My goal: I want to change the icon on the path for the last current point
completion: I want to change the green arrow on the last position
My problem: how can I achieve this ?
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.PathOverlay;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
.
.
.
public class WegAnsehenActivity extends Activity {
MapView mapView;
IMapController mapController;
MyLocationNewOverlay o;
Paint paint;
PathOverlay overlay;
//filled by the local service, method onLocationChanged
static List<Location> weg = new ArrayList<Location>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
mapController = mapView.getController();
//false keeps the mapView from loading online tiles using network connection!!!
mapView.setUseDataConnection(false);//true);
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(7);
paint.setColor(Color.BLUE);
overlay = new PathOverlay(Color.BLUE, this);
overlay.setPaint(paint);
o = new MyLocationNewOverlay(getApplicationContext(), mapView);
}
@Override
protected void onResume() {
super.onResume();
mapController.setZoom(16);
if (weg.size() >= 1) {
for (int i = 0; i < weg.size(); i++) {
if (i==weg.size()-1) {
mapController.setCenter(new GeoPoint(weg.get(i).getLatitude(), weg.get(i).getLongitude()));
}
GeoPoint point = new GeoPoint(weg.get(i));
overlay.addPoint(point);
}
mapView.getOverlayManager().add(overlay);
o.enableMyLocation(); //shows a green arrow I want to replace
mapView.getOverlays().add(o);
mapView.postInvalidate();
}
}
}
请帮帮忙!
问候Wicki
推荐答案
谢谢你的建议。
现在我已经找到了解决办法。结果
我已经注释掉指令o.enableMyLocation();,这是负责标准图标结果。
它遵循的最后4个指令替换:搜索
Thanks for the advices.
Now I have found a solution.
I have commented out the instruction "o.enableMyLocation();", that is responsible for standard icon.
It follows the replacement for the last 4 instructions:
mapView.getOverlayManager().add(overlay);
// o.enableMyLocation(); //shows the green-arrow-marker (my own position)
mapView.getOverlays().add(o);
setMarker(); //set an own marker
mapView.postInvalidate();
.
.
void setMarker() {
Drawable marker = getResources().getDrawable(R.drawable.icon);
ItemizedIconOverlay<OverlayItem> overlay = new ItemizedIconOverlay<OverlayItem>(
new ArrayList<OverlayItem>(), marker, null,
new DefaultResourceProxyImpl(this));
// gc: last GeoPoint
OverlayItem item = new OverlayItem(null, null, gc);
overlay.addItem(item);
mapView.getOverlays().add(overlay);
}
问候Wicki
Regards Wicki
这篇关于osmdroid,在一个图形页面设置自定义图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!