GoogleMapActivity.java
5.44 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
package com.pashanhoo.landsurvey;
import android.location.Location;
import android.location.LocationListener;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
import com.esri.android.runtime.ArcGISRuntime;
import com.esri.core.geometry.Point;
import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes;
import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.geoq.GeoQMapLayerTypes;
import com.pashanhoo.landsurvey.layers.geoq.GeoQMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.google.GoogleMapLayerTypes;
import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GISHelper;
import com.pashanhoo.landsurvey.utils.JZLocationConverter;
public class GoogleMapActivity extends AppCompatActivity {
private MapView mapView;
// GPS定位器对象
private LocationDisplayManager locationDisplayManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_map);
AppInfo.Settings();
ArcGISRuntime.setClientId("1eFHW78avlnRUPHm");
mapView = (MapView) findViewById(R.id.map);
mapView.setEsriLogoVisible(false);
mapView.enableWrapAround(false);
// GoogleMapsTiledServiceLayer GOOGLE_VECTOR_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.VECTOR_GOOGLE_MAP);
// GoogleMapsTiledServiceLayer GOOGLE_TER_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP);
// GoogleMapsTiledServiceLayer GOOGLE_IMAGE_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.IMAGE_GOOGLE_MAP);
// mapView.addLayer(GOOGLE_IMAGE_Layer);
// GoogleMapsTiledServiceLayer GOOGLE_ANNO_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.IMAGE_ANNO_GOOGLE_MAP);
// mapView.addLayer(GOOGLE_ANNO_Layer);
// GoogleMapsTiledServiceLayer OSM_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.OSM_Map);
// mapView.addLayer(OSM_Layer);
//---------------------------------------------------------------------------------------------------------------------
// 高德矢量图层(含路网,含注记)
GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
// 高德影像图层(不含路网,不含注记)
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE);
// 高德路网图层(含路网,含注记)
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD);
// 高德实时交通图层
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC);
mapView.addLayer(gaodeMapsTiledServiceLayer);
//---------------------------------------------------------------------------------------------------------------------
// GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
// mapView.addLayer(geoQMapsTiledServiceLayer);
mapView.setMaxResolution(156543.03392800014);
mapView.setMinResolution(0.29858214164761665);
Point pt = GISHelper.lonLat2Mercator(AppInfo.initPoint);
mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[16]);
locationDisplayManager = mapView.getLocationDisplayManager();
locationDisplayManager.setShowLocation(true);
locationDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.LOCATION);//设置模式
locationDisplayManager.setShowPings(true);
locationDisplayManager.setLocationListener(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Point pt = new Point(location.getLongitude(), location.getLatitude());
Point gcjPt = JZLocationConverter.wgs84ToGcj02(pt);
mapView.zoomToResolution(GISHelper.lonLat2Mercator(gcjPt),
GoogleMapsTiledServiceLayer.getRes()[18]);
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
});
FloatingActionButton gps = (FloatingActionButton) findViewById(R.id.gps);
gps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 设置GPS功能
if (locationDisplayManager.isStarted()) {
locationDisplayManager.stop();
} else {
locationDisplayManager.start();
mapView.zoomToResolution(GISHelper.lonLat2Mercator(locationDisplayManager.getPoint()),
GoogleMapsTiledServiceLayer.getRes()[18]);
}
}
});
}
}