-
Notifications
You must be signed in to change notification settings - Fork 982
/
ZoomToBoundsOnStartup.java
140 lines (119 loc) · 3.57 KB
/
ZoomToBoundsOnStartup.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package org.osmdroid.samplefragments.events;
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.api.IMapView;
import org.osmdroid.events.MapListener;
import org.osmdroid.events.ScrollEvent;
import org.osmdroid.events.ZoomEvent;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.util.BoundingBox;
import org.osmdroid.views.MapView;
import static org.osmdroid.samplefragments.events.SampleMapEventListener.df;
/**
* Created by Dad on 10/28/2016.
*/
public class ZoomToBoundsOnStartup extends BaseSampleFragment implements View.OnClickListener {
TextView textViewCurrentLocation;
Button animateTo;
@Override
public String getSampleTitle() {
return "Zoom to bounds on Start";
}
@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);
mMapView.getController().setZoom(7);
animateTo = root.findViewById(R.id.animateTo);
animateTo.setOnClickListener(this);
textViewCurrentLocation = root.findViewById(R.id.textViewCurrentLocation);
attach();
return root;
/*
values from onFirstLayout
18=13
17=13
16=13
15=13
14=13
13=13
12=13
11=13
10=13
7=13
6=13
5=13
4=13
3=14
2=15
1=10
0=10
on a button click
18=13,18
17=13
16=13
15=13
14=13
13=13
12=13
11=13
10=13
7=13
6=13
5=13
4=13
3=14,15
2=15,15
1=10,15
0=10,15
*/
}
private void attach() {
mMapView.addOnFirstLayoutListener(new MapView.OnFirstLayoutListener() {
@Override
public void onFirstLayout(View v, int left, int top, int right, int bottom) {
}
});
}
@Override
protected void addOverlays() {
super.addOverlays();
mMapView.setMapListener(new MapListener() {
@Override
public boolean onScroll(ScrollEvent event) {
Log.i(IMapView.LOGTAG, System.currentTimeMillis() + " onScroll " + event.getX() + "," + event.getY());
updateInfo();
return true;
}
@Override
public boolean onZoom(ZoomEvent event) {
Log.i(IMapView.LOGTAG, System.currentTimeMillis() + " onZoom " + event.getZoomLevel());
updateInfo();
return true;
}
});
}
private void updateInfo() {
IGeoPoint mapCenter = mMapView.getMapCenter();
textViewCurrentLocation.setText(df.format(mapCenter.getLatitude()) + "," +
df.format(mapCenter.getLongitude())
+ "," + mMapView.getZoomLevelDouble());
}
@Override
public void onClick(View v) {
final BoundingBox boundingBox = new BoundingBox(41.906802, 12.445436, 41.900073, 12.457852);
mMapView.zoomToBoundingBox(boundingBox, false);
mMapView.zoomToBoundingBox(boundingBox, false);
mMapView.invalidate();
//Log.d(LOGTAG, "ZoomToBoundingBox calculations: " + maxZoomLatitudeSpan + ","+maxZoomLongitudeSpan + ","+requiredLatitudeZoom + ","+requiredLongitudeZoom );
//D/OsmDroid: ZoomToBoundingBox calculations: 1.367585271809038E-4,9.655952453613281E-4,13.0,15.0
//D/OsmDroid: ZoomToBoundingBox calculations: 0.0011179235048756064,9.655952453613281E-4,16.0,15.0
}
}