@Test public void setterTest() { LatLong latLong = new LatLong(0, 0); Bitmap bitmap = GRAPHIC_FACTORY.createBitmap(10, 20); Marker marker = new Marker(null, null, 0, 0); Assert.assertNull(marker.getLatLong()); Assert.assertNull(marker.getBitmap()); Assert.assertEquals(0, marker.getHorizontalOffset()); Assert.assertEquals(0, marker.getVerticalOffset()); marker.setLatLong(latLong); Assert.assertEquals(latLong, marker.getLatLong()); marker.setBitmap(bitmap); Assert.assertEquals(bitmap, marker.getBitmap()); marker.setHorizontalOffset(-1); Assert.assertEquals(-1, marker.getHorizontalOffset()); marker.setVerticalOffset(-2); Assert.assertEquals(-2, marker.getVerticalOffset()); } }
@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); } }
@Test public void constructorTest() { LatLong latLong = new LatLong(0, 0); Bitmap bitmap = GRAPHIC_FACTORY.createBitmap(10, 20); Marker marker = new Marker(latLong, bitmap, 1, 2); Assert.assertEquals(latLong, marker.getLatLong()); Assert.assertEquals(bitmap, marker.getBitmap()); Assert.assertEquals(1, marker.getHorizontalOffset()); Assert.assertEquals(2, marker.getVerticalOffset()); }
@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 run() { if (current != null) { // since we want to keep the green bitmap around, we have to increment // its ref count, otherwise it gets recycled automatically when it is // replaced with the other colour. current.incrementRefCount(); } if (bitmapGreen.equals(current)) { marker.setBitmap(bitmapRed); current = bitmapRed; } else { marker.setBitmap(bitmapGreen); current = bitmapGreen; } redrawLayers(); handler.postDelayed(this, 2000); } }
public void mouseDragged(MouseEvent e) { if (isLeftMouseButton(e)) { if (isMousePressedOnMarker()) { startDragCursor(mapView); LatLong latLong = projection.fromPixels(e.getX(), e.getY()); mousePressMarker.setLatLong(latLong); mousePressMarker.requestRedraw(); } else if (getLastMousePoint() != null) { Point point = e.getPoint(); int moveHorizontal = point.x - lastMousePressPoint.x; int moveVertical = point.y - lastMousePressPoint.y; mapView.getModel().mapViewPosition.moveCenter(moveHorizontal, moveVertical); lastMousePressPoint = point; } } }
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); }
private Marker createMarker(PositionWithLayer positionWithLayer) { return new Marker(asLatLong(positionWithLayer.getPosition()), waypointIcon, 1, 0); }
@Override public final void onHeatmapCompleted(final Bitmap backbuffer) { // zoom level has changed in the mean time - regenerate if (mMapView.getModel().mapViewPosition.getZoomLevel() != zoomAtTrigger) { updatePending = false; Log.i(TAG, "Zoom level has changed - have to re-generate heat-map"); clearLayer(); proceedAfterHeatmapCompleted(); return; } final BitmapDrawable drawable = new BitmapDrawable(backbuffer); final org.mapsforge.core.graphics.Bitmap mfBitmap = AndroidGraphicFactory.convertToBitmap(drawable); if (heatmapLayer != null && mfBitmap != null) { heatmapLayer.setBitmap(mfBitmap); } else { Log.w(TAG, "Skipped heatmap draw: either layer or bitmap is null"); } updatePending = false; //saveHeatmapToFile(backbuffer); }
@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); }
@Override public final void onHeatmapCompleted(final Bitmap backbuffer) { // zoom level has changed in the mean time - regenerate if (mMapView.getModel().mapViewPosition.getZoomLevel() != mZoomAtTrigger) { mUpdatePending = false; Log.i(TAG, "Zoom level has changed - have to re-generate heat-map"); clearLayer(); proceedAfterHeatmapCompleted(); return; } final BitmapDrawable drawable = new BitmapDrawable(backbuffer); final org.mapsforge.core.graphics.Bitmap mfBitmap = AndroidGraphicFactory.convertToBitmap(drawable); if (mHeatmapLayer != null && mfBitmap != null) { mHeatmapLayer.setBitmap(mfBitmap); } else { Log.w(TAG, "Skipped heatmap draw: either layer or bitmap is null"); } mUpdatePending = false; //saveHeatmapToFile(backbuffer); } /**
@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)); } }
@UiThread void showCarPosition(Cars cars) { if (TaxiApplication.isMapVisible() && cars != null) { //final List<Layer> overlayItems = carsOverlay.getOverlayItems(); //overlayItems.clear(); TextView bubbleView = new TextView(this); Utils.setBackground(bubbleView, getResources().getDrawable(R.drawable.balloon_overlay_unfocused)); bubbleView.setGravity(Gravity.CENTER); bubbleView.setMaxEms(20); bubbleView.setTextSize(15); bubbleView.setTextColor(Color.BLACK); bubbleView.setText(cars.getNumber()); bubble = Utils.viewToBitmap(this, bubbleView); bubble.incrementRefCount(); if (cars.getCurrPosNorth() != null && cars.getCurrPosEast() != null) { Marker marker = new Marker(new LatLong(cars.getCurrPosNorth(), cars.getCurrPosEast()), bubble, 0, -bubble.getHeight() / 2); //marker.setDisplayModel(this.mapViews.get(0).getModel().displayModel); carsOverlay.add(marker); mapView.getLayerManager().getLayers().add(marker); //Log.i(TAG, "Car:" + cars.getNumber()); } //carsOverlay.requestRedraw(); } }
@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); }
bubble = Utils.viewToBitmap(this, bubbleView); bubble.incrementRefCount(); Marker marker = new Marker(new LatLong(newCRequest.getNorth(), newCRequest.getEast()), bubble, 0, -bubble.getHeight() / 2);
/** * */ private void proceedAfterHeatmapCompleted() { if (pointsLoaded && layoutInflated && !updatePending) { updatePending = true; clearLayer(); final BoundingBox bbox = MapPositionUtil.getBoundingBox( mMapView.getModel().mapViewPosition.getMapPosition(), mMapView.getDimension(), mMapView.getModel().displayModel.getTileSize()); target = mMapView.getModel().mapViewPosition.getCenter(); zoomAtTrigger = mMapView.getModel().mapViewPosition.getZoomLevel(); heatmapLayer = new Marker(target, null, 0, 0); mMapView.getLayerManager().getLayers().add(heatmapLayer); builder = new HeatmapBuilder( WifiDetailsMap.this, mMapView.getWidth(), mMapView.getHeight(), bbox, mMapView.getModel().mapViewPosition.getZoomLevel(), mMapView.getModel().displayModel.getScaleFactor(), mMapView.getModel().displayModel.getTileSize(), RADIUS).execute(points); } else { Log.i(TAG, "Another heat-map is currently generated. Skipped"); } }
/** * */ private void proceedAfterHeatmapCompleted() { if (mPointsLoaded && mLayoutInflated && !mUpdatePending) { mUpdatePending = true; clearLayer(); final BoundingBox bbox = MapPositionUtil.getBoundingBox( mMapView.getModel().mapViewPosition.getMapPosition(), mMapView.getDimension(), mMapView.getModel().displayModel.getTileSize()); mTarget = mMapView.getModel().mapViewPosition.getCenter(); mZoomAtTrigger = mMapView.getModel().mapViewPosition.getZoomLevel(); mHeatmapLayer = new Marker(mTarget, null, 0, 0); mMapView.getLayerManager().getLayers().add(mHeatmapLayer); new HeatmapBuilder( CellDetailsMap.this, mMapView.getWidth(), mMapView.getHeight(), bbox, mMapView.getModel().mapViewPosition.getZoomLevel(), mMapView.getModel().displayModel.getScaleFactor(), mMapView.getModel().displayModel.getTileSize(), RADIUS).execute(points); } else { Log.i(TAG, "Another heat-map is currently generated. Skipped"); } }