Reputation: 967
I'm trying to draw a simple way, a route, in my Android app with Mapsforge. I have followed an example and I created single points, OverlayItems. But when I try to draw a route I don't see anything in my map. Can anybody help me? Here is my simple code:
Paint wayPaint = new Paint();
wayPaint.setColor(color.Chocolate);
ArrayWayOverlay wayOverlay = new ArrayWayOverlay(wayPaint,wayPaint);
GeoPoint gp1 = new GeoPoint(41.38, 2.15);
GeoPoint gp2 = new GeoPoint(41.39, 2.15);
GeoPoint gp3 = new GeoPoint(41.40, 2.15);
GeoPoint gp4 = new GeoPoint(41.41, 2.15);
OverlayWay way = new OverlayWay(new GeoPoint[][] { { gp1, gp2, gp3, gp4 } });
wayOverlay.addWay(way);
mapView.getOverlays().add(wayOverlay);
I don't know if I have to put markers somewhere...
Upvotes: 1
Views: 5596
Reputation: 5063
The OverlayWay
api has been deprecated as of v-0.4.0
. Since I had a hard time finding new ways to draw overlays on the map I thought I post this here.Mapsforge
now has added the following types of overlays:
1. Circle
2. FixedPixelCircle
3. Marker
4. Polygon
5. Polyline
All of the new classes extends the Layer
class, making it easy to implement. You instantiate the required object and add it to the MapView
like this.
// instantiating the paint object
Paint paint = AndroidGraphicFactory.INSTANCE.createPaint();
paint.setColor(color);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(style);
// instantiating the polyline object
Polyline polyline = new Polyline(paint, AndroidGraphicFactory.INSTANCE);
// set lat lng for the polyline
List<LatLong> coordinateList = polyline.getLatLongs();
coordinateList.add(latlng1);
coordinateList.add(latlng2);
coordinateList.add(latlng3);
coordinateList.add(latlng4);
coordinateList.add(latlng5);
// adding the layer to the mapview
mapView.getLayerManager().getLayers().add(polyline);
There is also a mapsforge example link available.
Upvotes: 10
Reputation: 174
try set the wayPaint Style and the stroke width, like this:
Paint wayPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
wayPaint.setStyle(Paint.Style.STROKE);
wayPaint.setColor(Color.BLUE);
wayPaint.setAlpha(192);
wayPaint.setStrokeWidth(6);
wayDefaultPaintFill.setStrokeJoin(Paint.Join.MITER);
ArrayWayOverlay wayOverlay = new ArrayWayOverlay(wayPaint,wayPaint);
//your points
OverlayWay way = new OverlayWay(new GeoPoint[][] { {geoPoint1,geoPoint2,... } });
wayOverlay.addWay(way);
mapView.Overlays().add(wayOverlay);
hope this helps!
Upvotes: 4