Permalink
Browse files

feature/#990 - step 1 - Overlay.draw(Canvas, Projection)

Created method `Overlay.draw(Canvas, Projection)`, to be used and overridden rather than the now deprecated method `draw(Canvas, MapView, boolean)`.

Impacted interface:
* `OverlayManager`: created method `onDraw(Canvas, Projection)`, to be used and overridden rather than the now deprecated method `onDraw(Canvas, MapView)`

Impacted classes:
* `Overlay`: created method `draw(Canvas, Projection)`, to be used and overridden rather than the now deprecated method `draw(Canvas, MapView, boolean)`; gently refactored
* `Projection`: added getters `isHorizontalWrapEnabled`, `isVerticalWrapEnabled` and `getOrientation`

* `CirclePlottingOverlay`: removed useless overridden code of `draw(Canvas, MapView, boolean)` as there's no display
* `IconPlottingOverlay`: removed useless overridden code of `draw(Canvas, MapView, boolean)` as there's no display
* `MapEventsOverlay`: removed useless overridden code of `draw(Canvas, MapView, boolean)` as there's no display
* `MilStdPointPlottingOverlay`: removed useless overridden code of `draw(Canvas, MapView, boolean)` as there's no display
* `RotationGestureOverlay`: removed useless overridden code of `draw(Canvas, MapView, boolean)` as there's no display

* `Bug82WinDeath`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `CompassOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `CopyrightOverlay`: added field `mCopyrightNotice` and its setter; moved most of the code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `DirectedLocationOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `FolderOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `GroundOverlay2`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `IconOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `ItemizedOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`; replaced parameter `MapView` with `Projection` in method `onDrawItem(Canvas, Item, Point, MapView)`
* `ItemizedOverlayWithFocus`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `Marker`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `MinimapOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`; replaced method `setViewPort(Canvas, MapView)` with `setViewPort(Canvas, Projection)`
* `MyLocationNewOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`; replaced method `drawMyLocation(Canvas, MapView, Location)` with `drawMyLocation(Canvas, Projection, Location)`
* `PathOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `Polygon`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `Polyline`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `SampleTileStates`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `ScaleBarOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `SimpleLocationOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`
* `TilesOverlay`: moved code from `draw(Canvas, MapView, boolean)` to `draw(Canvas, Projection)`; replaced method `protectDisplayedTilesForCache(Canvas, MapView)` with `protectDisplayedTilesForCache(Canvas, Projection)`; replaced method `setViewPort(Canvas, MapView)` with `setViewPort(Canvas, Projection)`; `OverlayTileLooper`; unrelated little optimization in method `onTileReadyToDraw`

* `DefaultOverlayManager`: moved code from `onDraw(Canvas, MapView)` to new method `onDraw(Canvas, Projection)`
* `LinearRing`: remplace method `setClipArea(MapView)` with `setClipArea(Projection)`
  • Loading branch information...
monsieurtanuki committed Jan 5, 2019
1 parent 4f243f8 commit ac3463ab27f979561c97081bf70caade44d416ae
Showing with 174 additions and 218 deletions.
  1. +5 −9 OpenStreetMapViewer/src/main/java/org/osmdroid/bugtestfragments/Bug82WinDeath.java
  2. +0 −6 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/drawing/CirclePlottingOverlay.java
  3. +0 −6 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/drawing/IconPlottingOverlay.java
  4. +0 −6 ...etMapViewer/src/main/java/org/osmdroid/samplefragments/milstd2525/MilStdPointPlottingOverlay.java
  5. +2 −2 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/tileproviders/SampleTileStates.java
  6. +21 −0 osmdroid-android/src/main/java/org/osmdroid/views/Projection.java
  7. +21 −7 osmdroid-android/src/main/java/org/osmdroid/views/overlay/CopyrightOverlay.java
  8. +14 −5 osmdroid-android/src/main/java/org/osmdroid/views/overlay/DefaultOverlayManager.java
  9. +3 −4 osmdroid-android/src/main/java/org/osmdroid/views/overlay/FolderOverlay.java
  10. +2 −5 osmdroid-android/src/main/java/org/osmdroid/views/overlay/GroundOverlay2.java
  11. +2 −6 osmdroid-android/src/main/java/org/osmdroid/views/overlay/IconOverlay.java
  12. +18 −33 osmdroid-android/src/main/java/org/osmdroid/views/overlay/ItemizedOverlay.java
  13. +7 −10 osmdroid-android/src/main/java/org/osmdroid/views/overlay/ItemizedOverlayWithFocus.java
  14. +6 −5 osmdroid-android/src/main/java/org/osmdroid/views/overlay/LinearRing.java
  15. +0 −5 osmdroid-android/src/main/java/org/osmdroid/views/overlay/MapEventsOverlay.java
  16. +2 −6 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Marker.java
  17. +7 −14 osmdroid-android/src/main/java/org/osmdroid/views/overlay/MinimapOverlay.java
  18. +16 −2 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Overlay.java
  19. +10 −0 osmdroid-android/src/main/java/org/osmdroid/views/overlay/OverlayManager.java
  20. +1 −9 osmdroid-android/src/main/java/org/osmdroid/views/overlay/PathOverlay.java
  21. +3 −8 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Polygon.java
  22. +2 −8 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Polyline.java
  23. +5 −13 osmdroid-android/src/main/java/org/osmdroid/views/overlay/ScaleBarOverlay.java
  24. +17 −18 osmdroid-android/src/main/java/org/osmdroid/views/overlay/TilesOverlay.java
  25. +2 −6 osmdroid-android/src/main/java/org/osmdroid/views/overlay/compass/CompassOverlay.java
  26. +0 −6 osmdroid-android/src/main/java/org/osmdroid/views/overlay/gestures/RotationGestureOverlay.java
  27. +1 −7 osmdroid-android/src/main/java/org/osmdroid/views/overlay/mylocation/DirectedLocationOverlay.java
  28. +5 −9 osmdroid-android/src/main/java/org/osmdroid/views/overlay/mylocation/MyLocationNewOverlay.java
  29. +2 −3 osmdroid-android/src/main/java/org/osmdroid/views/overlay/mylocation/SimpleLocationOverlay.java
@@ -8,7 +8,7 @@

import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.Overlay;

/**
@@ -47,14 +47,10 @@ public MapOverlay() {
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if (!shadow) {
// && mapView.getZoomLevel() > 5
Log.i(TAG, "Drawing Bug82 Windeath circle");
Point point = mapView.getProjection().toPixels(new GeoPoint(50.71838, -103.42443), new Point());
canvas.drawCircle(point.x, point.y, 100.0f, innerPaint);
}

public void draw(Canvas canvas, Projection pProjection) {
Log.i(TAG, "Drawing Bug82 Windeath circle");
Point point = pProjection.toPixels(new GeoPoint(50.71838, -103.42443), new Point());
canvas.drawCircle(point.x, point.y, 100.0f, innerPaint);
}
}
}
@@ -1,6 +1,5 @@
package org.osmdroid.samplefragments.drawing;

import android.graphics.Canvas;
import android.util.Log;
import android.view.MotionEvent;

@@ -28,11 +27,6 @@ public CirclePlottingOverlay(float distanceKm) {
this.distanceKm = distanceKm;
}

@Override
public void draw(Canvas c, MapView osmv, boolean shadow) {

}

@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {

@@ -1,6 +1,5 @@
package org.osmdroid.samplefragments.drawing;

import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;

@@ -29,11 +28,6 @@ public IconPlottingOverlay(Drawable m) {

}

@Override
public void draw(Canvas c, MapView osmv, boolean shadow) {

}

@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
if (markerIcon != null) {
@@ -1,6 +1,5 @@
package org.osmdroid.samplefragments.milstd2525;

import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.util.SparseArray;
import android.view.MotionEvent;
@@ -37,11 +36,6 @@ public void setSymbol(SimpleSymbol def) {
this.def = def;
}

@Override
public void draw(Canvas c, MapView osmv, boolean shadow) {

}

@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
if (def != null) {
@@ -12,7 +12,7 @@
import org.osmdroid.R;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.tileprovider.TileStates;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.Overlay;

/**
@@ -50,7 +50,7 @@ protected void addOverlays() {
final Bitmap ko = ((BitmapDrawable)getResources().getDrawable(R.drawable.twotone_warning_black_36)).getBitmap();
mMapView.getOverlayManager().add(new Overlay() {
@Override
public void draw(Canvas c, MapView osmv, boolean shadow) {
public void draw(Canvas c, Projection projection) {
final Bitmap bitmap = mOk ? ok : ko;
c.drawBitmap(bitmap, c.getWidth() / 2 - bitmap.getWidth() / 2, c.getHeight() / 2 - bitmap.getHeight() / 2, null);
}
@@ -780,4 +780,25 @@ boolean setMapScroll(final MapView pMapView) {
pMapView.setMapScroll(mScrollX, mScrollY);
return true;
}

/**
* @since 6.1.0
*/
public boolean isHorizontalWrapEnabled() {
return horizontalWrapEnabled;
}

/**
* @since 6.1.0
*/
public boolean isVerticalWrapEnabled() {
return verticalWrapEnabled;
}

/**
* @since 6.1.0
*/
public float getOrientation() {
return mOrientation;
}
}
@@ -32,6 +32,7 @@

import org.osmdroid.tileprovider.tilesource.ITileSource;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;


/**
@@ -55,6 +56,7 @@
protected boolean alignBottom = true;
protected boolean alignRight = false;
final DisplayMetrics dm;
private String mCopyrightNotice;
// Constructor

public CopyrightOverlay(Context context) {
@@ -104,11 +106,16 @@ public void setOffset(final int x, final int y) {

@Override
public void draw(Canvas canvas, MapView map, boolean shadow) {
if (shadow) return;

setCopyrightNotice(map.getTileProvider().getTileSource().getCopyrightNotice());
draw(canvas, map.getProjection());
}

if (map.getTileProvider().getTileSource().getCopyrightNotice() == null ||
map.getTileProvider().getTileSource().getCopyrightNotice().length() == 0)
/**
* @since 6.1.0
*/
@Override
public void draw(final Canvas canvas, final Projection pProjection) {
if (mCopyrightNotice == null || mCopyrightNotice.length() == 0)
return;

int width = canvas.getWidth();
@@ -131,8 +138,15 @@ public void draw(Canvas canvas, MapView map, boolean shadow) {
y = paint.getTextSize() + yOffset;

// Draw the text
map.getProjection().save(canvas, false, false);
canvas.drawText(map.getTileProvider().getTileSource().getCopyrightNotice(), x, y, paint);
map.getProjection().restore(canvas, false);
pProjection.save(canvas, false, false);
canvas.drawText(mCopyrightNotice, x, y, paint);
pProjection.restore(canvas, false);
}

/**
* @since 6.1.0
*/
public void setCopyrightNotice(final String pCopyrightNotice) {
mCopyrightNotice = pCopyrightNotice;
}
}
@@ -8,6 +8,7 @@

import org.osmdroid.api.IMapView;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.Overlay.Snappable;

import android.graphics.Canvas;
@@ -31,7 +32,7 @@

public DefaultOverlayManager(final TilesOverlay tilesOverlay) {
setTilesOverlay(tilesOverlay);
mOverlayList = new CopyOnWriteArrayList<Overlay>();
mOverlayList = new CopyOnWriteArrayList<>();
}

@Override
@@ -119,25 +120,33 @@ public void remove() {

@Override
public void onDraw(final Canvas c, final MapView pMapView) {
onDraw(c, pMapView.getProjection());
}

/**
* @since 6.1.0
*/
@Override
public void onDraw(final Canvas c, final Projection pProjection) {
//fix for https://github.com/osmdroid/osmdroid/issues/904
if (mTilesOverlay!=null)
mTilesOverlay.protectDisplayedTilesForCache(c, pMapView);
mTilesOverlay.protectDisplayedTilesForCache(c, pProjection);
for (final Overlay overlay : mOverlayList) {
if (overlay!=null && overlay.isEnabled() && overlay instanceof TilesOverlay) {
((TilesOverlay) overlay).protectDisplayedTilesForCache(c, pMapView);
((TilesOverlay) overlay).protectDisplayedTilesForCache(c, pProjection);
}
}

//always pass false, the shadow parameter will be removed in a later version of osmdroid, this change should result in the on draw being called twice
if (mTilesOverlay != null && mTilesOverlay.isEnabled()) {
mTilesOverlay.draw(c, pMapView, false);
mTilesOverlay.draw(c, pProjection);
}

//always pass false, the shadow parameter will be removed in a later version of osmdroid, this change should result in the on draw being called twice
for (final Overlay overlay : mOverlayList) {
//#396 fix, null check
if (overlay!=null && overlay.isEnabled()) {
overlay.draw(c, pMapView, false);
overlay.draw(c, pProjection);
}
}
//potential fix for #52 pMapView.invalidate();
@@ -3,6 +3,7 @@
import java.util.List;

import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;

import android.annotation.SuppressLint;
import android.content.Context;
@@ -67,10 +68,8 @@ public boolean remove(Overlay item){
}

@SuppressLint("WrongCall")
@Override public void draw(Canvas canvas, MapView osm, boolean shadow) {
if (shadow)
return;
mOverlayManager.onDraw(canvas, osm);
@Override public void draw(final Canvas pCanvas, final Projection pProjection) {
mOverlayManager.onDraw(pCanvas, pProjection);
}

@Override public boolean onSingleTapUp(MotionEvent e, MapView mapView){
@@ -6,7 +6,6 @@
import android.graphics.Paint;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;

/**
@@ -73,14 +72,12 @@ public float getTransparency(){


@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
public void draw(Canvas canvas, Projection pj)
{
if(null == mImage || shadow) {
if(null == mImage) {
return;
}

final Projection pj = mapView.getProjection();

long x0 = pj.getLongPixelXFromLongitude(mLonL),
y0 = pj.getLongPixelYFromLatitude(mLatU),
x1 = pj.getLongPixelXFromLongitude(mLonR),
@@ -47,16 +47,12 @@ public IconOverlay(IGeoPoint position, Drawable icon) {
* Draw the icon.
*/
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if (shadow)
return;
public void draw(Canvas canvas, Projection pj) {
if (mIcon == null)
return;
if (mPosition == null)
return;

final Projection pj = mapView.getProjection();

pj.toPixels(mPosition, mPositionPixels);
int width = mIcon.getIntrinsicWidth();
int height = mIcon.getIntrinsicHeight();
@@ -66,7 +62,7 @@ public void draw(Canvas canvas, MapView mapView, boolean shadow) {

mIcon.setAlpha((int) (mAlpha * 255));

float rotationOnScreen = (mFlat ? -mBearing : mapView.getMapOrientation()-mBearing);
float rotationOnScreen = (mFlat ? -mBearing : pj.getOrientation()-mBearing);
drawAt(canvas, mIcon, mPositionPixels.x, mPositionPixels.y, false, rotationOnScreen);
}

Oops, something went wrong.

0 comments on commit ac3463a

Please sign in to comment.