How to set bounding box in mapsforge just like in osmdroid and how do I put a text above or below the pathLayer?
In osmdroid, I usually call the setScrollableAreaLimit()
method but in mapsforge there's no such method in the mapView
. How do I accomplish this?
And also how do I add a TextOverlay
below or above the PathLayer
?
//Bounding Box
maxScrollableLimit = new BoundingBox(14.7882,121.1421,14.3469,120.8990);
...
private PathLayer createPathLayerFirst(PathWrapper response) {
Style style = Style.builder()
.generalization(Style.GENERALIZATION_SMALL)
.strokeColor(0x9900cc33)
.strokeWidth(4 * getResources().getDisplayMetrics().density)
.build();
PathLayer pathLayer = new PathLayer(mapView.map(), style);
List<GeoPoint> geoPoints = new ArrayList<>();
PointList pointList = response.getPoints();
for (int i = 0; i < pointList.getSize(); i++)
geoPoints.add(new GeoPoint(pointList.getLatitude(i), pointList.getLongitude(i)));
pathLayer.setPoints(geoPoints);
return pathLayer;
}
From the code you provide, it is not clear if you looked at the mapsforge docs at all. Do so first, then return to my answer.
For setting map limits, add the following code to your onStart() method:
mapView.getModel().mapViewPosition.setMapLimit(this.getBoundingBox());
And in the same class, have the following method ready:
private BoundingBox getBoundingBox() {
final double MINLAT = Double.valueOf(res.getString(R.string.mapminlat));
final double MINLON = Double.valueOf(res.getString(R.string.mapminlon));
final double MAXLAT = Double.valueOf(res.getString(R.string.mapmaxlat));
final double MAXLON = Double.valueOf(res.getString(R.string.mapmaxlon));
return new BoundingBox(MINLAT, MINLON, MAXLAT, MAXLON);
}
For adding a layer to your mapview do the following:
mapView.getLayerManager().getLayers().add(layer);
For creating a layer, see the docs. Take a special look at the examples; maybe the LabelLayer is what you are looking for.