Skip to content

Commit 34f9d4d

Browse files
committed
Merge pull request #1144 from garvankeeley/1129-1087-follow-mode-hashing
1129 / 1087: in follow mode, dots not drawn
2 parents 192aed1 + 7a20438 commit 34f9d4d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

Diff for: android/src/main/java/org/mozilla/mozstumbler/client/mapview/MapFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void run() {
201201
mAccuracyOverlay = new AccuracyCircleOverlay(mRootView.getContext(), sGPSColor);
202202
mMap.getOverlays().add(mAccuracyOverlay);
203203

204-
mObservationPointsOverlay = new ObservationPointsOverlay(mRootView.getContext(), mMap);
204+
mObservationPointsOverlay = new ObservationPointsOverlay(mRootView.getContext());
205205
mMap.getOverlays().add(mObservationPointsOverlay);
206206

207207
ObservedLocationsReceiver observer = ObservedLocationsReceiver.getInstance();

Diff for: android/src/main/java/org/mozilla/mozstumbler/client/mapview/ObservationPointsOverlay.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class ObservationPointsOverlay extends Overlay {
4747
private final int mSize3px;
4848

4949
LinkedHashMap<Integer, ObservationPoint> mHashedGrid;
50+
private Point mHashedGridAnchorPoint = new Point(0,0);
5051

51-
ObservationPointsOverlay(Context ctx, MapView mapView) {
52+
ObservationPointsOverlay(Context ctx) {
5253
super(ctx);
5354
mConvertPx = new DevicePixelConverter(ctx);
5455

@@ -91,7 +92,7 @@ void update(ObservationPoint obsPoint, MapView mapView, boolean isMlsPointUpdate
9192

9293
if (!isMlsPointUpdate) {
9394
// add to hashed grid
94-
addToGridHash(obsPoint, point);
95+
addToGridHash(obsPoint, point, new Point(mapView.getScrollX(), mapView.getScrollY()));
9596
}
9697

9798
mapView.postInvalidate();
@@ -113,8 +114,8 @@ private void drawWifiScan(Canvas c, Point p) {
113114
c.drawCircle(p.x, p.y, size, mWifiPaint);
114115
}
115116

116-
private void addToGridHash(ObservationPoint obsPoint, Point screenPoint) {
117-
int hash = toGridPoint(screenPoint.x, screenPoint.y);
117+
private void addToGridHash(ObservationPoint obsPoint, Point screenPoint, Point currentScroll) {
118+
int hash = hashedGridPoint(screenPoint.x, screenPoint.y, currentScroll.x, currentScroll.y);
118119
ObservationPoint gp = mHashedGrid.get(hash);
119120
if (gp == null || toTypeBitField(obsPoint) > toTypeBitField(gp)) {
120121
mHashedGrid.put(hash, obsPoint);
@@ -123,21 +124,23 @@ private void addToGridHash(ObservationPoint obsPoint, Point screenPoint) {
123124

124125
public void zoomChanged(MapView mapView) {
125126
mHashedGrid = new LinkedHashMap<Integer, ObservationPoint>();
127+
mHashedGridAnchorPoint = new Point(mapView.getScrollX(), mapView.getScrollY());
126128
final Projection pj = mapView.getProjection();
127129
LinkedList<ObservationPoint> points = ObservedLocationsReceiver.getInstance().getObservationPoints();
128130
final Iterator<ObservationPoint> i = points.iterator();
129131
final Point gps = new Point();
130132
ObservationPoint point;
133+
Point zero = new Point(0, 0);
131134
while (i.hasNext()) {
132135
point = i.next();
133136
pj.toPixels(point.pointGPS, gps);
134-
addToGridHash(point, gps);
137+
addToGridHash(point, gps, zero);
135138
}
136139
}
137140

138-
private int toGridPoint(int x, int y) {
139-
x = (int) Math.round(x / (mSize3px * 2.0));
140-
y = (int) Math.round(y / (mSize3px * 2.0));
141+
private int hashedGridPoint(int x, int y, int scrollX, int scrollY) {
142+
x = (int) Math.round((x - mHashedGridAnchorPoint.x + scrollX) / (mSize3px * 2.0));
143+
y = (int) Math.round((y - mHashedGridAnchorPoint.y + scrollY) / (mSize3px * 2.0));
141144
return x * 10000 + y;
142145
}
143146

0 commit comments

Comments
 (0)