MainActivity.java
7.92 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package com.pashanhoo.landsurvey;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.runtime.ArcGISRuntime;
import com.esri.core.geometry.Point;
import com.pashanhoo.landsurvey.layers.tianditu.TDTTileinfo;
import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLocalTiledMapServiceLayer;
import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuTiledMapServiceLayer;
import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuTiledMapServiceType;
import com.pashanhoo.landsurvey.utils.AppInfo;
public class MainActivity extends AppCompatActivity {
private MapView mapView;
private LocationDisplayManager locationDisplayManager;
private TianDiTuTiledMapServiceLayer t_vec;
private TianDiTuTiledMapServiceLayer t_cva;
private TianDiTuTiledMapServiceLayer t_img;
private TianDiTuTiledMapServiceLayer t_cia;
// mbtiles式天地图数据
private TianDiTuLocalTiledMapServiceLayer t_local;
private String mapType;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//初始化-------------------------------------------------------------------
AppInfo.Settings();
//按钮动作-------------------------------------------------------------------
FloatingActionButton zoomin = (FloatingActionButton) findViewById(R.id.zoomin);
zoomin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(locationDisplayManager!=null){
locationDisplayManager.stop();
}
mapView.zoomin(true);
}
});
FloatingActionButton zoomout = (FloatingActionButton) findViewById(R.id.zoomout);
zoomout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(locationDisplayManager!=null){
locationDisplayManager.stop();
}
mapView.zoomout(true);
}
});
FloatingActionButton fullmap = (FloatingActionButton) findViewById(R.id.fullmap);
fullmap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
locationDisplayManager.stop();
mapView.zoomToResolution(AppInfo.initPoint, AppInfo.initRes);
}
});
FloatingActionButton gps = (FloatingActionButton) findViewById(R.id.gps);
gps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(locationDisplayManager.isStarted()){
locationDisplayManager.stop();
}else{
locationDisplayManager.start();
mapView.zoomToResolution(locationDisplayManager.getPoint(), TDTTileinfo.getRes4490()[18]);
}
}
});
//地图初始化-------------------------------------------------------------------
ArcGISRuntime.setClientId("1eFHW78avlnRUPHm");
mapView = (MapView)findViewById(R.id.map);
mapView.setEsriLogoVisible(false);
mapView.enableWrapAround(false);
t_vec = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.VEC_C);
mapView.addLayer(t_vec);
t_cva = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.CVA_C);
mapView.addLayer(t_cva);
// t_local = new TianDiTuLocalTiledMapServiceLayer("my.mbtiles");
// mapView.addLayer(t_local);
t_img = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.IMG_C);
t_img.setVisible(false);
mapView.addLayer(t_img);
t_cia = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.CIA_C);
t_cia.setVisible(false);
mapView.addLayer(t_cia);
mapType = "VEC";
mapView.setMaxResolution(TDTTileinfo.getRes4490()[0]);
mapView.setMinResolution(TDTTileinfo.getRes4490()[18]);
mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
private static final long serialVersionUID = 1L;
@Override
public void onStatusChanged(Object o, STATUS status) {
if(status == STATUS.INITIALIZED){
mapView.zoomToResolution(AppInfo.initPoint, AppInfo.initRes);
}
}
});
// GPS
locationDisplayManager = mapView.getLocationDisplayManager();
locationDisplayManager.setShowLocation(true);
locationDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.LOCATION);//设置模式
locationDisplayManager.setShowPings(true);
locationDisplayManager.setLocationListener(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
mapView.zoomToResolution(new Point(location.getLongitude(), location.getLatitude()), mapView.getResolution());
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
});
}
@Override
public void onResume() {
super.onResume();
mapView.unpause();
if(locationDisplayManager!=null){
locationDisplayManager.resume();
}
}
@Override
public void onPause() {
super.onPause();
mapView.pause();
if(locationDisplayManager!=null){
locationDisplayManager.pause();
}
}
@Override
public void onStop() {
super.onStop();
if(locationDisplayManager!=null){
locationDisplayManager.stop();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
if(mapType == "VEC"){
setLayer("IMG");
mapType = "IMG";
}else{
setLayer("VEC");
mapType = "VEC";
}
return true;
}
return super.onOptionsItemSelected(item);
}
// 切换地图形式
private void setLayer(String type){
switch (type){
case "VEC":
t_vec.setVisible(true);
t_cva.setVisible(true);
t_img.setVisible(false);
t_cia.setVisible(false);
break;
case "IMG":
t_vec.setVisible(false);
t_cva.setVisible(false);
t_img.setVisible(true);
t_cia.setVisible(true);
break;
default:
Log.i("keymapinfo", "map");
}
}
}