private float computeHorizontalOffset() { // compute only the offset required by the bitmap, not the text size, // because at this point we do not know the text boxing if (Position.RIGHT == this.position || Position.LEFT == this.position || Position.BELOW_RIGHT == this.position || Position.BELOW_LEFT == this.position || Position.ABOVE_RIGHT == this.position || Position.ABOVE_LEFT == this.position) { float horizontalOffset = this.bitmap.getWidth() / 2f + this.gap; if (Position.LEFT == this.position || Position.BELOW_LEFT == this.position || Position.ABOVE_LEFT == this.position) { horizontalOffset *= -1f; } return horizontalOffset; } return 0; }
@Override public void setBitmapShader(Bitmap bitmap) { if (bitmap == null) { return; } this.shaderWidth = bitmap.getWidth(); this.shaderHeight = bitmap.getHeight(); Rectangle rectangle = new Rectangle(0, 0, bitmap.getWidth(), bitmap.getHeight()); this.texturePaint = new TexturePaint(AwtGraphicFactory.getBitmap(bitmap), rectangle); }
public SymbolContainer(Point point, Display display, int priority, Bitmap symbol, float theta, boolean alignCenter) { super(point, display, priority); this.symbol = symbol; this.theta = theta; this.alignCenter = alignCenter; if (alignCenter) { double halfWidth = this.symbol.getWidth() / 2d; double halfHeight = this.symbol.getHeight() / 2d; this.boundary = new Rectangle(-halfWidth, -halfHeight, halfWidth, halfHeight); } else { this.boundary = new Rectangle(0, 0, this.symbol.getWidth(), this.symbol.getHeight()); } this.symbol.incrementRefCount(); }
public synchronized boolean contains(Point center, Point point) { // Touch min 20x20 px at baseline mdpi (160dpi) double width = Math.max(20 * this.displayModel.getScaleFactor(), this.bitmap.getWidth()); double height = Math.max(20 * this.displayModel.getScaleFactor(), this.bitmap.getHeight()); Rectangle r = new Rectangle( center.x - width / 2 + this.horizontalOffset, center.y - height / 2 + this.verticalOffset, center.x + width / 2 + this.horizontalOffset, center.y + height / 2 + this.verticalOffset); return r.contains(point); }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null || this.bitmap.isDestroyed()) { return; } long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize()); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, mapSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, mapSize); 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); }
/** * Calculates the required length and value of the scalebar * * @param unitAdapter the DistanceUnitAdapter to calculate for * @return a {@link ScaleBarLengthAndValue} object containing the required scaleBarLength and scaleBarValue */ protected ScaleBarLengthAndValue calculateScaleBarLengthAndValue(DistanceUnitAdapter unitAdapter) { this.prevMapPosition = this.mapViewPosition.getMapPosition(); double groundResolution = MercatorProjection.calculateGroundResolution(this.prevMapPosition.latLong.latitude, MercatorProjection.getMapSize(this.prevMapPosition.zoomLevel, this.displayModel.getTileSize())); groundResolution = groundResolution / unitAdapter.getMeterRatio(); int[] scaleBarValues = unitAdapter.getScaleBarValues(); int scaleBarLength = 0; int mapScaleValue = 0; for (int scaleBarValue : scaleBarValues) { mapScaleValue = scaleBarValue; scaleBarLength = (int) (mapScaleValue / groundResolution); if (scaleBarLength < (this.mapScaleBitmap.getWidth() - 10)) { break; } } return new ScaleBarLengthAndValue(scaleBarLength, mapScaleValue); }
/** * Called from {@link MapView} * * @param graphicContext The graphicContext to use to draw the MapScaleBar */ public void draw(GraphicContext graphicContext) { if (!this.visible) { return; } if (this.mapViewDimension.getDimension() == null) { return; } if (this.isRedrawNecessary()) { redraw(this.mapScaleCanvas); this.redrawNeeded = false; } int positionLeft = calculatePositionLeft(0, this.mapViewDimension.getDimension().width, this.mapScaleBitmap.getWidth()); int positionTop = calculatePositionTop(0, this.mapViewDimension.getDimension().height, this.mapScaleBitmap.getHeight()); graphicContext.drawBitmap(this.mapScaleBitmap, positionLeft, positionTop); }
private float computeHorizontalOffset() { // compute only the offset required by the bitmap, not the text size, // because at this point we do not know the text boxing if (Position.RIGHT == this.position || Position.LEFT == this.position || Position.BELOW_RIGHT == this.position || Position.BELOW_LEFT == this.position || Position.ABOVE_RIGHT == this.position || Position.ABOVE_LEFT == this.position) { float horizontalOffset = this.bitmap.getWidth() / 2f + this.gap; if (Position.LEFT == this.position || Position.BELOW_LEFT == this.position || Position.ABOVE_LEFT == this.position) { horizontalOffset *= -1f; } return horizontalOffset; } return 0; }
/** * Set group marker parameter. To know index and calculate position on spiral. * * @param index the index of this child marker. * @param bitmap the bitmap of the group marker. * @param horizontalOffset the horizontal offset of the group marker. * @param verticalOffset the vertical offset of the group marker. */ public void init(int index, Bitmap bitmap, int horizontalOffset, int verticalOffset) { this.index = index; this.groupBitmapHalfHeight = bitmap.getHeight() / 2; this.groupBitmapHalfWidth = bitmap.getWidth() / 2; this.groupHOffset = horizontalOffset; this.groupVOffset = verticalOffset; }
@Override public void setBitmapShader(Bitmap bitmap) { if (bitmap == null) { return; } this.shaderWidth = bitmap.getWidth(); this.shaderHeight = bitmap.getHeight(); Rectangle rectangle = new Rectangle(0, 0, bitmap.getWidth(), bitmap.getHeight()); this.texturePaint = new TexturePaint(AwtGraphicFactory.getBitmap(bitmap), rectangle); }
@SuppressWarnings("unused") @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void setBitmapShader(org.mapsforge.core.graphics.Bitmap bitmap) { if (bitmap == null) { return; } android.graphics.Bitmap androidBitmap = AndroidGraphicFactory.getBitmap(bitmap); if (androidBitmap == null) { return; } this.shaderWidth = bitmap.getWidth(); this.shaderHeight = bitmap.getHeight(); if (!AndroidGraphicFactory.KEEP_RESOURCE_BITMAPS && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // there is an problem when bitmaps are recycled too early on honeycomb and up, // where shaders are corrupted. This problem does of course not arise if // the bitmaps are cached for future use. // incrementing the refcount stops the recycling, but leaks the bitmap. bitmap.incrementRefCount(); } this.paint.setColor(AndroidGraphicFactory.getColor(Color.WHITE)); this.paint.setShader(new BitmapShader(androidBitmap, TileMode.REPEAT, TileMode.REPEAT)); }
public synchronized boolean contains(Point center, Point point) { // Touch min 20x20 px at baseline mdpi (160dpi) double width = Math.max(20 * this.displayModel.getScaleFactor(), this.bitmap.getWidth()); double height = Math.max(20 * this.displayModel.getScaleFactor(), this.bitmap.getHeight()); Rectangle r = new Rectangle( center.x - width / 2 + this.horizontalOffset, center.y - height / 2 + this.verticalOffset, center.x + width / 2 + this.horizontalOffset, center.y + height / 2 + this.verticalOffset); return r.contains(point); }
public SymbolContainer(Point point, Display display, int priority, Bitmap symbol, float theta, boolean alignCenter) { super(point, display, priority); this.symbol = symbol; this.theta = theta; this.alignCenter = alignCenter; if (alignCenter) { double halfWidth = this.symbol.getWidth() / 2d; double halfHeight = this.symbol.getHeight() / 2d; this.boundary = new Rectangle(-halfWidth, -halfHeight, halfWidth, halfHeight); } else { this.boundary = new Rectangle(0, 0, this.symbol.getWidth(), this.symbol.getHeight()); } this.symbol.incrementRefCount(); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(mapScaleBar.getMapScaleBitmap().getWidth(), mapScaleBar.getMapScaleBitmap().getHeight()); }
private Rectangle getBitmapRectangle(Point center) { Boolean isSelected = isSelected(); return new Rectangle( center.x - (float) cluster.getClusterManager().markerIconBmps.get(markerType) .getBitmap(isSelected).getWidth() + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().x, center.y - (float) cluster.getClusterManager().markerIconBmps.get(markerType) .getBitmap(isSelected).getHeight() + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().y, center.x + (float) cluster.getClusterManager().markerIconBmps.get(markerType) .getBitmap(isSelected).getWidth() + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().x, center.y + (float) cluster.getClusterManager().markerIconBmps.get(markerType) .getBitmap(isSelected).getHeight() + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().y); }
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.latLong == null || this.bitmap == null || this.bitmap.isDestroyed()) { return; } long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize()); double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, mapSize); double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, mapSize); 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); }
/** * Calculates the required length and value of the scalebar * * @param unitAdapter the DistanceUnitAdapter to calculate for * @return a {@link ScaleBarLengthAndValue} object containing the required scaleBarLength and scaleBarValue */ protected ScaleBarLengthAndValue calculateScaleBarLengthAndValue(DistanceUnitAdapter unitAdapter) { this.prevMapPosition = this.mapViewPosition.getMapPosition(); double groundResolution = MercatorProjection.calculateGroundResolution(this.prevMapPosition.latLong.latitude, MercatorProjection.getMapSize(this.prevMapPosition.zoomLevel, this.displayModel.getTileSize())); groundResolution = groundResolution / unitAdapter.getMeterRatio(); int[] scaleBarValues = unitAdapter.getScaleBarValues(); int scaleBarLength = 0; int mapScaleValue = 0; for (int scaleBarValue : scaleBarValues) { mapScaleValue = scaleBarValue; scaleBarLength = (int) (mapScaleValue / groundResolution); if (scaleBarLength < (this.mapScaleBitmap.getWidth() - 10)) { break; } } return new ScaleBarLengthAndValue(scaleBarLength, mapScaleValue); }
/** * Called from {@link MapView} * * @param graphicContext The graphicContext to use to draw the MapScaleBar */ public void draw(GraphicContext graphicContext) { if (!this.visible) { return; } if (this.mapViewDimension.getDimension() == null) { return; } if (this.isRedrawNecessary()) { redraw(this.mapScaleCanvas); this.redrawNeeded = false; } int positionLeft = calculatePositionLeft(0, this.mapViewDimension.getDimension().width, this.mapScaleBitmap.getWidth()); int positionTop = calculatePositionTop(0, this.mapViewDimension.getDimension().height, this.mapScaleBitmap.getHeight()); graphicContext.drawBitmap(this.mapScaleBitmap, positionLeft, positionTop); }
@Override public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { if (this.getLatLong() == null || this.getBitmap() == null || this.getBitmap().isDestroyed()) { return; } long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize()); double pixelX = MercatorProjection.longitudeToPixelX(this.getLatLong().longitude, mapSize); double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize); int halfBitmapWidth = this.getBitmap().getWidth() / 2; int halfBitmapHeight = this.getBitmap().getHeight() / 2; int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.getHorizontalOffset()); int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.getVerticalOffset()); int right = left + this.getBitmap().getWidth(); int bottom = top + this.getBitmap().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.getBitmap(), left, top); if (this.paintText != null) { String text = String.valueOf(this.children.size()); canvas.drawText(text, left + halfBitmapWidth - 5, top + halfBitmapHeight + 5, this.paintText); } }