@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); } }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null) { return; } int tileSize = this.displayModel.getTileSize(); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, zoomLevel, tileSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, zoomLevel, tileSize); int halfBitmapWidth = this.bitmap.getWidth() / 2; int halfBitmapHeight = this.bitmap.getHeight() / 2; int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset); int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset); int right = left + this.bitmap.getWidth(); int bottom = top + this.bitmap.getHeight(); Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersects(bitmapRectangle)) { return; } canvas.drawBitmap(this.bitmap, left, top); }
Marker extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null) { return; } int tileSize = this.displayModel.getTileSize(); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, zoomLevel, tileSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, zoomLevel, tileSize); int halfBitmapWidth = this.bitmap.getWidth() / 2; int halfBitmapHeight = this.bitmap.getHeight() / 2; int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset); int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset); int right = left + this.bitmap.getWidth(); int bottom = top + this.bitmap.getHeight(); Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersects(bitmapRectangle)) { return; } canvas.drawBitmap(this.bitmap, left, top); } }
Marker extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null) { return; } int tileSize = this.displayModel.getTileSize(); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, zoomLevel, tileSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, zoomLevel, tileSize); int halfBitmapWidth = this.bitmap.getWidth() / 2; int halfBitmapHeight = this.bitmap.getHeight() / 2; int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset); int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset); int right = left + this.bitmap.getWidth(); int bottom = top + this.bitmap.getHeight(); Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersects(bitmapRectangle)) { return; } canvas.drawBitmap(this.bitmap, left, top); } Marker(LatLong latLong, Bitmap bitmap, int horizontalOffset, int verticalOffset); }
Marker extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null) { return; } int tileSize = this.displayModel.getTileSize(); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, zoomLevel, tileSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, zoomLevel, tileSize); int halfBitmapWidth = this.bitmap.getWidth() / 2; int halfBitmapHeight = this.bitmap.getHeight() / 2; int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset); int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset); int right = left + this.bitmap.getWidth(); int bottom = top + this.bitmap.getHeight(); Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersects(bitmapRectangle)) { return; } canvas.drawBitmap(this.bitmap, left, top); } Marker(LatLong latLong, Bitmap bitmap, int horizontalOffset, int verticalOffset); synchronized boolean contains(Point center, Point point); @Override synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint); synchronized Bitmap getBitmap(); synchronized int getHorizontalOffset(); synchronized LatLong getLatLong(); synchronized LatLong getPosition(); synchronized int getVerticalOffset(); @Override synchronized void onDestroy(); synchronized void setBitmap(Bitmap bitmap); synchronized void setHorizontalOffset(int horizontalOffset); synchronized void setLatLong(LatLong latLong); synchronized void setVerticalOffset(int verticalOffset); }
Marker extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null) { return; } int tileSize = this.displayModel.getTileSize(); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, zoomLevel, tileSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, zoomLevel, tileSize); int halfBitmapWidth = this.bitmap.getWidth() / 2; int halfBitmapHeight = this.bitmap.getHeight() / 2; int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset); int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset); int right = left + this.bitmap.getWidth(); int bottom = top + this.bitmap.getHeight(); Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersects(bitmapRectangle)) { return; } canvas.drawBitmap(this.bitmap, left, top); } Marker(LatLong latLong, Bitmap bitmap, int horizontalOffset, int verticalOffset); synchronized boolean contains(Point center, Point point); @Override synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint); synchronized Bitmap getBitmap(); synchronized int getHorizontalOffset(); synchronized LatLong getLatLong(); synchronized LatLong getPosition(); synchronized int getVerticalOffset(); @Override synchronized void onDestroy(); synchronized void setBitmap(Bitmap bitmap); synchronized void setHorizontalOffset(int horizontalOffset); synchronized void setLatLong(LatLong latLong); synchronized void setVerticalOffset(int verticalOffset);  }