private float computeVerticalOffset(byte zoomLevel) { float verticalOffset = this.dyScaled.get(zoomLevel); if (Position.ABOVE == this.position || Position.ABOVE_LEFT == this.position || Position.ABOVE_RIGHT == this.position) { verticalOffset -= this.bitmap.getHeight() / 2f + this.gap; } else if (Position.BELOW == this.position || Position.BELOW_LEFT == this.position || Position.BELOW_RIGHT == this.position) { verticalOffset += this.bitmap.getHeight() / 2f + this.gap; } return 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); }
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); }
/** * 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 computeVerticalOffset(byte zoomLevel) { float verticalOffset = this.dyScaled.get(zoomLevel); if (Position.ABOVE == this.position || Position.ABOVE_LEFT == this.position || Position.ABOVE_RIGHT == this.position) { verticalOffset -= this.bitmap.getHeight() / 2f + this.gap; } else if (Position.BELOW == this.position || Position.BELOW_LEFT == this.position || Position.BELOW_RIGHT == this.position) { verticalOffset += this.bitmap.getHeight() / 2f + this.gap; } return verticalOffset; }
/** * 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; }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) static Marker createMarker(Context c, int resourceIdentifier, LatLong latLong) { Drawable drawable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? c.getDrawable(resourceIdentifier) : c.getResources().getDrawable(resourceIdentifier); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable); return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2); }
@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); }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onCreate(Bundle sis) { Drawable drawableWhite = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDrawable(R.drawable.marker_white) : getResources().getDrawable(R.drawable.marker_white); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColorFilter(new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY)); bitmapGreen = AndroidGraphicFactory.convertToBitmap(drawableWhite, paint); paint.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY)); bitmapRed = AndroidGraphicFactory.convertToBitmap(drawableWhite, paint); marker = new Marker(latLong, bitmapGreen, 0, -bitmapGreen.getHeight() / 2); super.onCreate(sis); }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) static Marker createTappableMarker(final Context c, int resourceIdentifier, LatLong latLong) { Drawable drawable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? c.getDrawable(resourceIdentifier) : c.getResources().getDrawable(resourceIdentifier); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable); bitmap.incrementRefCount(); return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2) { @Override public boolean onTap(LatLong geoPoint, Point viewPosition, Point tapPoint) { if (contains(viewPosition, tapPoint)) { Toast.makeText(c, "The Marker was tapped " + geoPoint.toString(), Toast.LENGTH_SHORT).show(); return true; } return false; } }; }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override protected void createLayers() { super.createLayers(); // Bubble overlays for (DummyContent.DummyItem item : DummyContent.ITEMS) { TextView bubbleView = new TextView(this); Utils.setBackground(bubbleView, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDrawable(R.drawable.balloon_overlay_unfocused) : getResources().getDrawable(R.drawable.balloon_overlay_unfocused)); bubbleView.setGravity(Gravity.CENTER); bubbleView.setMaxEms(20); bubbleView.setTextSize(15); bubbleView.setTextColor(Color.BLACK); bubbleView.setText(item.text); bubble = Utils.viewToBitmap(this, bubbleView); bubble.incrementRefCount(); this.mapView.getLayerManager().getLayers().add(new Marker(item.location, bubble, 0, -bubble.getHeight() / 2)); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(mapScaleBar.getMapScaleBitmap().getWidth(), mapScaleBar.getMapScaleBitmap().getHeight()); }
@SuppressWarnings("deprecation") private void addGroupMarker() { LatLong latLong = new LatLong(52.525582, 13.370061); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(getResources().getDrawable(R.drawable.marker_green)); GroupMarker groupMarker = new GroupMarker(latLong, bitmap, 0, -bitmap.getHeight() / 2, mapView.getLayerManager().getLayers(), BLACK); for (int i = 0; i < 10.; i++) { groupMarker.getChildren().add(new ChildMarker(latLong, bitmap, 0, 0, BLACK)); } mapView.addLayer(groupMarker); } }
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); }
/** * 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); }