315122b8 by chiangbt

update 3.26

1 parent b9cc8134
......@@ -10,6 +10,7 @@ import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
......@@ -35,12 +36,15 @@ public class MainActivity extends AppCompatActivity {
private TianDiTuLocalTiledMapServiceLayer t_local;
private String mapType;
private TextView mapinfoView;
private int curLevel = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
mapinfoView = (TextView)findViewById(R.id.mapinfo);
setSupportActionBar(toolbar);
//初始化-------------------------------------------------------------------
AppInfo.Settings();
......@@ -52,7 +56,9 @@ public class MainActivity extends AppCompatActivity {
if(locationDisplayManager!=null){
locationDisplayManager.stop();
}
mapView.zoomin(true);
if(curLevel < 19) {
mapView.zoomin(true);
}
}
});
FloatingActionButton zoomout = (FloatingActionButton) findViewById(R.id.zoomout);
......@@ -62,7 +68,9 @@ public class MainActivity extends AppCompatActivity {
if(locationDisplayManager!=null){
locationDisplayManager.stop();
}
mapView.zoomout(true);
if(curLevel > 0) {
mapView.zoomout(true);
}
}
});
FloatingActionButton fullmap = (FloatingActionButton) findViewById(R.id.fullmap);
......@@ -116,6 +124,8 @@ public class MainActivity extends AppCompatActivity {
public void onStatusChanged(Object o, STATUS status) {
if(status == STATUS.INITIALIZED){
mapView.zoomToResolution(AppInfo.initPoint, AppInfo.initRes);
curLevel= TDTTileinfo.getCurrentLevel(AppInfo.initRes);
mapinfoView.setText("当前地图级别为:"+ String.valueOf(curLevel));
}
}
});
......@@ -126,10 +136,13 @@ public class MainActivity extends AppCompatActivity {
@Override
public void postAction(float v, float v1, double v2) {
Log.i("map", String.valueOf(TDTTileinfo.getCurrentLevel(mapView.getResolution())));
int level = TDTTileinfo.getCurrentLevel(mapView.getResolution());
if(level > 7 || level < 10){
t_local.clearTiles();
curLevel = TDTTileinfo.getCurrentLevel(mapView.getResolution());
mapinfoView.setText("当前地图级别为:"+ String.valueOf(curLevel));
// t_local只有8和9级数据
if(curLevel > 9 | curLevel <8){
t_local.setVisible(false);
}else{
t_local.setVisible(true);
}
}
});
......
package com.pashanhoo.landsurvey.layers.tianditu;
import android.util.Log;
import com.esri.core.geometry.Point;
/**
......@@ -144,7 +146,7 @@ public class TDTTileinfo {
public static int getCurrentLevel(double resolution){
for(int i=0; i< res4490.length;i++){
if((res4490[i] -resolution)<0.001){
if((res4490[i] -resolution)<0.00000001){
return i;
}
}
......
......@@ -24,14 +24,15 @@ import java.util.concurrent.RejectedExecutionException;
public class TianDiTuLocalTiledMapServiceLayer extends TiledServiceLayer {
String sqlitedb = "";
private TileInfo tiandituTileInfo;
private String layername = "";
private SQLiteDatabase sqLiteDatabase;
public TianDiTuLocalTiledMapServiceLayer(String url, String layername) {
super(url);
this.sqlitedb = url;
public TianDiTuLocalTiledMapServiceLayer(String dbname, String layername) {
super(dbname);
this.layername = layername;
this.sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(Environment.getExternalStorageDirectory()+"/keymapinfo/" + dbname,
null);
try {
getServiceExecutor().submit(new Runnable() {
......@@ -67,40 +68,27 @@ public class TianDiTuLocalTiledMapServiceLayer extends TiledServiceLayer {
protected byte[] getTile(int level, int col, int row) throws Exception {
byte[] result = null;
try{
result = getOfflineCacheDB(level, col, row);
}catch (Exception ex) {
ex.printStackTrace();
}
String sql = "SELECT * FROM " + this.layername + " where TILELEVEL = " + level + " and TILECOL = " + col + " and TILEROW = " + row;
Cursor mCursor = this.sqLiteDatabase.rawQuery(sql, null);
boolean hasData = false;
return result;
}
private byte[] getOfflineCacheDB(int level, int col, int row) throws Exception {
byte[] result = null;
// Log.i("local", level + ":"+ col + ":" + row);
// row = (int) (Math.pow(2, level) - col - row);
String sql = "select * from " + this.layername + " where TILELEVEL = " + level + " and TILECOL = " + col + " and TILEROW = " + row;
Cursor mCursor =
SQLiteDatabase.openOrCreateDatabase(Environment.getExternalStorageDirectory()+"/keymapinfo/" + this.sqlitedb, null)
.rawQuery(sql, null);
boolean hasData = false;
while (mCursor.moveToNext()) {//判断是否存在数据
hasData = true;
}
if (hasData) {//数据库中有数据
try {
if (mCursor.moveToFirst()) {
result = mCursor.getBlob(mCursor.getColumnIndex("TILEDATA"));
while (mCursor.moveToNext()) {//判断是否存在数据
hasData = true;
}
if (hasData) {//数据库中有数据
try {
if (mCursor.moveToFirst()) {
result = mCursor.getBlob(mCursor.getColumnIndex("TILEDATA"));
}
mCursor.close();
} catch (Exception e) {
result = null;
}
mCursor.close();
} catch (Exception e) {
e.printStackTrace();
result = null;
}
}catch (Exception ex) {
result = null;
}
return result;
}
......
......@@ -64,5 +64,20 @@
app:srcCompat="@mipmap/ic_home_white_48dp" />
</android.support.v7.widget.LinearLayoutCompat>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|left">
<TextView
android:id="@+id/mapinfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:text="地图信息" />
</android.support.v7.widget.LinearLayoutCompat>
</android.support.design.widget.CoordinatorLayout>
......