-
Notifications
You must be signed in to change notification settings - Fork 982
/
SampleRotation.java
83 lines (70 loc) · 2.76 KB
/
SampleRotation.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
package org.osmdroid.samplefragments.location;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import org.osmdroid.R;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
/**
* created on 1/2/2017.
*
* @author Alex O'Ree
*/
public class SampleRotation extends BaseSampleFragment implements View.OnClickListener {
ImageButton btnRotateLeft, btnRotateRight;
protected TextView textViewCurrentLocation = null;
@Override
public String getSampleTitle() {
return "Map Rotation";
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.map_with_locationbox_controls, null);
mMapView = root.findViewById(R.id.mapview);
btnRotateLeft = root.findViewById(R.id.btnRotateLeft);
btnRotateLeft.setOnClickListener(this);
btnRotateRight = root.findViewById(R.id.btnRotateRight);
btnRotateRight.setOnClickListener(this);
textViewCurrentLocation = root.findViewById(R.id.textViewCurrentLocation);
textViewCurrentLocation.setText("0.0");
return root;
}
@Override
public void addOverlays() {
super.addOverlays();
final DisplayMetrics dm = getActivity().getResources().getDisplayMetrics();
RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(true);
mMapView.getOverlays().add(mRotationGestureOverlay);
ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(mMapView);
mScaleBarOverlay.setScaleBarOffset(0, (int) (40 * dm.density));
mScaleBarOverlay.setCentred(true);
mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
mMapView.getOverlays().add(mScaleBarOverlay);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnRotateLeft: {
float angle = mMapView.getMapOrientation() + 10;
if (angle > 360)
angle = 360 - angle;
mMapView.setMapOrientation(angle);
}
break;
case R.id.btnRotateRight: {
float angle = mMapView.getMapOrientation() - 10;
if (angle < 0)
angle += 360f;
mMapView.setMapOrientation(angle);
}
break;
}
textViewCurrentLocation.setText(mMapView.getMapOrientation() + "");
}
}