package com.linksoon.ocean.offline;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISLocalTiledLayer;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.map.CallbackListener;
import com.esri.core.tasks.tilecache.ExportTileCacheParameters;
import com.esri.core.tasks.tilecache.ExportTileCacheParameters.ExportBy;
import com.esri.core.tasks.tilecache.ExportTileCacheStatus;
import com.esri.core.tasks.tilecache.ExportTileCacheTask;
public class MainActivity extends AppCompatActivity {
static final String TAG = "ExportTileCacheTaskSampleActivity";
// Map elements
MapView mMapView;
ArcGISLocalTiledLayer localTiledLayer;
// action bar menu items
MenuItem selectLevels;
MenuItem download;
MenuItem switchMaps;
boolean isLocalLayerVisible = false;
// The generated tile cache will be a compact cache
boolean createAsTilePackage = false;
double[] levels;
final CharSequence[] items = { "Level ID:0", "Level ID:1", "Level ID:2",
"Level ID:3", "Level ID:4", "Level ID:5", "Level ID:6",
"Level ID:7", "Level ID:8", "Level ID:9", };
double[] mapResolution = { 156543.03392800014, 78271.51696399994,
39135.75848200009, 19567.87924099992, 9783.93962049996,
4891.96981024998, 2445.98490512499, 1222.992452562495,
611.4962262813797, 305.74811314055756 };
boolean[] itemsChecked = new boolean[items.length];
ArrayList<Double> levelsArraylist = new ArrayList<Double>();
// path to persist data to disk
public static String DEFAULT_BASEMAP_PATH;
public static Context context;
// tile package url
String tileURL;
public static String defaultPath = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
DEFAULT_BASEMAP_PATH = getResources().getString(R.string.offline_dir);
defaultPath = Environment.getExternalStorageDirectory().getPath()
+ DEFAULT_BASEMAP_PATH;
// Initialize MapView and extent
mMapView = (MapView) findViewById(R.id.mapView);
context=this;
// Add Tile layer to the MapView
tileURL = getResources().getString(R.string.tileServiceURL);
ArcGISTiledMapServiceLayer tilelayer = new ArcGISTiledMapServiceLayer(
tileURL);
//mMapView.addLayer(tilelayer);
GoogleMapLayer googleLayer = new GoogleMapLayer(GoogleMapLayerTypes.IMAGE_GOOGLE_MAP);
mMapView.addLayer(googleLayer);
Button zI =(Button)findViewById(R.id.zoomIn);
zI.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMapView.zoomin();
}
});
Button zO =(Button)findViewById(R.id.zoomOut);
zO.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMapView.zoomout();
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
// menu items
selectLevels = menu.getItem(0);
selectLevels.setIcon(android.R.drawable.ic_menu_crop);
download = menu.getItem(1);
switchMaps = menu.getItem(2);
return super.onCreateOptionsMenu(menu);
}
public static boolean isConnect(){
//Context context=App.getInstance();
ConnectivityManager cwjManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cwjManager.getActiveNetworkInfo();
if (info != null && info.isAvailable()){
return true;
}
else
{
return false;
}
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.select_levels:
showDialog();
return true;
case R.id.download:
downloadBasemap();
return true;
case R.id.switch_maps:
if (isLocalLayerVisible) {
switchToOnlineLayer();
} else {
switchToLocalLayer();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/**
* Launches the dialog to let the user select the Levels of Detail to be
* downloaded from the tile service. Called when selectLevels action bar
* icon is selected.
*
**/
public void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select the Levels of Detail");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// When ok button is pressed, we go through the array of
// itemsChecked and add the selected
// items to levelsArraylist
for (int i = 0; i < items.length; i++) {
if (itemsChecked[i]) {
levelsArraylist.add((double) i);
itemsChecked[i] = false;
}
}
}
});
builder.setMultiChoiceItems(items, new boolean[] { false, false, false,
false, false, false, false, false, false, false },
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
itemsChecked[which] = isChecked;
}
});
builder.show();
}
/**
* Download the basemap for the level of details selected by the user Called
* when download button is clicked.
*
*/
@SuppressWarnings("boxing")
public void downloadBasemap() {
// Set the progressbar to VISIBLE
setProgressBarIndeterminateVisibility(true);
// Get the the extent covered by generated tile cache, here we are using
// the area being displayed on screen
Envelope extentForTPK = new Envelope();
mMapView.getExtent().queryEnvelope(extentForTPK);
// If the user does not select the Level of details
// then give out the status message in a toast
if (levelsArraylist.size() == 0) {
Toast.makeText(this, "Please Select Levels of Detail",
Toast.LENGTH_LONG).show();
// Hide the progress bar
setProgressBarIndeterminateVisibility(false);
return;
}
levels = new double[levelsArraylist.size()];
final String tileCachePath = def
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用ArcGIS for Android开发的加载GoogleMap地图。并判断无网络时自动加载本地图片。图片存放在/ArcGIS/samples/tiledcache/下。在有网络时自动存储地图图片。未做容量控制及清空策略。并集成了从ArcGIS Server缓存图片的例子。
资源推荐
资源详情
资源评论
收起资源包目录
OfflineMap.rar (64个子文件)
OfflineMap
gradlew 5KB
settings.gradle 16B
OfflineMap.iml 941B
.idea
libraries
junit_4_12.xml 477B
hamcrest_core_1_3.xml 526B
support_vector_drawable_23_4_0.xml 640B
arcgis_android_10_2_8.xml 1KB
support_v4_23_4_0.xml 903B
appcompat_v7_23_4_0.xml 761B
animated_vector_drawable_23_4_0.xml 645B
support_annotations_23_4_0.xml 495B
runConfigurations.xml 564B
misc.xml 2KB
compiler.xml 686B
workspace.xml 175KB
gradle.xml 819B
.name 7B
encodings.xml 159B
modules.xml 357B
copyright
profiles_settings.xml 76B
build
intermediates
dex-cache
cache.xml 64B
generated
mockable-android-23.jar 22.2MB
gradle
wrapper
gradle-wrapper.properties 231B
gradle-wrapper.jar 52KB
.gradle
2.10
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 20KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.bin 55KB
localClassSetAnalysis.lock 17B
taskArtifacts
cache.properties.lock 17B
fileHashes.bin 141KB
outputFileStates.bin 20KB
taskArtifacts.bin 113KB
fileSnapshots.bin 2.81MB
cache.properties 31B
local.properties 428B
gradlew.bat 2KB
gradle.properties 872B
.gitignore 105B
app
src
androidTest
java
com
linksoon
ocean
offline
ApplicationTest.java 369B
test
java
com
linksoon
ocean
offline
ExampleUnitTest.java 333B
main
AndroidManifest.xml 1KB
res
mipmap-hdpi
ic_launcher.png 3KB
mipmap-xxxhdpi
ic_launcher.png 10KB
mipmap-xhdpi
ic_launcher.png 5KB
menu
menu.xml 571B
mipmap-mdpi
ic_launcher.png 2KB
drawable
ic_download.png 1KB
layout
levels.xml 4KB
activity_main.xml 2KB
values-w820dp
dimens.xml 364B
values
colors.xml 214B
strings.xml 564B
styles.xml 394B
dimens.xml 216B
mipmap-xxhdpi
ic_launcher.png 8KB
java
com
linksoon
ocean
offline
App.java 421B
GoogleMapLayerTypes.java 422B
MainActivity.java 15KB
GoogleMapLayer.java 7KB
build
intermediates
generated
source
buildConfig
androidTest
debug
com
linksoon
ocean
offline
test
assets
shaders
androidTest
outputs
logs
apk
libs
app.iml 10KB
.gitignore 8B
build.gradle 851B
proguard-rules.pro 662B
build.gradle 600B
共 64 条
- 1
Tangel0904
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- libjpeg 编译所需的 Win32.mak vs编译libjpeg
- 自动驾驶-状态估计和定位-粒子滤波实现和源码.pdf
- 数据可视化-智慧物流服务中心大屏页面.zip
- yolov5,SSD 可能使用到的一些代码
- bbbbbbbbbbbbbbbbbb
- 安卓逆向学习笔记之Frida Stalker 还原OLLVM AES.docx
- 安卓逆向学习笔记之unicorn来trace还原OLLVM Base64.docx
- 基于jquery的自定义表格组件实现
- Nessus最新20240426离线安装插件all-2.0.tar.gz
- 最新版本私钥助记词碰撞器大富豪使用python进行制作通过接口的方式进行验证支持多币种多链多网络一分钟万次验证高出货率
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页