public synchronized void setDimension(Dimension dimension) { if (this.dimension != null && this.dimension.equals(dimension)) { return; } this.dimension = dimension; destroyBitmaps(); if (dimension.width > 0 && dimension.height > 0) { this.odBitmap = this.graphicFactory.createBitmap(dimension.width, dimension.height, IS_TRANSPARENT); this.lmBitmap = this.graphicFactory.createBitmap(dimension.width, dimension.height, IS_TRANSPARENT); } } }
Bitmap create() { if (dimension.width > 0 && dimension.height > 0) { Bitmap bitmap = factory.createBitmap(dimension.width, dimension.height, isTransparent); bitmap.setBackgroundColor(color); return bitmap; } return null; } }
public MapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension mapViewDimension, DisplayModel displayModel, GraphicFactory graphicFactory, int width, int height) { this.mapViewPosition = mapViewPosition; this.mapViewDimension = mapViewDimension; this.displayModel = displayModel; this.graphicFactory = graphicFactory; this.mapScaleBitmap = graphicFactory.createBitmap(width, height); this.scaleBarPosition = DEFAULT_SCALE_BAR_POSITION; this.mapScaleCanvas = graphicFactory.createCanvas(); this.mapScaleCanvas.setBitmap(this.mapScaleBitmap); this.distanceUnitAdapter = MetricUnitAdapter.INSTANCE; this.visible = true; this.redrawNeeded = true; }
@Test public void drawTest() { for (int tileSize : TILE_SIZES) { Marker marker = new Marker(null, null, 0, 0); marker.setDisplayModel(new FixedTileSizeDisplayModel(tileSize)); BoundingBox boundingBox = new BoundingBox(-1, -1, 1, 1); Canvas canvas = GRAPHIC_FACTORY.createCanvas(); canvas.setBitmap(GRAPHIC_FACTORY.createBitmap(tileSize, tileSize)); Point point = new Point(0, 0); marker.draw(boundingBox, (byte) 0, canvas, point); marker.setLatLong(new LatLong(0, 0)); marker.draw(boundingBox, (byte) 0, canvas, point); marker.setBitmap(GRAPHIC_FACTORY.createBitmap(10, 20)); marker.draw(boundingBox, (byte) 0, canvas, point); } }
@Test public void drawTest() { for (int tileSize : TILE_SIZES) { Polyline polyline = new Polyline(null, GRAPHIC_FACTORY); polyline.setDisplayModel(new FixedTileSizeDisplayModel(tileSize)); BoundingBox boundingBox = new BoundingBox(-1, -1, 1, 1); Canvas canvas = GRAPHIC_FACTORY.createCanvas(); canvas.setBitmap(GRAPHIC_FACTORY.createBitmap(tileSize, tileSize)); Point point = new Point(0, 0); polyline.draw(boundingBox, (byte) 0, canvas, point); List<LatLong> latLongs = new ArrayList<>(); latLongs.add(new LatLong(0, 0)); latLongs.add(new LatLong(1, 1)); polyline.setPoints(latLongs); polyline.draw(boundingBox, (byte) 0, canvas, point); polyline.setPaintStroke(GRAPHIC_FACTORY.createPaint()); polyline.draw(boundingBox, (byte) 0, canvas, point); } }
Bitmap create() { if (dimension.width > 0 && dimension.height > 0) { Bitmap bitmap = factory.createBitmap(dimension.width, dimension.height, isTransparent); bitmap.setBackgroundColor(color); return bitmap; } return null; } }
public synchronized void setDimension(Dimension dimension) { if (this.dimension != null && this.dimension.equals(dimension)) { return; } this.dimension = dimension; destroyBitmaps(); if (dimension.width > 0 && dimension.height > 0) { this.odBitmap = this.graphicFactory.createBitmap(dimension.width, dimension.height, IS_TRANSPARENT); this.lmBitmap = this.graphicFactory.createBitmap(dimension.width, dimension.height, IS_TRANSPARENT); } } }
@Test public void isTransparentTest() { Paint paint = new AwtPaint(); Assert.assertFalse(paint.isTransparent()); paint.setColor(Color.TRANSPARENT); Assert.assertTrue(paint.isTransparent()); Bitmap bitmap = org.mapsforge.map.awt.graphics.AwtGraphicFactory.INSTANCE.createBitmap(1, 1); paint.setBitmapShader(bitmap); Assert.assertFalse(paint.isTransparent()); } }
@Test public void drawTest() { for (int tileSize : TILE_SIZES) { Polygon polygon = new Polygon(null, null, GRAPHIC_FACTORY); polygon.setDisplayModel(new FixedTileSizeDisplayModel(tileSize)); BoundingBox boundingBox = new BoundingBox(-1, -1, 1, 1); Canvas canvas = GRAPHIC_FACTORY.createCanvas(); canvas.setBitmap(GRAPHIC_FACTORY.createBitmap(tileSize, tileSize)); Point point = new Point(0, 0); polygon.draw(boundingBox, (byte) 0, canvas, point); List<LatLong> latLongs = new ArrayList<>(); latLongs.add(new LatLong(0, 0)); latLongs.add(new LatLong(1, 1)); polygon.setPoints(latLongs); polygon.draw(boundingBox, (byte) 0, canvas, point); polygon.setPaintFill(GRAPHIC_FACTORY.createPaint()); polygon.setPaintStroke(GRAPHIC_FACTORY.createPaint()); polygon.draw(boundingBox, (byte) 0, canvas, point); } }
@Test public void constructorTest() { LatLong latLong = new LatLong(0, 0); Bitmap bitmap = GRAPHIC_FACTORY.createBitmap(10, 20); Marker marker = new Marker(latLong, bitmap, 1, 2); Assert.assertEquals(latLong, marker.getLatLong()); Assert.assertEquals(bitmap, marker.getBitmap()); Assert.assertEquals(1, marker.getHorizontalOffset()); Assert.assertEquals(2, marker.getVerticalOffset()); }
public MapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension mapViewDimension, DisplayModel displayModel, GraphicFactory graphicFactory, int width, int height) { this.mapViewPosition = mapViewPosition; this.mapViewDimension = mapViewDimension; this.displayModel = displayModel; this.graphicFactory = graphicFactory; this.mapScaleBitmap = graphicFactory.createBitmap(width, height); this.scaleBarPosition = DEFAULT_SCALE_BAR_POSITION; this.mapScaleCanvas = graphicFactory.createCanvas(); this.mapScaleCanvas.setBitmap(this.mapScaleBitmap); this.distanceUnitAdapter = MetricUnitAdapter.INSTANCE; this.visible = true; this.redrawNeeded = true; }
@Test public void getTopLeftPointTest() { for (int tileSize : TILE_SIZES) { MapPosition mapPosition = new MapPosition(new LatLong(0, 0), (byte) 0); Canvas canvas = GRAPHIC_FACTORY.createCanvas(); canvas.setBitmap(GRAPHIC_FACTORY.createBitmap(tileSize, tileSize)); Point expectedPoint = new Point(0, 0); Assert.assertEquals(expectedPoint, MapPositionUtil.getTopLeftPoint(mapPosition, canvas.getDimension(), tileSize)); mapPosition = new MapPosition(new LatLong(0, 90), (byte) 1); expectedPoint = new Point(tileSize, (float) tileSize / 2); Assert.assertEquals(expectedPoint, MapPositionUtil.getTopLeftPoint(mapPosition, canvas.getDimension(), tileSize)); } } }
@Test public void drawTest() { for (int tileSize : TILE_SIZES) { Circle circle = new Circle(null, 0, null, null); circle.setDisplayModel(new FixedTileSizeDisplayModel(tileSize)); BoundingBox boundingBox = new BoundingBox(-1, -1, 1, 1); Canvas canvas = GRAPHIC_FACTORY.createCanvas(); canvas.setBitmap(GRAPHIC_FACTORY.createBitmap(tileSize, tileSize)); Point point = new Point(0, 0); circle.draw(boundingBox, (byte) 0, canvas, point); circle.setLatLong(new LatLong(0, 0)); circle.draw(boundingBox, (byte) 0, canvas, point); circle.setRadius(1); circle.draw(boundingBox, (byte) 0, canvas, point); circle.setPaintFill(GRAPHIC_FACTORY.createPaint()); circle.draw(boundingBox, (byte) 0, canvas, point); circle.setPaintStroke(GRAPHIC_FACTORY.createPaint()); circle.draw(boundingBox, (byte) 0, canvas, point); } }
@Test public void setterTest() { LatLong latLong = new LatLong(0, 0); Bitmap bitmap = GRAPHIC_FACTORY.createBitmap(10, 20); Marker marker = new Marker(null, null, 0, 0); Assert.assertNull(marker.getLatLong()); Assert.assertNull(marker.getBitmap()); Assert.assertEquals(0, marker.getHorizontalOffset()); Assert.assertEquals(0, marker.getVerticalOffset()); marker.setLatLong(latLong); Assert.assertEquals(latLong, marker.getLatLong()); marker.setBitmap(bitmap); Assert.assertEquals(bitmap, marker.getBitmap()); marker.setHorizontalOffset(-1); Assert.assertEquals(-1, marker.getHorizontalOffset()); marker.setVerticalOffset(-2); Assert.assertEquals(-2, marker.getVerticalOffset()); } }
@Test public void getBoundingBoxTest() { for (int tileSize : TILE_SIZES) { MapPosition mapPosition = new MapPosition(new LatLong(0, 0), (byte) 0); Canvas canvas = GRAPHIC_FACTORY.createCanvas(); canvas.setBitmap(GRAPHIC_FACTORY.createBitmap(tileSize, tileSize)); double latitudeMin = MercatorProjection.LATITUDE_MIN; double latitudeMax = MercatorProjection.LATITUDE_MAX; BoundingBox expectedBoundingBox = new BoundingBox(latitudeMin, -180, latitudeMax, 180); Assert.assertEquals(expectedBoundingBox, MapPositionUtil.getBoundingBox(mapPosition, canvas.getDimension(), tileSize)); mapPosition = new MapPosition(new LatLong(0, 90), (byte) 0); expectedBoundingBox = new BoundingBox(latitudeMin, -90, latitudeMax, 180); Assert.assertEquals(expectedBoundingBox, MapPositionUtil.getBoundingBox(mapPosition, canvas.getDimension(), tileSize)); mapPosition = new MapPosition(new LatLong(90, -180), (byte) 0); expectedBoundingBox = new BoundingBox(0, -180, latitudeMax, 0); Assert.assertEquals(expectedBoundingBox, MapPositionUtil.getBoundingBox(mapPosition, canvas.getDimension(), tileSize)); } }