fde2caee by chiangbt

百度地图图层

1 parent e877532b
...@@ -11,6 +11,8 @@ import com.esri.android.map.LocationDisplayManager; ...@@ -11,6 +11,8 @@ import com.esri.android.map.LocationDisplayManager;
11 import com.esri.android.map.MapView; 11 import com.esri.android.map.MapView;
12 import com.esri.android.runtime.ArcGISRuntime; 12 import com.esri.android.runtime.ArcGISRuntime;
13 import com.esri.core.geometry.Point; 13 import com.esri.core.geometry.Point;
14 import com.pashanhoo.landsurvey.layers.baidu.BaiduMapLayerTypes;
15 import com.pashanhoo.landsurvey.layers.baidu.BaiduMapsTiledServiceLayer;
14 import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes; 16 import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes;
15 import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer; 17 import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer;
16 import com.pashanhoo.landsurvey.layers.geoq.GeoQMapLayerTypes; 18 import com.pashanhoo.landsurvey.layers.geoq.GeoQMapLayerTypes;
...@@ -56,9 +58,13 @@ public class GoogleMapActivity extends AppCompatActivity { ...@@ -56,9 +58,13 @@ public class GoogleMapActivity extends AppCompatActivity {
56 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD); 58 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD);
57 // 高德实时交通图层 59 // 高德实时交通图层
58 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC); 60 // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC);
59 mapView.addLayer(gaodeMapsTiledServiceLayer); 61 // mapView.addLayer(gaodeMapsTiledServiceLayer);
60 //--------------------------------------------------------------------------------------------------------------------- 62 //---------------------------------------------------------------------------------------------------------------------
61 63
64 BaiduMapsTiledServiceLayer baiduMapsTiledServiceLayer = new BaiduMapsTiledServiceLayer(BaiduMapLayerTypes.BAIDU_TRAFFIC);
65 mapView.addLayer(baiduMapsTiledServiceLayer);
66
67 //---------------------------------------------------------------------------------------------------------------------
62 // GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile); 68 // GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
63 // mapView.addLayer(geoQMapsTiledServiceLayer); 69 // mapView.addLayer(geoQMapsTiledServiceLayer);
64 70
......
1 package com.pashanhoo.landsurvey.layers.baidu;
2
3 import com.pashanhoo.landsurvey.layers.BaseTiledMapServiceType;
4
5 public enum BaiduMapLayerTypes implements BaseTiledMapServiceType {
6 /**
7 * 百度矢量图层(含路网,含注记)
8 */
9 BAIDU_VECTOR,
10 /**
11 * 百度影像图层(不含路网,不含注记)
12 */
13 BAIDU_IMAGE,
14 /**
15 * 百度路网图层(含路网,含注记)
16 */
17 BAIDU_ROAD,
18 /**
19 * 百度实时交通图层
20 */
21 BAIDU_TRAFFIC;
22
23 @Override
24 public String getName()
25 {
26 return this.name().toString();
27 }
28 }
1 package com.pashanhoo.landsurvey.layers.baidu;
2
3 import android.annotation.SuppressLint;
4 import android.content.ContentValues;
5 import android.database.Cursor;
6 import android.util.Log;
7
8 import com.esri.android.map.TiledServiceLayer;
9 import com.esri.android.map.event.OnStatusChangedListener;
10 import com.esri.core.geometry.Envelope;
11 import com.esri.core.geometry.Point;
12 import com.esri.core.geometry.SpatialReference;
13 import com.esri.core.internal.io.handler.ResponseListener;
14 import com.esri.core.internal.io.handler.a;
15 import com.esri.core.io.UserCredentials;
16 import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes;
17 import com.pashanhoo.landsurvey.utils.AppInfo;
18 import com.pashanhoo.landsurvey.utils.GADBHelper;
19
20 import java.util.Calendar;
21 import java.util.TimeZone;
22 import java.util.concurrent.RejectedExecutionException;
23
24 /**
25 * Created by jiangbotao on 2018/3/28.
26 */
27
28 public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
29 private static final double xmin = -22041257.773878;
30 private static final double ymin = -32673939.6727517;
31 private static final double xmax = 22041257.773878;
32 private static final double ymax = 20851350.0432886;
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
39 private static final double[] res = {156543.03392800014,
40 78271.516963999937,
41 39135.758482000092,
42 19567.879240999919,
43 9783.9396204999593,
44 4891.9698102499797,
45 2445.9849051249898,
46 1222.9924525624949,
47 611.49622628138,
48 305.748113140558,
49 152.874056570411,
50 76.4370282850732,
51 38.2185141425366,
52 19.1092570712683,
53 9.55462853563415,
54 4.7773142679493699,
55 2.3886571339746849,
56 1.1943285668550503,
57 0.59716428355981721,
58 0.29858214164761665};
59
60 private static final double[] scale = {591657527.591555,
61 295828763.79577702,
62 147914381.89788899,
63 73957190.948944002,
64 36978595.474472001,
65 18489297.737236001,
66 9244648.8686180003,
67 4622324.4343090001,
68 2311162.217155,
69 1155581.108577,
70 577790.554289,
71 288895.277144,
72 144447.638572,
73 72223.819286, 6111.909643,
74 18055.954822,
75 9027.9774109999998,
76 4513.9887049999998
77 , 2256.994353,
78 1128.4971760000001};
79
80 private static String URL = "http://maps.iwxlh.com";
81 private ResponseListener responseListener;
82 private static Point origin = new Point(-20037508.342787, 20037508.342787);
83
84 private BaiduMapLayerTypes baiduMapLayerTypes;
85
86 public BaiduMapsTiledServiceLayer(BaiduMapLayerTypes layerType) {
87 this(true);
88 this.baiduMapLayerTypes = layerType;
89 // 新建数据表,主要在Activity中必须有AppInfo.Settings()初始数据库
90 GADBHelper.createTable(AppInfo.mapcachedb, this.baiduMapLayerTypes.getName());
91 }
92
93 public BaiduMapsTiledServiceLayer(boolean initLayer) {
94 super(URL);
95 this.isBingMap = true;
96
97 if (!(initLayer))
98 return;
99 try {
100 getServiceExecutor().submit(new Runnable() {
101 public void run() {
102 BaiduMapsTiledServiceLayer.this.initLayer();
103 }
104 });
105 } catch (RejectedExecutionException localRejectedExecutionException) {
106 Log.e("ArcGIS", "initialization of the layer failed.", localRejectedExecutionException);
107 }
108 }
109
110 public static double[] getRes() {
111 return res;
112 }
113
114 protected void initLayer() {
115 if (getID() == 0L) {
116 this.nativeHandle = create();
117 }
118 if (getID() == 0L) {
119 this.changeStatus(OnStatusChangedListener.STATUS.fromInt(-1000));
120 } else {
121 try {
122 this.setDefaultSpatialReference(SpatialReference.create(102100));
123 this.setFullExtent(new Envelope(xmin, ymin, xmax, ymax));
124 this.setTileInfo(new TileInfo(origin, scale, res, scale.length, 96, 256, 256));
125 super.initLayer();
126 } catch (Exception localException) {
127 this.changeStatus(OnStatusChangedListener.STATUS.fromInt(-1005));
128 Log.e("ArcGIS", "Bing map url =" + getUrl(), localException);
129 }
130 }
131 }
132
133 @SuppressLint("DefaultLocale")
134 protected byte[] getTile(int level, int col, int row) throws Exception {
135 byte[] result = null;
136
137 String url = "";
138 String s = "Galil";
139 switch (baiduMapLayerTypes) {
140 case BAIDU_VECTOR:
141 int offsetV = (int) (Math.pow(2, level - 1));
142 url= "http://online" + ((col + row) % 8 + 1) + ".map.bdimg.com/onlinelabel/?qt=tile"
143 + "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1) + "&z=" + level
144 + "&styles=sl";
145 break;
146 case BAIDU_IMAGE:
147 int offsetI = (int) (Math.pow(2, level - 1));
148 url= "http://online" + ((col + row) % 8 + 1) + ".map.bdimg.com/onlinelabel/?qt=tile"
149 + "&x=" + (col - offsetI) + "&y=" + (offsetI - row - 1) + "&z=" + level
150 + "&styles=pl";
151 break;
152 case BAIDU_ROAD:
153 url = "http://webst02.is.autonavi.com/appmaptile?style=8&x=" + col + "&y=" + row + "&z=" + level;
154 break;
155 case BAIDU_TRAFFIC:
156 int offsetT = (int) (Math.pow(2, level - 1));
157 url = "http://its.map.baidu.com:8002/traffic/TrafficTileService?"
158 + "level=" + level + "&x=" + (col - offsetT) + "&y=" + (offsetT - row - 1)
159 + "&time=" + System.currentTimeMillis();
160 break;
161 }
162 Log.i("baidu", url);
163 try {
164 // 首先从离线数据库中读取
165 result = getOfflineCacheDB(level, col, row);
166 // 如果没有就直接从web上读取
167 if (result == null) {
168 result = a.a(url, null, null, this.responseListener);
169 // 将读取的数据存入mbtiles中
170 AddOfflineCacheDB(level, col, row, result);
171 }
172 } catch (Exception ex) {
173 ex.printStackTrace();
174 }
175
176 return result;
177 }
178
179 public void refresh() {
180 try {
181 getServiceExecutor().submit(new Runnable() {
182 public void run() {
183 if (!(BaiduMapsTiledServiceLayer.this.isInitialized()))
184 return;
185 try {
186 BaiduMapsTiledServiceLayer.this.clearTiles();
187 } catch (Exception localException) {
188 Log.e("ArcGIS", "Re-initialization of the layer failed.", localException);
189 }
190 }
191 });
192 } catch (RejectedExecutionException localRejectedExecutionException) {
193 return;
194 }
195 }
196
197 public void reinitializeLayer(UserCredentials usercredentials) {
198 }
199
200 public void reinitializeLayer(String appID) {
201 super.reinitializeLayer(null);
202 }
203
204 private byte[] getOfflineCacheDB(int level, int col, int row) throws Exception {
205
206 byte[] result = null;
207 String sql = "select * from " + this.baiduMapLayerTypes.getName() + " where TILELEVEL = " + level + " and TILECOL = " + col + " and TILEROW = " + row;
208 Cursor mCursor = AppInfo.mapcachedb.rawQuery(sql, null);
209 boolean hasData = false;
210
211 while (mCursor.moveToNext()) {//判断是否存在数据
212 hasData = true;
213 }
214 if (hasData) {//数据库中有数据
215 try {
216 if (mCursor.moveToFirst()) {
217 result = mCursor.getBlob(mCursor.getColumnIndex("TILEDATA"));
218 }
219 mCursor.close();
220 } catch (Exception e) {
221 e.printStackTrace();
222 result = null;
223 }
224 }
225 return result;
226 }
227
228 private void AddOfflineCacheDB(int level, int col, int row, byte[] bytes) {
229 ContentValues values = new ContentValues();
230 values.put("TILELEVEL", level);
231 values.put("TILECOL", col);
232 values.put("TILEROW", row);
233 values.put("TILEDATA", bytes);
234
235 AppInfo.mapcachedb.insert(this.baiduMapLayerTypes.getName(), null, values);
236 }
237 }