-
Notifications
You must be signed in to change notification settings - Fork 982
/
Bug164EndlessOnScolls.java
90 lines (75 loc) · 2.75 KB
/
Bug164EndlessOnScolls.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package org.osmdroid.bugtestfragments;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.osmdroid.R;
import org.osmdroid.api.IGeoPoint;
import org.osmdroid.events.MapListener;
import org.osmdroid.events.ScrollEvent;
import org.osmdroid.events.ZoomEvent;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.util.GeoPoint;
import static org.osmdroid.samplefragments.events.SampleMapEventListener.df;
/**
* <a href="https://github.com/osmdroid/osmdroid/issues/164">https://github.com/osmdroid/osmdroid/issues/164</a>
* Created by alex on 8/28/16.
*/
public class Bug164EndlessOnScolls extends BaseSampleFragment implements View.OnClickListener {
@Override
public String getSampleTitle() {
return "Bug #164 Endless onScroll callsScoll";
}
TextView textViewCurrentLocation;
Button animateTo;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.map_with_locationbox164, container, false);
mMapView = root.findViewById(R.id.mapview);
textViewCurrentLocation = root.findViewById(R.id.textViewCurrentLocation);
animateTo = root.findViewById(R.id.animateTo);
animateTo.setOnClickListener(this);
Log.d(TAG, "onCreateView");
return root;
}
int callsScoll = 0;
int callsZoom = 0;
protected void addOverlays() {
super.addOverlays();
//
mMapView.setMapListener(new MapListener() {
@Override
public boolean onScroll(ScrollEvent event) {
Log.i(TAG, "onScroll called");
callsScoll++;
updateInfo();
return true;
}
@Override
public boolean onZoom(ZoomEvent event) {
Log.i(TAG, "onZoom called");
callsZoom++;
updateInfo();
return true;
}
});
}
private void updateInfo() {
IGeoPoint mapCenter = mMapView.getMapCenter();
textViewCurrentLocation.setText(df.format(mapCenter.getLatitude()) + "," +
df.format(mapCenter.getLongitude())
+ "," + mMapView.getZoomLevelDouble() + "\nonScroll: " + callsScoll + " onZoom: "
+ callsZoom);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.animateTo) {
double lat = Math.random() * 180d - 90;
double lon = Math.random() * 360 - 180;
mMapView.getController().animateTo(new GeoPoint(lat, lon));
}
}
}