Update some parameters to improve performances of MapViewDrawing.

This commit is contained in:
Mikael Capelle 2018-03-02 11:19:00 +01:00
parent bd1c393053
commit d442a7e910

View File

@ -21,6 +21,7 @@ import org.mapsforge.core.model.BoundingBox;
import org.mapsforge.core.model.LatLong; import org.mapsforge.core.model.LatLong;
import org.mapsforge.core.model.MapPosition; import org.mapsforge.core.model.MapPosition;
import org.mapsforge.core.util.LatLongUtils; import org.mapsforge.core.util.LatLongUtils;
import org.mapsforge.core.util.Parameters;
import org.mapsforge.map.awt.graphics.AwtBitmap; import org.mapsforge.map.awt.graphics.AwtBitmap;
import org.mapsforge.map.awt.graphics.AwtGraphicFactory; import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
import org.mapsforge.map.awt.util.AwtUtil; import org.mapsforge.map.awt.util.AwtUtil;
@ -88,7 +89,7 @@ public class MapViewDrawing extends MapView implements Drawing {
Color color; Color color;
public MapViewMarkerOverlay(Marker marker, Color color) { public MapViewMarkerOverlay(Marker marker, Color color) {
super(new Layer[] { marker }); super(new Layer[]{ marker });
this.color = color; this.color = color;
} }
@ -107,8 +108,8 @@ public class MapViewDrawing extends MapView implements Drawing {
public void moveTo(Point point) { public void moveTo(Point point) {
Marker marker = (Marker) this.layers[0]; Marker marker = (Marker) this.layers[0];
this.delete(); this.delete();
marker = new Marker(convertPoint(point), marker.getBitmap(), marker.getHorizontalOffset(), marker = new Marker(convertPoint(point), marker.getBitmap(),
marker.getVerticalOffset()); marker.getHorizontalOffset(), marker.getVerticalOffset());
this.layers[0] = marker; this.layers[0] = marker;
MapViewDrawing.this.getLayerManager().getLayers().add(marker); MapViewDrawing.this.getLayerManager().getLayers().add(marker);
} }
@ -118,11 +119,11 @@ public class MapViewDrawing extends MapView implements Drawing {
private class MapViewPathOverlay extends MapViewOverlay implements PathOverlay { private class MapViewPathOverlay extends MapViewOverlay implements PathOverlay {
public MapViewPathOverlay(PolylineAutoScaling path, Marker origin, Marker destination) { public MapViewPathOverlay(PolylineAutoScaling path, Marker origin, Marker destination) {
super(new Layer[] { path, origin, destination }); super(new Layer[]{ path, origin, destination });
} }
public MapViewPathOverlay(PolylineAutoScaling path) { public MapViewPathOverlay(PolylineAutoScaling path) {
super(new Layer[] { path }); super(new Layer[]{ path });
} }
} }
@ -188,6 +189,10 @@ public class MapViewDrawing extends MapView implements Drawing {
private int tileSize; private int tileSize;
public MapViewDrawing() { public MapViewDrawing() {
super();
Parameters.NUMBER_OF_THREADS = 2;
Parameters.SQUARE_FRAME_BUFFER = false;
getMapScaleBar().setVisible(true); getMapScaleBar().setVisible(true);
DisplayModel model = getModel().displayModel; DisplayModel model = getModel().displayModel;
this.tileSize = DEFAULT_TILE_SIZE; this.tileSize = DEFAULT_TILE_SIZE;
@ -198,10 +203,11 @@ public class MapViewDrawing extends MapView implements Drawing {
return new LatLong(point.getLatitude(), point.getLongitude()); return new LatLong(point.getLatitude(), point.getLongitude());
} }
private TileRendererLayer createTileRendererLayer(TileCache tileCache, MapDataStore mapDataStore, private TileRendererLayer createTileRendererLayer(TileCache tileCache,
MapViewPosition mapViewPosition, HillsRenderConfig hillsRenderConfig) { MapDataStore mapDataStore, MapViewPosition mapViewPosition,
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore, mapViewPosition, false, HillsRenderConfig hillsRenderConfig) {
true, false, GRAPHIC_FACTORY, hillsRenderConfig) { TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
@Override @Override
public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY, public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY,
org.mapsforge.core.model.Point tapXY) { org.mapsforge.core.model.Point tapXY) {
@ -258,7 +264,8 @@ public class MapViewDrawing extends MapView implements Drawing {
public void drawGraph(File file) { public void drawGraph(File file) {
// Tile cache // Tile cache
TileCache tileCache = AwtUtil.createTileCache(tileSize, getModel().frameBufferModel.getOverdrawFactor(), 1024, TileCache tileCache = AwtUtil.createTileCache(tileSize,
getModel().frameBufferModel.getOverdrawFactor(), 1024,
new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString())); new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
// Layers // Layers
@ -271,10 +278,12 @@ public class MapViewDrawing extends MapView implements Drawing {
BoundingBox boundingBox = mapDataStore.boundingBox(); BoundingBox boundingBox = mapDataStore.boundingBox();
final Model model = getModel(); final Model model = getModel();
if (model.mapViewPosition.getZoomLevel() == 0 || !boundingBox.contains(model.mapViewPosition.getCenter())) { if (model.mapViewPosition.getZoomLevel() == 0
byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(), boundingBox, || !boundingBox.contains(model.mapViewPosition.getCenter())) {
model.displayModel.getTileSize()); byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
model.mapViewPosition.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel)); boundingBox, model.displayModel.getTileSize());
model.mapViewPosition
.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
} }
} }
@ -297,7 +306,8 @@ public class MapViewDrawing extends MapView implements Drawing {
PathOverlay overlay = null; PathOverlay overlay = null;
if (markers) { if (markers) {
Marker origin = createMarker(path.getOrigin().getPoint(), DEFAULT_PATH_COLOR), Marker origin = createMarker(path.getOrigin().getPoint(), DEFAULT_PATH_COLOR),
destination = createMarker(path.getDestination().getPoint(), DEFAULT_PATH_COLOR); destination = createMarker(path.getDestination().getPoint(),
DEFAULT_PATH_COLOR);
overlay = new MapViewPathOverlay(line, origin, destination); overlay = new MapViewPathOverlay(line, origin, destination);
} }
else { else {