8b3ceed3 by chiangbt

update 3.29

1 parent 07d77721
......@@ -17,7 +17,11 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BootActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
......@@ -26,11 +30,7 @@
android:theme="@style/AppTheme.NoActionBar"> <!-- 禁止屏幕旋转 -->
</activity>
<activity android:name=".GoogleMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
......
......@@ -28,15 +28,17 @@ public class GoogleMapActivity extends AppCompatActivity {
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_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_VECTOR_Layer);
GoogleMapsTiledServiceLayer GOOGLE_IMAGE_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.IMAGE_GOOGLE_MAP);
mapView.addLayer(GOOGLE_IMAGE_Layer);
// GoogleMapsTiledServiceLayer GOOGLE_ANNO_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.ANNOTATION_GOOGLE_MAP);
// mapView.addLayer(GOOGLE_ANNO_Layer);
......
package com.pashanhoo.landsurvey;
import android.annotation.SuppressLint;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
......@@ -30,7 +29,7 @@ import com.esri.core.symbol.PictureMarkerSymbol;
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.layers.tianditu.TianDiTuLayerTypes;
import com.pashanhoo.landsurvey.search.POISuggestion;
import com.pashanhoo.landsurvey.utils.AppInfo;
......@@ -129,7 +128,7 @@ public class MainActivity extends AppCompatActivity {
locationDisplayManager.stop();
} else {
locationDisplayManager.start();
mapView.zoomToResolution(locationDisplayManager.getPoint(), TDTTileinfo.getRes4490()[18]);
mapView.zoomToResolution(locationDisplayManager.getPoint(), t_vec.getRes()[18]);
}
}
});
......@@ -154,18 +153,18 @@ public class MainActivity extends AppCompatActivity {
mapView.setEsriLogoVisible(false);
mapView.enableWrapAround(false);
// 添加地图图层
t_vec = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.VEC_C);
t_vec = new TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes.VEC_C);
mapView.addLayer(t_vec);
t_cva = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.CVA_C);
t_cva = new TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes.CVA_C);
mapView.addLayer(t_cva);
// 一个本地sqlite数据库,注意其只有8-9级数据,因此在数据层中予以了显示控制
t_local = new TianDiTuLocalTiledMapServiceLayer("my.db", "IMG_C");
mapView.addLayer(t_local);
// 添加地图图层
t_img = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.IMG_C);
t_img = new TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes.IMG_C);
t_img.setVisible(false);
mapView.addLayer(t_img);
t_cia = new TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType.CIA_C);
t_cia = new TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes.CIA_C);
t_cia.setVisible(false);
mapView.addLayer(t_cia);
mapType = "VEC";
......@@ -173,8 +172,8 @@ public class MainActivity extends AppCompatActivity {
graphicsLayer = new GraphicsLayer();
mapView.addLayer(graphicsLayer);
// 设置地图的最小和最大分辨率
mapView.setMaxResolution(TDTTileinfo.getRes4490()[1]);
mapView.setMinResolution(TDTTileinfo.getRes4490()[19]);
mapView.setMaxResolution(t_vec.getRes()[1]);
mapView.setMinResolution(t_vec.getRes()[19]);
// 监听地图状态变化事件
mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
private static final long serialVersionUID = 1L;
......@@ -215,7 +214,7 @@ public class MainActivity extends AppCompatActivity {
locationDisplayManager.setLocationListener(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
mapView.zoomToResolution(new Point(location.getLongitude(), location.getLatitude()), TDTTileinfo.getRes4490()[18]);
mapView.zoomToResolution(new Point(location.getLongitude(), location.getLatitude()), t_vec.getRes()[18]);
mapinfoView.setText("当前地图级别为:18");
}
......@@ -240,7 +239,7 @@ public class MainActivity extends AppCompatActivity {
POISuggestion colorSuggestion = (POISuggestion) searchSuggestion;
Point poipt = new Point(colorSuggestion.getLng(), colorSuggestion.getLat());
mapView.zoomToResolution(poipt, TDTTileinfo.getRes4490()[19]);
mapView.zoomToResolution(poipt, t_vec.getRes()[19]);
graphicsLayer.addGraphic(new Graphic(poipt,
new PictureMarkerSymbol(getResources().getDrawable(R.mipmap.locator)).setOffsetY(16)));
// floatingSearchView.clearSuggestions();
......
package com.pashanhoo.landsurvey.layers.google;
import com.pashanhoo.landsurvey.layers.BaseTiledMapServiceType;
/**
* Created by jiangbotao on 2018/3/28.
*/
public interface GoogleMapLayerTypes {
public enum GoogleMapLayerTypes implements BaseTiledMapServiceType {
/** * Google vector map service by city map*/
final int VECTOR_GOOGLE_MAP = 1;
VECTOR_GOOGLE_MAP,
/** * Google image map service by satellite map */
final int IMAGE_GOOGLE_MAP = 2;
IMAGE_GOOGLE_MAP,
/** * Google topographic map service ======= topographic map */
final int TERRAIN_GOOGLE_MAP = 3;
TERRAIN_GOOGLE_MAP,
/** * Google road POI map service = = = = net road map */
final int ANNOTATION_GOOGLE_MAP = 4;
ANNOTATION_GOOGLE_MAP;
@Override
public String getName()
{
return this.name().toString();
}
}
......
package com.pashanhoo.landsurvey.layers.google;
import com.esri.android.map.TiledServiceLayer;
import java.util.concurrent.RejectedExecutionException;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;
import com.esri.android.map.TiledServiceLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
......@@ -14,6 +15,8 @@ import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.ResponseListener;
import com.esri.core.internal.io.handler.a;
import com.esri.core.io.UserCredentials;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GADBHelper;
import com.pashanhoo.landsurvey.utils.GISHelper;
/**
......@@ -28,27 +31,61 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
private static final double XMin = 110.35992000000005;
private static final double YMin = 31.382360000000062;
private static final double XMax = 116.65036000000009;
private static final double YMax = 36.36647000000005;
private static final double[] res = {156543.03392800014, 78271.516963999937, 39135.758482000092, 19567.879240999919, 9783.9396204999593, 4891.9698102499797, 2445.9849051249898,
1222.9924525624949, 611.49622628138, 305.748113140558, 152.874056570411, 76.4370282850732, 38.2185141425366, 19.1092570712683, 9.55462853563415, 4.7773142679493699, 2.3886571339746849,
1.1943285668550503 , 0.59716428355981721, 0.29858214164761665 };
private static final double[] scale = {591657527.591555, 295828763.79577702, 147914381.89788899, 73957190.948944002, 36978595.474472001, 18489297.737236001, 9244648.8686180003,
4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289, 288895.277144, 144447.638572, 72223.819286, 6111.909643, 18055.954822, 9027.9774109999998, 4513.9887049999998
,2256.994353, 1128.4971760000001 };
private static final double[] res = {156543.03392800014,
78271.516963999937,
39135.758482000092,
19567.879240999919,
9783.9396204999593,
4891.9698102499797,
2445.9849051249898,
1222.9924525624949,
611.49622628138,
305.748113140558,
152.874056570411,
76.4370282850732,
38.2185141425366,
19.1092570712683,
9.55462853563415,
4.7773142679493699,
2.3886571339746849,
1.1943285668550503,
0.59716428355981721,
0.29858214164761665};
private static final double[] scale = {591657527.591555,
295828763.79577702,
147914381.89788899,
73957190.948944002,
36978595.474472001,
18489297.737236001,
9244648.8686180003,
4622324.4343090001,
2311162.217155,
1155581.108577,
577790.554289,
288895.277144,
144447.638572,
72223.819286, 6111.909643,
18055.954822,
9027.9774109999998,
4513.9887049999998
, 2256.994353,
1128.4971760000001};
private static String URL = "http://maps.iwxlh.com";
private ResponseListener responseListener;
private static Point origin = new Point(-20037508.342787, 20037508.342787);
private int GoogleMapLayerType;
private GoogleMapLayerTypes googleMapLayerType;
public GoogleMapsTiledServiceLayer(int layerType) {
public GoogleMapsTiledServiceLayer(GoogleMapLayerTypes layerType) {
this(true);
this.GoogleMapLayerType = layerType;
this.googleMapLayerType = layerType;
// 新建数据表,主要在Activity中必须有AppInfo.Settings()初始数据库
GADBHelper.createTable(AppInfo.mapcachedb, this.googleMapLayerType.getName());
}
public GoogleMapsTiledServiceLayer(boolean initLayer) {
......@@ -77,22 +114,15 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
this.nativeHandle = create();
}
if (getID() == 0L) {
changeStatus(OnStatusChangedListener.STATUS.fromInt(-1000));
this.changeStatus(OnStatusChangedListener.STATUS.fromInt(-1000));
} else {
try {
setDefaultSpatialReference(SpatialReference.create(102100));
GISHelper.lonLat2Mercator(new Point(XMin, YMin));
GISHelper.lonLat2Mercator(new Point(XMax, YMax));
setFullExtent(new Envelope(xmin, ymin, xmax, ymax));
// setFullExtent(new Envelope(minMercatorPoint.getX(),
// minMercatorPoint.getY(), maxMercatorPoint.getX(),
// maxMercatorPoint.getY()));
setTileInfo(new TiledServiceLayer.TileInfo(origin, scale, res, scale.length, 96, 256, 256));
this.setDefaultSpatialReference(SpatialReference.create(102100));
this.setFullExtent(new Envelope(xmin, ymin, xmax, ymax));
this.setTileInfo(new TiledServiceLayer.TileInfo(origin, scale, res, scale.length, 96, 256, 256));
super.initLayer();
} catch (Exception localException) {
changeStatus(OnStatusChangedListener.STATUS.fromInt(-1005));
this.changeStatus(OnStatusChangedListener.STATUS.fromInt(-1005));
Log.e("ArcGIS", "Bing map url =" + getUrl(), localException);
}
}
......@@ -100,25 +130,40 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
@SuppressLint("DefaultLocale")
protected byte[] getTile(int level, int col, int row) throws Exception {
byte[] result = null;
String url = "";
String s = "Galil";
switch (GoogleMapLayerType) {
case GoogleMapLayerTypes.IMAGE_GOOGLE_MAP:
switch (googleMapLayerType) {
case IMAGE_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=s&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.VECTOR_GOOGLE_MAP:
case VECTOR_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=m@161000000&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP:
case TERRAIN_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=t@131,r@227000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.ANNOTATION_GOOGLE_MAP:
case ANNOTATION_GOOGLE_MAP:
// url = "http://mt2.google.cn/vt/lyrs=m@161000000&v=w2.114&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s=" + s;
url = "http://webst02.is.autonavi.com/appmaptile?style=8&x="+ col +"&y="+ row +"&z="+level;
url = "http://webst02.is.autonavi.com/appmaptile?style=8&x=" + col + "&y=" + row + "&z=" + level;
break;
}
return a.a(url, null, null, this.responseListener);
try {
// 首先从离线数据库中读取
result = getOfflineCacheDB(level, col, row);
// 如果没有就直接从web上读取
if (result == null) {
result = a.a(url, null, null, this.responseListener);
// 将读取的数据存入mbtiles中
AddOfflineCacheDB(level, col, row, result);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
public void refresh() {
......@@ -145,4 +190,38 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
public void reinitializeLayer(String appID) {
super.reinitializeLayer(null);
}
private byte[] getOfflineCacheDB(int level, int col, int row) throws Exception {
byte[] result = null;
String sql = "select * from " + this.googleMapLayerType.getName() + " where TILELEVEL = " + level + " and TILECOL = " + col + " and TILEROW = " + row;
Cursor mCursor = AppInfo.mapcachedb.rawQuery(sql, null);
boolean hasData = false;
while (mCursor.moveToNext()) {//判断是否存在数据
hasData = true;
}
if (hasData) {//数据库中有数据
try {
if (mCursor.moveToFirst()) {
result = mCursor.getBlob(mCursor.getColumnIndex("TILEDATA"));
}
mCursor.close();
} catch (Exception e) {
e.printStackTrace();
result = null;
}
}
return result;
}
private void AddOfflineCacheDB(int level, int col, int row, byte[] bytes) {
ContentValues values = new ContentValues();
values.put("TILELEVEL", level);
values.put("TILECOL", col);
values.put("TILEROW", row);
values.put("TILEDATA", bytes);
AppInfo.mapcachedb.insert(this.googleMapLayerType.getName(), null, values);
}
}
......
package com.pashanhoo.landsurvey.layers.tianditu;
import java.util.Random;
/**
* Created by jiangbotao on 2018/3/23.
*/
public class TDTUrl {
private TianDiTuTiledMapServiceType _tiandituMapServiceType;
private int _level;
private int _col;
private int _row;
public TDTUrl(int level, int col, int row, TianDiTuTiledMapServiceType tiandituMapServiceType) {
this._level = level;
this._col = col;
this._row = row;
this._tiandituMapServiceType = tiandituMapServiceType;
}
public String generatUrl() {
StringBuilder url = new StringBuilder("http://t");
Random random = new Random();
int subdomain = (random.nextInt(6) + 1);
url.append(subdomain);
switch (this._tiandituMapServiceType) {
case VEC_C:
url.append(".tianditu.com/DataServer?T=vec_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case CVA_C:
url.append(".tianditu.com/DataServer?T=cva_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case CIA_C:
url.append(".tianditu.com/DataServer?T=cia_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case IMG_C:
url.append(".tianditu.com/DataServer?T=img_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case VEC_W:
url.append(".tianditu.com/DataServer?T=vec_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case CVA_W:
url.append(".tianditu.com/DataServer?T=cva_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case CIA_W:
url.append(".tianditu.com/DataServer?T=cia_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
case IMG_W:
url.append(".tianditu.com/DataServer?T=img_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
break;
default:
return null;
}
return url.toString();
}
}
......@@ -6,7 +6,7 @@ import com.pashanhoo.landsurvey.layers.BaseTiledMapServiceType;
* Created by jiangbotao on 2018/3/23.
*/
public enum TianDiTuTiledMapServiceType implements BaseTiledMapServiceType {
public enum TianDiTuLayerTypes implements BaseTiledMapServiceType {
/**
* 矢量数据,CGCS2000
......
......@@ -8,6 +8,8 @@ import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.ResponseListener;
import com.esri.core.internal.io.handler.a;
import com.esri.core.io.UserCredentials;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GADBHelper;
......@@ -16,6 +18,7 @@ import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
import java.util.concurrent.RejectedExecutionException;
/**
......@@ -24,23 +27,78 @@ import java.util.concurrent.RejectedExecutionException;
public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
private TianDiTuTiledMapServiceType _mapType;
private static final Point originalPoint = new Point(-180, 90);
private static final double[] res = {
1.40625,
0.703125,
0.3515625,
0.17578125,
0.087890625,
0.0439453125,
0.02197265625,
0.010986328125,
0.0054931640625,
0.00274658203125,
0.001373291015625,
0.0006866455078125,
0.00034332275390625,
0.000171661376953125,
8.58306884765629E-05,
4.29153442382814E-05,
2.14576721191407E-05,
1.07288360595703E-05,
5.36441802978515E-06,
2.68220901489258E-06,
1.34110450744629E-06
};
private static final double[] scale = {
400000000,
295497598.5708346,
147748799.285417,
73874399.6427087,
36937199.8213544,
18468599.9106772,
9234299.95533859,
4617149.97766929,
2308574.98883465,
1154287.49441732,
577143.747208662,
288571.873604331,
144285.936802165,
72142.9684010827,
36071.4842005414,
18035.7421002707,
9017.87105013534,
4508.93552506767,
2254.467762533835,
1127.2338812669175,
563.616940
};
private static final int levels = 21;
private static final int dpi = 96;
private static final int tileWidth = 256;
private static final int tileHeight = 256;
private ResponseListener responseListener;
private TianDiTuLayerTypes _mapType;
private TileInfo tiandituTileInfo;
public TianDiTuTiledMapServiceLayer() {
this(null, null, true);
}
public TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType mapType) {
public TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes mapType) {
this(mapType, null, true);
GADBHelper.createTable(AppInfo.mapcachedb, _mapType.getName());
}
public TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType mapType, UserCredentials usercredentials) {
public TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes mapType, UserCredentials usercredentials) {
this(mapType, usercredentials, true);
}
public TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType mapType, UserCredentials usercredentials, boolean flag) {
public TianDiTuTiledMapServiceLayer(TianDiTuLayerTypes mapType, UserCredentials usercredentials, boolean flag) {
super("");
this._mapType = mapType;
setCredentials(usercredentials);
......@@ -54,6 +112,7 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
}
final TianDiTuTiledMapServiceLayer a;
{
a = TianDiTuTiledMapServiceLayer.this;
//super();
......@@ -64,13 +123,17 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
}
}
public static double[] getRes() {
return res;
}
public TianDiTuTiledMapServiceType getMapType() {
public TianDiTuLayerTypes getMapType() {
return this._mapType;
}
protected void initLayer() {
this.buildTileInfo();
this.tiandituTileInfo = new com.esri.android.map.TiledServiceLayer.TileInfo(originalPoint, scale, res, levels, dpi, tileWidth, tileHeight);
this.setTileInfo(this.tiandituTileInfo);
this.setFullExtent(new Envelope(-180, -90, 180, 90));
this.setDefaultSpatialReference(SpatialReference.create(4490)); //CGCS2000
//this.setDefaultSpatialReference(SpatialReference.create(4326));
......@@ -114,35 +177,34 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
@Override
protected byte[] getTile(int level, int col, int row) throws Exception {
byte[] result = null;
StringBuilder url = new StringBuilder("http://t");
Random random = new Random();
int subdomain = (random.nextInt(6) + 1);
url.append(subdomain);
switch (this._mapType) {
case VEC_C:
url.append(".tianditu.com/DataServer?T=vec_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
case CVA_C:
url.append(".tianditu.com/DataServer?T=cva_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
case CIA_C:
url.append(".tianditu.com/DataServer?T=cia_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
case IMG_C:
url.append(".tianditu.com/DataServer?T=img_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
default:
return null;
}
try {
// 首先从离线数据库中读取
result = getOfflineCacheDB(level, col, row);
// 如果没有就直接从web上读取
if (result == null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
URL sjwurl = new URL(this.getTianDiMapUrl(level, col, row));
HttpURLConnection httpUrl = null;
BufferedInputStream bis = null;
byte[] buf = new byte[1024];
httpUrl = (HttpURLConnection) sjwurl.openConnection();
httpUrl.connect();
bis = new BufferedInputStream(httpUrl.getInputStream());
while (true) {
int bytes_read = bis.read(buf);
if (bytes_read > 0) {
bos.write(buf, 0, bytes_read);
} else {
break;
}
}
;
bis.close();
httpUrl.disconnect();
result = bos.toByteArray();
result = com.esri.core.internal.io.handler.a.a(url.toString(), null, null, this.responseListener);
// 将读取的数据存入mbtiles中
AddOfflineCacheDB(level, col, row, result);
}
......@@ -153,7 +215,7 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
return result;
}
private void AddOfflineCacheDB(int level, int col, int row, byte[] bytes){
private void AddOfflineCacheDB(int level, int col, int row, byte[] bytes) {
ContentValues values = new ContentValues();
values.put("TILELEVEL", level);
values.put("TILECOL", col);
......@@ -193,68 +255,5 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
return this.tiandituTileInfo;
}
/**
*
* */
private String getTianDiMapUrl(int level, int col, int row) {
String url = new TDTUrl(level, col, row, this._mapType).generatUrl();
return url;
}
private void buildTileInfo() {
Point originalPoint = new Point(-180, 90);
double[] res = {
1.40625,
0.703125,
0.3515625,
0.17578125,
0.087890625,
0.0439453125,
0.02197265625,
0.010986328125,
0.0054931640625,
0.00274658203125,
0.001373291015625,
0.0006866455078125,
0.00034332275390625,
0.000171661376953125,
8.58306884765629E-05,
4.29153442382814E-05,
2.14576721191407E-05,
1.07288360595703E-05,
5.36441802978515E-06,
2.68220901489258E-06,
1.34110450744629E-06
};
double[] scale = {
400000000,
295497598.5708346,
147748799.285417,
73874399.6427087,
36937199.8213544,
18468599.9106772,
9234299.95533859,
4617149.97766929,
2308574.98883465,
1154287.49441732,
577143.747208662,
288571.873604331,
144285.936802165,
72142.9684010827,
36071.4842005414,
18035.7421002707,
9017.87105013534,
4508.93552506767,
2254.467762533835,
1127.2338812669175,
563.616940
};
int levels = 21;
int dpi = 96;
int tileWidth = 256;
int tileHeight = 256;
this.tiandituTileInfo = new com.esri.android.map.TiledServiceLayer.TileInfo(originalPoint, scale, res, levels, dpi, tileWidth, tileHeight);
this.setTileInfo(this.tiandituTileInfo);
}
}
......
......@@ -21,8 +21,8 @@ public class AppInfo {
public static Point initPoint = new Point(121.56, 29.862149);
// public static double initRes = TDTTileinfo.getRes4490()[6];
public static double initRes = TDTTileinfo.getRes4326()[6];
public static double initRes = TDTTileinfo.getRes4490()[6];
// public static double initRes = TDTTileinfo.getRes4326()[6];
public static void Settings(){
......
......@@ -55,8 +55,7 @@ public class GADBHelper extends SQLiteOpenHelper {
"(TILELEVEL INT," +
"TILECOL INT," +
"TILEROW INT," +
"TILEDATA BLOB," +
"TILETIME TEXT)");
"TILEDATA BLOB)");
db.setTransactionSuccessful();
db.endTransaction();
......
package com.pashanhoo.landsurvey.utils;
import com.esri.core.geometry.Point;
/**
* Created by jiangbotao on 2018/3/28.
*/
public class JZLocationConverter {
private static final double LAT_OFFSET_0(double x, double y) {
return -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
}
private static final double LAT_OFFSET_1(double x, double y) {
return (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
}
private static final double LAT_OFFSET_2(double x, double y) {
return (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0;
}
private static final double LAT_OFFSET_3(double x, double y) {
return (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0;
}
private static final double LON_OFFSET_0(double x, double y) {
return 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
}
private static final double LON_OFFSET_1(double x, double y) {
return (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
}
private static final double LON_OFFSET_2(double x, double y) {
return (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0;
}
private static final double LON_OFFSET_3(double x, double y) {
return (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x / 30.0 * Math.PI)) * 2.0 / 3.0;
}
private static double RANGE_LON_MAX = 137.8347;
private static double RANGE_LON_MIN = 72.004;
private static double RANGE_LAT_MAX = 55.8271;
private static double RANGE_LAT_MIN = 0.8293;
private static double jzA = 6378245.0;
private static double jzEE = 0.00669342162296594323;
public static double transformLat(double x, double y) {
double ret = LAT_OFFSET_0(x, y);
ret += LAT_OFFSET_1(x, y);
ret += LAT_OFFSET_2(x, y);
ret += LAT_OFFSET_3(x, y);
return ret;
}
public static double transformLon(double x, double y) {
double ret = LON_OFFSET_0(x, y);
ret += LON_OFFSET_1(x, y);
ret += LON_OFFSET_2(x, y);
ret += LON_OFFSET_3(x, y);
return ret;
}
public static boolean outOfChina(double lat, double lon) {
if (lon < RANGE_LON_MIN || lon > RANGE_LON_MAX)
return true;
if (lat < RANGE_LAT_MIN || lat > RANGE_LAT_MAX)
return true;
return false;
}
public static Point gcj02Encrypt(double ggLat, double ggLon) {
Point resPoint = new Point();
double mgLat;
double mgLon;
if (outOfChina(ggLat, ggLon)) {
resPoint.setY(ggLat);
resPoint.setX(ggLon);
return resPoint;
}
double dLat = transformLat(ggLon - 105.0, ggLat - 35.0);
double dLon = transformLon(ggLon - 105.0, ggLat - 35.0);
double radLat = ggLat / 180.0 * Math.PI;
double magic = Math.sin(radLat);
magic = 1 - jzEE * magic * magic;
double sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((jzA * (1 - jzEE)) / (magic * sqrtMagic) * Math.PI);
dLon = (dLon * 180.0) / (jzA / sqrtMagic * Math.cos(radLat) * Math.PI);
mgLat = ggLat + dLat;
mgLon = ggLon + dLon;
resPoint.setY(mgLat);
resPoint.setX(mgLon);
return resPoint;
}
public static Point gcj02Decrypt(double gjLat, double gjLon) {
Point gPt = gcj02Encrypt(gjLat, gjLon);
double dLon = gPt.getX() - gjLon;
double dLat = gPt.getY() - gjLat;
Point pt = new Point();
pt.setY(gjLat - dLat);
pt.setX(gjLon - dLon);
return pt;
}
public static Point bd09Decrypt(double bdLat, double bdLon) {
Point gcjPt = new Point();
double x = bdLon - 0.0065, y = bdLat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * Math.PI);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * Math.PI);
gcjPt.setX(z * Math.cos(theta));
gcjPt.setY(z * Math.sin(theta));
return gcjPt;
}
public static Point bd09Encrypt(double ggLat, double ggLon) {
Point bdPt = new Point();
double x = ggLon, y = ggLat;
double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * Math.PI);
double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * Math.PI);
bdPt.setX(z * Math.cos(theta) + 0.0065);
bdPt.setY(z * Math.sin(theta) + 0.006);
return bdPt;
}
/**
* @param location 世界标准地理坐标(WGS-84)
* @return 中国国测局地理坐标(GCJ-02)<火星坐标>
* @brief 世界标准地理坐标(WGS-84) 转换成 中国国测局地理坐标(GCJ-02)<火星坐标>
*
* ####只在中国大陆的范围的坐标有效,以外直接返回世界标准坐标
*/
public static Point wgs84ToGcj02(Point location) {
return gcj02Encrypt(location.getY(), location.getX());
}
/**
* @param location 中国国测局地理坐标(GCJ-02)
* @return 世界标准地理坐标(WGS-84)
* @brief 中国国测局地理坐标(GCJ-02) 转换成 世界标准地理坐标(WGS-84)
*
* ####此接口有1-2米左右的误差,需要精确定位情景慎用
*/
public static Point gcj02ToWgs84(Point location) {
return gcj02Decrypt(location.getY(), location.getX());
}
/**
* @param location 世界标准地理坐标(WGS-84)
* @return 百度地理坐标(BD-09)
* @brief 世界标准地理坐标(WGS-84) 转换成 百度地理坐标(BD-09)
*/
public static Point wgs84ToBd09(Point location) {
Point gcj02Pt = gcj02Encrypt(location.getY(), location.getX());
return bd09Encrypt(gcj02Pt.getY(), gcj02Pt.getX());
}
/**
* @param location 中国国测局地理坐标(GCJ-02)<火星坐标>
* @return 百度地理坐标(BD-09)
* @brief 中国国测局地理坐标(GCJ-02)<火星坐标> 转换成 百度地理坐标(BD-09)
*/
public static Point gcj02ToBd09(Point location) {
return bd09Encrypt(location.getY(), location.getX());
}
/**
* @param location 百度地理坐标(BD-09)
* @return 中国国测局地理坐标(GCJ-02)<火星坐标>
* @brief 百度地理坐标(BD-09) 转换成 中国国测局地理坐标(GCJ-02)<火星坐标>
*/
public static Point bd09ToGcj02(Point location) {
return bd09Decrypt(location.getY(), location.getX());
}
/**
* @param location 百度地理坐标(BD-09)
* @return 世界标准地理坐标(WGS-84)
* @brief 百度地理坐标(BD-09) 转换成 世界标准地理坐标(WGS-84)
*
* ####此接口有1-2米左右的误差,需要精确定位情景慎用
*/
public static Point bd09ToWgs84(Point location) {
Point gcj02 = bd09ToGcj02(location);
return gcj02Decrypt(gcj02.getY(), gcj02.getX());
}
}
......@@ -28,4 +28,5 @@
android:layout_marginLeft="0dp"
app:srcCompat="@mipmap/ic_my_location_white_48dp" />
</android.support.v7.widget.LinearLayoutCompat>
</android.support.constraint.ConstraintLayout>
......