@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); } }
public synchronized boolean contains(Point center, Point point, double latitude, byte zoomLevel) { // Touch min 20x20 px at baseline mdpi (160dpi) double distance = Math.max(20 / 2 * this.displayModel.getScaleFactor(), getRadiusInPixels(latitude, zoomLevel)); return center.distance(point) < distance; }
/** * @param radius the new non-negative radius of this circle in meters. * @throws IllegalArgumentException if the given {@code radius} is negative or {@link Float#NaN}. */ public synchronized void setRadius(float radius) { setRadiusInternal(radius); }
@Test public void setterTest() { LatLong latLong = new LatLong(1, 2); Paint paintFill = GRAPHIC_FACTORY.createPaint(); Paint paintStroke = GRAPHIC_FACTORY.createPaint(); Circle circle = new Circle(null, 0, null, null); Assert.assertNull(circle.getPosition()); Assert.assertEquals(0, circle.getRadius(), 0); Assert.assertNull(circle.getPaintFill()); Assert.assertNull(circle.getPaintStroke()); circle.setLatLong(latLong); Assert.assertEquals(latLong, circle.getPosition()); circle.setRadius(1); Assert.assertEquals(1, circle.getRadius(), 0); circle.setPaintFill(paintFill); Assert.assertEquals(paintFill, circle.getPaintFill()); circle.setPaintStroke(paintStroke); Assert.assertEquals(paintStroke, circle.getPaintStroke()); } }
@Test public void constructorTest() { LatLong latLong = new LatLong(0, 0); int radius = 3; Paint paintFill = GRAPHIC_FACTORY.createPaint(); Paint paintStroke = GRAPHIC_FACTORY.createPaint(); Circle circle = new Circle(latLong, radius, paintFill, paintStroke); Assert.assertEquals(latLong, circle.getPosition()); Assert.assertEquals(radius, circle.getRadius(), 0); Assert.assertEquals(paintFill, circle.getPaintFill()); Assert.assertEquals(paintStroke, circle.getPaintStroke()); verifyInvalidRadius(latLong, -1, paintFill, paintStroke); verifyInvalidRadius(latLong, Float.NaN, paintFill, paintStroke); }
private static Circle createCircle(LatLong latLong, float radius, Paint paintFill, Paint paintStroke) { return new Circle(latLong, radius, paintFill, paintStroke); }
protected void onLongPress(LatLong position) { if (this.mapRequest == null) this.mapRequest = new MapRequest(); this.mapRequest.setNorth(position.latitude); this.mapRequest.setEast(position.longitude); showAddress(position); Layers layers = mapView.getLayerManager().getLayers(); //this.mapViews.get(0).getLayerManager().getLayers() if (index >= 0) layers.remove(index); float circleSize = 8 * this.mapView.getModel().displayModel.getScaleFactor(); Paint GREEN = Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.GREEN), 0, Style.FILL); Circle circle = new Circle(position, circleSize, GREEN, null); layers.add(circle); index = layers.size() - 1; circle.requestRedraw(); }
public void setPosition(double latitude, double longitude, float accuracy) { synchronized (this) { LatLong latLong = new LatLong(latitude, longitude); this.marker.setLatLong(latLong); if (this.circle != null) { this.circle.setLatLong(latLong); this.circle.setRadius(accuracy); } requestRedraw(); } } }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.circle != null) { this.circle.draw(boundingBox, zoomLevel, canvas, topLeftPoint); } this.marker.draw(boundingBox, zoomLevel, canvas, topLeftPoint); }
@Override protected void onAdd() { if (this.circle != null) { this.circle.setDisplayModel(this.displayModel); } this.marker.setDisplayModel(this.displayModel); }
final Circle circle = new Circle(point, CIRCLE_WIFI_CATALOG_WIDTH, mPaintCatalogFill, mPaintCatalogStroke); mCatalogObjects.add(circle);
/** * @param latLong the initial center point of this circle (may be null). * @param radius the initial non-negative radius of this circle in meters. * @param paintFill the initial {@code Paint} used to fill this circle (may be null). * @param paintStroke the initial {@code Paint} used to stroke this circle (may be null). * @param keepAligned if set to true it will keep the bitmap aligned with the map, * to avoid a moving effect of a bitmap shader. * @throws IllegalArgumentException if the given {@code radius} is negative or {@link Float#NaN}. */ public Circle(LatLong latLong, float radius, Paint paintFill, Paint paintStroke, boolean keepAligned) { super(); this.keepAligned = keepAligned; this.latLong = latLong; setRadiusInternal(radius); this.paintFill = paintFill; this.paintStroke = paintStroke; }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || (this.paintStroke == null && this.paintFill == null)) { return; } double latitude = this.latLong.latitude; double longitude = this.latLong.longitude; long mapSize = MercatorProjection.getMapSize(zoomLevel, displayModel.getTileSize()); int pixelX = (int) (MercatorProjection.longitudeToPixelX(longitude, mapSize) - topLeftPoint.x); int pixelY = (int) (MercatorProjection.latitudeToPixelY(latitude, mapSize) - topLeftPoint.y); int radiusInPixel = getRadiusInPixels(latitude, zoomLevel); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersectsCircle(pixelX, pixelY, radiusInPixel)) { return; } if (this.paintStroke != null) { if (this.keepAligned) { this.paintStroke.setBitmapShaderShift(topLeftPoint); } canvas.drawCircle(pixelX, pixelY, radiusInPixel, this.paintStroke); } if (this.paintFill != null) { if (this.keepAligned) { this.paintFill.setBitmapShaderShift(topLeftPoint); } canvas.drawCircle(pixelX, pixelY, radiusInPixel, this.paintFill); } }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override protected void createLayers() { super.createLayers(); // marker to show at the location Drawable drawable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDrawable(R.drawable.ic_maps_indicator_current_position) : getResources().getDrawable(R.drawable.ic_maps_indicator_current_position); Marker marker = new Marker(null, AndroidGraphicFactory.convertToBitmap(drawable), 0, 0); // circle to show the location accuracy (optional) Circle circle = new Circle(null, 0, getPaint(AndroidGraphicFactory.INSTANCE.createColor(48, 0, 0, 255), 0, Style.FILL), getPaint(AndroidGraphicFactory.INSTANCE.createColor(160, 0, 0, 255), 2, Style.STROKE)); // create the overlay this.myLocationOverlay = new MyLocationOverlay(marker, circle); this.mapView.getLayerManager().getLayers().add(this.myLocationOverlay); }
/** * @param radius the new non-negative radius of this circle in meters. * @throws IllegalArgumentException if the given {@code radius} is negative or {@link Float#NaN}. */ public synchronized void setRadius(float radius) { setRadiusInternal(radius); }
public synchronized boolean contains(Point center, Point point, double latitude, byte zoomLevel) { // Touch min 20x20 px at baseline mdpi (160dpi) double distance = Math.max(20 / 2 * this.displayModel.getScaleFactor(), getRadiusInPixels(latitude, zoomLevel)); return center.distance(point) < distance; }
/** * @param latLong the initial center point of this circle (may be null). * @param radius the initial non-negative radius of this circle in meters. * @param paintFill the initial {@code Paint} used to fill this circle (may be null). * @param paintStroke the initial {@code Paint} used to stroke this circle (may be null). * @param keepAligned if set to true it will keep the bitmap aligned with the map, * to avoid a moving effect of a bitmap shader. * @throws IllegalArgumentException if the given {@code radius} is negative or {@link Float#NaN}. */ public Circle(LatLong latLong, float radius, Paint paintFill, Paint paintStroke, boolean keepAligned) { super(); this.keepAligned = keepAligned; this.latLong = latLong; setRadiusInternal(radius); this.paintFill = paintFill; this.paintStroke = paintStroke; }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || (this.paintStroke == null && this.paintFill == null)) { return; } double latitude = this.latLong.latitude; double longitude = this.latLong.longitude; long mapSize = MercatorProjection.getMapSize(zoomLevel, displayModel.getTileSize()); int pixelX = (int) (MercatorProjection.longitudeToPixelX(longitude, mapSize) - topLeftPoint.x); int pixelY = (int) (MercatorProjection.latitudeToPixelY(latitude, mapSize) - topLeftPoint.y); int radiusInPixel = getRadiusInPixels(latitude, zoomLevel); Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight()); if (!canvasRectangle.intersectsCircle(pixelX, pixelY, radiusInPixel)) { return; } if (this.paintStroke != null) { if (this.keepAligned) { this.paintStroke.setBitmapShaderShift(topLeftPoint); } canvas.drawCircle(pixelX, pixelY, radiusInPixel, this.paintStroke); } if (this.paintFill != null) { if (this.keepAligned) { this.paintFill.setBitmapShaderShift(topLeftPoint); } canvas.drawCircle(pixelX, pixelY, radiusInPixel, this.paintFill); } }