@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); polygon.getLatLongs().add(new LatLong(0, 0)); polygon.getLatLongs().add(new LatLong(1, 1)); polygon.draw(boundingBox, (byte) 0, canvas, point); polygon.setPaintFill(GRAPHIC_FACTORY.createPaint()); polygon.setPaintStroke(GRAPHIC_FACTORY.createPaint()); polygon.draw(boundingBox, (byte) 0, canvas, point); } }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLongs.size() < 2 || (this.paintStroke == null && this.paintFill == null)) { return; } Iterator<LatLong> iterator = this.latLongs.iterator(); Path path = this.graphicFactory.createPath(); LatLong latLong = iterator.next(); int tileSize = displayModel.getTileSize(); float x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); float y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.moveTo(x, y); while (iterator.hasNext()) { latLong = iterator.next(); x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.lineTo(x, y); } if (this.paintStroke != null) { canvas.drawPath(path, this.paintStroke); } if (this.paintFill != null) { canvas.drawPath(path, this.paintFill); } }
Polygon extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLongs.size() < 2 || (this.paintStroke == null && this.paintFill == null)) { return; } Iterator<LatLong> iterator = this.latLongs.iterator(); Path path = this.graphicFactory.createPath(); LatLong latLong = iterator.next(); int tileSize = displayModel.getTileSize(); float x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); float y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.moveTo(x, y); while (iterator.hasNext()) { latLong = iterator.next(); x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.lineTo(x, y); } if (this.paintStroke != null) { canvas.drawPath(path, this.paintStroke); } if (this.paintFill != null) { canvas.drawPath(path, this.paintFill); } } }
Polygon extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLongs.size() < 2 || (this.paintStroke == null && this.paintFill == null)) { return; } Iterator<LatLong> iterator = this.latLongs.iterator(); Path path = this.graphicFactory.createPath(); LatLong latLong = iterator.next(); int tileSize = displayModel.getTileSize(); float x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); float y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.moveTo(x, y); while (iterator.hasNext()) { latLong = iterator.next(); x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.lineTo(x, y); } if (this.paintStroke != null) { canvas.drawPath(path, this.paintStroke); } if (this.paintFill != null) { canvas.drawPath(path, this.paintFill); } } Polygon(Paint paintFill, Paint paintStroke, GraphicFactory graphicFactory); }
Polygon extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLongs.size() < 2 || (this.paintStroke == null && this.paintFill == null)) { return; } Iterator<LatLong> iterator = this.latLongs.iterator(); Path path = this.graphicFactory.createPath(); LatLong latLong = iterator.next(); int tileSize = displayModel.getTileSize(); float x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); float y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.moveTo(x, y); while (iterator.hasNext()) { latLong = iterator.next(); x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.lineTo(x, y); } if (this.paintStroke != null) { canvas.drawPath(path, this.paintStroke); } if (this.paintFill != null) { canvas.drawPath(path, this.paintFill); } } Polygon(Paint paintFill, Paint paintStroke, GraphicFactory graphicFactory); @Override synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint); List<LatLong> getLatLongs(); synchronized Paint getPaintFill(); synchronized Paint getPaintStroke(); synchronized void setPaintFill(Paint paintFill); synchronized void setPaintStroke(Paint paintStroke); }
Polygon extends Layer { @Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLongs.size() < 2 || (this.paintStroke == null && this.paintFill == null)) { return; } Iterator<LatLong> iterator = this.latLongs.iterator(); Path path = this.graphicFactory.createPath(); LatLong latLong = iterator.next(); int tileSize = displayModel.getTileSize(); float x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); float y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.moveTo(x, y); while (iterator.hasNext()) { latLong = iterator.next(); x = (float) (MercatorProjection.longitudeToPixelX(latLong.longitude, zoomLevel, tileSize) - topLeftPoint.x); y = (float) (MercatorProjection.latitudeToPixelY(latLong.latitude, zoomLevel, tileSize) - topLeftPoint.y); path.lineTo(x, y); } if (this.paintStroke != null) { canvas.drawPath(path, this.paintStroke); } if (this.paintFill != null) { canvas.drawPath(path, this.paintFill); } } Polygon(Paint paintFill, Paint paintStroke, GraphicFactory graphicFactory); @Override synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint); List<LatLong> getLatLongs(); synchronized Paint getPaintFill(); synchronized Paint getPaintStroke(); synchronized void setPaintFill(Paint paintFill); synchronized void setPaintStroke(Paint paintStroke);  }