44ea6c1a by chiangbt

更新百度地图数据及应用案例

1 parent 4165197e
No preview for this file type
...@@ -16,9 +16,7 @@ ...@@ -16,9 +16,7 @@
16 android:label="@string/app_name" 16 android:label="@string/app_name"
17 android:supportsRtl="true" 17 android:supportsRtl="true"
18 android:theme="@style/AppTheme"> 18 android:theme="@style/AppTheme">
19 <activity android:name=".BootActivity"> 19 <activity android:name=".BootActivity" />
20
21 </activity>
22 <activity 20 <activity
23 android:name=".MainActivity" 21 android:name=".MainActivity"
24 android:label="@string/app_name" 22 android:label="@string/app_name"
...@@ -32,6 +30,9 @@ ...@@ -32,6 +30,9 @@
32 <category android:name="android.intent.category.LAUNCHER" /> 30 <category android:name="android.intent.category.LAUNCHER" />
33 </intent-filter> 31 </intent-filter>
34 </activity> 32 </activity>
33 <activity android:name=".BaiduMapActivity">
34
35 </activity>
35 </application> 36 </application>
36 37
37 </manifest> 38 </manifest>
...\ No newline at end of file ...\ No newline at end of file
......
1 package com.pashanhoo.landsurvey;
2
3 import android.support.v7.app.AppCompatActivity;
4 import android.os.Bundle;
5 import android.widget.Toast;
6
7 import com.esri.android.map.LocationDisplayManager;
8 import com.esri.android.map.MapView;
9 import com.esri.android.map.event.OnStatusChangedListener;
10 import com.esri.android.runtime.ArcGISRuntime;
11 import com.esri.core.geometry.Point;
12 import com.pashanhoo.landsurvey.layers.baidu.BaiduMapLayerTypes;
13 import com.pashanhoo.landsurvey.layers.baidu.BaiduMapsTiledServiceLayer;
14 import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer;
15 import com.pashanhoo.landsurvey.utils.AppInfo;
16 import com.pashanhoo.landsurvey.utils.GISHelper;
17 import com.pashanhoo.landsurvey.utils.JZLocationConverter;
18
19 public class BaiduMapActivity extends AppCompatActivity {
20
21 private MapView mapView;
22 // GPS定位器对象
23 private LocationDisplayManager locationDisplayManager;
24
25 @Override
26 protected void onCreate(Bundle savedInstanceState) {
27 super.onCreate(savedInstanceState);
28 setContentView(R.layout.activity_baidu_map);
29
30 AppInfo.Settings();
31
32 ArcGISRuntime.setClientId("1eFHW78avlnRUPHm");
33 mapView = (MapView) findViewById(R.id.map);
34 mapView.setEsriLogoVisible(false);
35 mapView.enableWrapAround(false);
36
37 BaiduMapsTiledServiceLayer baiduMapsTiledServiceLayer = new BaiduMapsTiledServiceLayer(BaiduMapLayerTypes.BAIDU_VECTOR);
38 mapView.addLayer(baiduMapsTiledServiceLayer);
39
40 mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
41 @Override
42 public void onStatusChanged(Object o, STATUS status) {
43 if(status == STATUS.INITIALIZED){
44 Point curPt = JZLocationConverter.wgs84ToGcj02(AppInfo.initPoint);
45 Point pt = GISHelper.lonLat2Mercator(curPt);
46 mapView.zoomToResolution(pt, BaiduMapsTiledServiceLayer.getRes()[10]);
47
48 Toast.makeText(BaiduMapActivity.this,
49 mapView.getCenter().getX() + ":" + mapView.getCenter().getY(),
50 Toast.LENGTH_LONG).show();
51 }
52 }
53 });
54
55
56 }
57 }
...@@ -2,10 +2,12 @@ package com.pashanhoo.landsurvey; ...@@ -2,10 +2,12 @@ package com.pashanhoo.landsurvey;
2 2
3 import android.location.Location; 3 import android.location.Location;
4 import android.location.LocationListener; 4 import android.location.LocationListener;
5 import android.os.Environment;
5 import android.support.design.widget.FloatingActionButton; 6 import android.support.design.widget.FloatingActionButton;
6 import android.support.v7.app.AppCompatActivity; 7 import android.support.v7.app.AppCompatActivity;
7 import android.os.Bundle; 8 import android.os.Bundle;
8 import android.view.View; 9 import android.view.View;
10 import android.widget.Toast;
9 11
10 import com.esri.android.map.LocationDisplayManager; 12 import com.esri.android.map.LocationDisplayManager;
11 import com.esri.android.map.MapView; 13 import com.esri.android.map.MapView;
...@@ -53,7 +55,7 @@ public class GoogleMapActivity extends AppCompatActivity { ...@@ -53,7 +55,7 @@ public class GoogleMapActivity extends AppCompatActivity {
53 55
54 //--------------------------------------------------------------------------------------------------------------------- 56 //---------------------------------------------------------------------------------------------------------------------
55 // 高德矢量图层(含路网,含注记) 57 // 高德矢量图层(含路网,含注记)
56 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR); 58 GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
57 // 高德影像图层(不含路网,不含注记) 59 // 高德影像图层(不含路网,不含注记)
58 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE); 60 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE);
59 // 高德路网图层(含路网,含注记) 61 // 高德路网图层(含路网,含注记)
...@@ -70,11 +72,14 @@ public class GoogleMapActivity extends AppCompatActivity { ...@@ -70,11 +72,14 @@ public class GoogleMapActivity extends AppCompatActivity {
70 // GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile); 72 // GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
71 // mapView.addLayer(geoQMapsTiledServiceLayer); 73 // mapView.addLayer(geoQMapsTiledServiceLayer);
72 74
75
73 mapView.setMaxResolution(156543.03392800014); 76 mapView.setMaxResolution(156543.03392800014);
74 mapView.setMinResolution(0.29858214164761665); 77 mapView.setMinResolution(0.29858214164761665);
75 78
76 Point pt = GISHelper.lonLat2Mercator(AppInfo.initPoint); 79
77 mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[16]); 80 Point curPt = JZLocationConverter.wgs84ToGcj02(AppInfo.initPoint);
81 Point pt = GISHelper.lonLat2Mercator(curPt);
82 mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[17]);
78 83
79 locationDisplayManager = mapView.getLocationDisplayManager(); 84 locationDisplayManager = mapView.getLocationDisplayManager();
80 locationDisplayManager.setShowLocation(true); 85 locationDisplayManager.setShowLocation(true);
...@@ -113,8 +118,40 @@ public class GoogleMapActivity extends AppCompatActivity { ...@@ -113,8 +118,40 @@ public class GoogleMapActivity extends AppCompatActivity {
113 locationDisplayManager.start(); 118 locationDisplayManager.start();
114 mapView.zoomToResolution(GISHelper.lonLat2Mercator(locationDisplayManager.getPoint()), 119 mapView.zoomToResolution(GISHelper.lonLat2Mercator(locationDisplayManager.getPoint()),
115 GoogleMapsTiledServiceLayer.getRes()[18]); 120 GoogleMapsTiledServiceLayer.getRes()[18]);
121
122 Point cupt = GISHelper.mercator2lonLat(mapView.getCenter());
123 Toast.makeText(GoogleMapActivity.this,
124 cupt.getX() + ":" + cupt.getY(),
125 Toast.LENGTH_LONG).show();
116 } 126 }
117 } 127 }
118 }); 128 });
119 } 129 }
130
131 @Override
132 public void onResume() {
133 super.onResume();
134 mapView.unpause();
135 if (locationDisplayManager != null) {
136 locationDisplayManager.resume();
137 }
138 }
139
140 @Override
141 public void onPause() {
142 super.onPause();
143 mapView.pause();
144 if (locationDisplayManager != null) {
145 locationDisplayManager.pause();
146 }
147 }
148
149 @Override
150 public void onStop() {
151 super.onStop();
152 if (locationDisplayManager != null) {
153 locationDisplayManager.stop();
154 }
155
156 }
120 } 157 }
......
...@@ -240,7 +240,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -240,7 +240,7 @@ public class MainActivity extends AppCompatActivity {
240 mapView.zoomToResolution(poipt, t_vec.getRes()[19]); 240 mapView.zoomToResolution(poipt, t_vec.getRes()[19]);
241 graphicsLayer.addGraphic(new Graphic(poipt, 241 graphicsLayer.addGraphic(new Graphic(poipt,
242 new PictureMarkerSymbol(getResources().getDrawable(R.mipmap.locator)).setOffsetY(16))); 242 new PictureMarkerSymbol(getResources().getDrawable(R.mipmap.locator)).setOffsetY(16)));
243 mapinfoView.setText("当前地图级别为:"+ t_vec.getCurrentLevel()); 243 mapinfoView.setText("当前地图级别为:" + t_vec.getCurrentLevel());
244 } 244 }
245 245
246 @Override 246 @Override
......
...@@ -8,6 +8,8 @@ import android.util.Log; ...@@ -8,6 +8,8 @@ import android.util.Log;
8 import com.esri.android.map.TiledServiceLayer; 8 import com.esri.android.map.TiledServiceLayer;
9 import com.esri.android.map.event.OnStatusChangedListener; 9 import com.esri.android.map.event.OnStatusChangedListener;
10 import com.esri.core.geometry.Envelope; 10 import com.esri.core.geometry.Envelope;
11 import com.esri.core.geometry.GeometryEngine;
12 import com.esri.core.geometry.GeometryUtil;
11 import com.esri.core.geometry.Point; 13 import com.esri.core.geometry.Point;
12 import com.esri.core.geometry.SpatialReference; 14 import com.esri.core.geometry.SpatialReference;
13 import com.esri.core.internal.io.handler.ResponseListener; 15 import com.esri.core.internal.io.handler.ResponseListener;
...@@ -26,15 +28,10 @@ import java.util.concurrent.RejectedExecutionException; ...@@ -26,15 +28,10 @@ import java.util.concurrent.RejectedExecutionException;
26 */ 28 */
27 29
28 public class BaiduMapsTiledServiceLayer extends TiledServiceLayer { 30 public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
29 private static final double xmin = -22041257.773878; 31 private static final double xmin = -20037508.3427892;
30 private static final double ymin = -32673939.6727517; 32 private static final double ymin = -20037508.3427892;
31 private static final double xmax = 22041257.773878; 33 private static final double xmax = 20037508.3427892;
32 private static final double ymax = 20851350.0432886; 34 private static final double ymax = 20037508.3427892;
33
34 private static final double XMin = 110.35992000000005;
35 private static final double YMin = 31.382360000000062;
36 private static final double XMax = 116.65036000000009;
37 private static final double YMax = 36.36647000000005;
38 35
39 private static final double[] res = {156543.03392800014, 36 private static final double[] res = {156543.03392800014,
40 78271.516963999937, 37 78271.516963999937,
...@@ -73,13 +70,13 @@ public class BaiduMapsTiledServiceLayer extends TiledServiceLayer { ...@@ -73,13 +70,13 @@ public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
73 72223.819286, 6111.909643, 70 72223.819286, 6111.909643,
74 18055.954822, 71 18055.954822,
75 9027.9774109999998, 72 9027.9774109999998,
76 4513.9887049999998 73 4513.9887049999998,
77 , 2256.994353, 74 2256.994353,
78 1128.4971760000001}; 75 1128.4971760000001};
79 76
80 private static String URL = "http://maps.iwxlh.com"; 77 private static String URL = "http://maps.iwxlh.com";
81 private ResponseListener responseListener; 78 private ResponseListener responseListener;
82 private static Point origin = new Point(-20037508.342787, 20037508.342787); 79 private static Point origin = new Point(-20037508.3427892, 20037508.3427892);
83 80
84 private BaiduMapLayerTypes baiduMapLayerTypes; 81 private BaiduMapLayerTypes baiduMapLayerTypes;
85 82
...@@ -136,26 +133,32 @@ public class BaiduMapsTiledServiceLayer extends TiledServiceLayer { ...@@ -136,26 +133,32 @@ public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
136 Log.i("baidu", level + "/"+col+"/"+row); 133 Log.i("baidu", level + "/"+col+"/"+row);
137 String url = ""; 134 String url = "";
138 String s = "Galil"; 135 String s = "Galil";
139 int offsetV = (int) (Math.pow(2, level - 1)); 136
137 int zoom = level - 1;
138 int offsetX = (int)Math.pow(2, level - 1);
139 int offsetY = offsetX - 1;
140 int numX = col - (int)Math.pow(2, level - 1);
141 int numY = (-row) + offsetY;
142 zoom = level + 1;
143 int num = (col + row) % 8 + 1;
144 num = 2;
145
140 switch (baiduMapLayerTypes) { 146 switch (baiduMapLayerTypes) {
141 case BAIDU_VECTOR: 147 case BAIDU_VECTOR:
142 url= "http://online" + ((col + row) % 8 + 1) + ".map.bdimg.com/onlinelabel/?qt=tile" 148 // url= "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=pl&scaler=1&udt=20141103";
143 + "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1) + "&z=" + level 149 url = "http://online" + num +".map.bdimg.com/tile/?qt=tile&x=" + numX + "&y=" + numY + "&z=" + zoom + "&styles=pl";
144 + "&styles=pl";
145 break;
146 case BAIDU_IMAGE:
147 url= "http://online" + ((col + row) % 8 + 1) + ".map.bdimg.com/onlinelabel/?qt=tile"
148 + "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1) + "&z=" + level
149 + "&styles=sl";
150 break; 150 break;
151 case BAIDU_ROAD: 151 case BAIDU_ROAD:
152 url = "http://online" + num +".map.bdimg.com/tile/?qt=tile&x=" + numX + "&y=" + numY + "&z=" + zoom + "&styles=sl";
153 break;
154 case BAIDU_IMAGE:
152 url = "http://shangetu" + ((col + row) % 8 + 1) + ".map.bdimg.com/it/u=" 155 url = "http://shangetu" + ((col + row) % 8 + 1) + ".map.bdimg.com/it/u="
153 + "x=" + (col - offsetV) + ";y=" + (offsetV - row - 1) + ";z=" + level 156 + "x=" + numX + ";y=" + numY+ ";z=" + zoom
154 + ";v=009;type=sate&fm=46"; 157 + ";v=009;type=sate&fm=46";
155 break; 158 break;
156 case BAIDU_TRAFFIC: 159 case BAIDU_TRAFFIC:
157 url = "http://its.map.baidu.com:8002/traffic/TrafficTileService?" 160 url = "http://its.map.baidu.com:8002/traffic/TrafficTileService?"
158 + "level=" + level + "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1) 161 + "level=" + zoom + "&x=" + numX + "&y=" + numY
159 + "&time=" + System.currentTimeMillis(); 162 + "&time=" + System.currentTimeMillis();
160 break; 163 break;
161 } 164 }
......
...@@ -24,22 +24,10 @@ public enum TianDiTuLayerTypes implements BaseTiledMapServiceType { ...@@ -24,22 +24,10 @@ public enum TianDiTuLayerTypes implements BaseTiledMapServiceType {
24 * 影像注记 24 * 影像注记
25 * */ 25 * */
26 CIA_C, 26 CIA_C,
27 /** 27
28 * 矢量数据,web墨卡托4326 28 TER_C,
29 */ 29
30 VEC_W, 30 CTA_C;
31 /**
32 * 影像数据
33 * */
34 IMG_W,
35 /**
36 * 矢量注记
37 * */
38 CVA_W,
39 /**
40 * 影像注记
41 * */
42 CIA_W;
43 31
44 public void setName() 32 public void setName()
45 { 33 {
......
...@@ -190,6 +190,12 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer { ...@@ -190,6 +190,12 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
190 case IMG_C: 190 case IMG_C:
191 url.append(".tianditu.com/DataServer?T=img_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level); 191 url.append(".tianditu.com/DataServer?T=img_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
192 break; 192 break;
193 case TER_C:
194 url.append(".tianditu.com/DataServer?T=ter_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
195 break;
196 case CTA_C:
197 url.append(".tianditu.com/DataServer?T=cta_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
198 break;
193 default: 199 default:
194 return null; 200 return null;
195 } 201 }
......
...@@ -19,9 +19,9 @@ public class AppInfo { ...@@ -19,9 +19,9 @@ public class AppInfo {
19 19
20 public static SQLiteDatabase mapcachedb; 20 public static SQLiteDatabase mapcachedb;
21 21
22 public static Point initPoint = new Point(121.56, 29.862149); 22 public static Point initPoint = new Point(116.39167, 39.90333);
23 23
24 public static double initRes = TDTTileinfo.getRes4490()[6]; 24 public static double initRes = TDTTileinfo.getRes4490()[17];
25 // public static double initRes = TDTTileinfo.getRes4326()[6]; 25 // public static double initRes = TDTTileinfo.getRes4326()[6];
26 26
27 27
......
1 <?xml version="1.0" encoding="utf-8"?>
2 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 tools:context=".BaiduMapActivity">
8
9 <com.esri.android.map.MapView
10 android:id="@+id/map"
11 android:layout_width="fill_parent"
12 android:layout_height="fill_parent"></com.esri.android.map.MapView>
13
14 <android.support.v7.widget.LinearLayoutCompat
15 android:layout_width="match_parent"
16 android:layout_height="match_parent"
17 android:orientation="vertical"
18 android:layout_marginTop="16dp"
19 android:layout_marginLeft="16dp"
20 android:layout_marginBottom="16dp"
21 android:layout_gravity="top|start">
22 <android.support.design.widget.FloatingActionButton
23 android:id="@+id/gps"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content"
26 android:layout_gravity="top|start"
27 android:layout_marginTop="0dp"
28 android:layout_marginLeft="0dp"
29 app:srcCompat="@mipmap/ic_my_location_white_48dp" />
30 </android.support.v7.widget.LinearLayoutCompat>
31
32 </android.support.constraint.ConstraintLayout>
...\ No newline at end of file ...\ No newline at end of file
...@@ -9,4 +9,5 @@ ...@@ -9,4 +9,5 @@
9 9
10 <string name="drawer_item_section_header1">图层控制</string> 10 <string name="drawer_item_section_header1">图层控制</string>
11 <string name="drawer_item_section_header2">版权信息</string> 11 <string name="drawer_item_section_header2">版权信息</string>
12 <string name="title_activity_baidu_map">BaiduMapActivity</string>
12 </resources> 13 </resources>
......
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
13 - TianDiTuLayerTypes 13 - TianDiTuLayerTypes
14 - VEC_C,矢量图层 14 - VEC_C,矢量图层
15 - IMG_C,影像图层 15 - IMG_C,影像图层
16 - TER_C,地形层
16 - CVA_C,矢量注记层 17 - CVA_C,矢量注记层
17 - CIA_C,影像注记层 18 - CIA_C,影像注记层
19 - CTA_C,地形注记层
18 20
19 腾讯图层 21 腾讯图层
20 22
...@@ -62,7 +64,7 @@ Point initPoint = new Point(121.56, 29.862149); ...@@ -62,7 +64,7 @@ Point initPoint = new Point(121.56, 29.862149);
62 mapView.zoomToResolution(initPoint, t_vec.getRes()[16]); 64 mapView.zoomToResolution(initPoint, t_vec.getRes()[16]);
63 ``` 65 ```
64 66
65 其它 67 其它(以Tencent图层为例)
66 ``` 68 ```
67 TencentMapsTiledServiceLayer tencentMapsTiledServiceLayer = new TencentMapsTiledServiceLayer(TencentMapLayerTypes.TENCENT_MAP_VECTOR); 69 TencentMapsTiledServiceLayer tencentMapsTiledServiceLayer = new TencentMapsTiledServiceLayer(TencentMapLayerTypes.TENCENT_MAP_VECTOR);
68 mapView.addLayer(tencentMapsTiledServiceLayer); 70 mapView.addLayer(tencentMapsTiledServiceLayer);
......