forked from Esri/arcgis-runtime-samples-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Esri#541 from Esri/trev8939/prepDevelopFor100.4Rel…
…ease Trev8939/prep develop for100.4 release
- Loading branch information
Showing
87 changed files
with
2,544 additions
and
979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Display KML | ||
Display a KML layer from a URL, portal item, or local KML file. | ||
|
||
![Display KML App](display-kml.png) | ||
|
||
## How to use the sample | ||
Select the KML layer you'd like to display from the dropdown menu in the upper right. | ||
|
||
Before attempting to load a KML file from local storage, the file will have to be sideloaded onto the device. See [Offline Data](#offline-data). | ||
|
||
## How it works | ||
1. To create a KML layer from a URL, create a `KMLDataset` using the URL to the KML file. Then pass the data set to the `KmlLayer` constructor. | ||
2. To create a KML layer from a portal item, construct a `PortalItem` with a portal and the KML portal item. Pass the portal item to the `KmlLayer` constructor. | ||
1. To create a KML layer from a local file, create a `KMLDataset` using a path to the local KML file in external storage. Then pass the data set to the `KmlLayer` constructor. | ||
1. Add the layer as an operational layer to the map with `map.getOperationalLayers().add(kmlLayer)`. | ||
|
||
## Relevant API | ||
* KmlDataset | ||
* KmlLayer | ||
* Portal | ||
* PortalItem | ||
|
||
## Offline Data | ||
1. Download the data from [ArcGIS Online](https://arcgisruntime.maps.arcgis.com/home/item.html?id=324e4742820e46cfbe5029ff2c32cb1f). | ||
1. Extract the contents of the downloaded zip file to disk. | ||
1. Open your command prompt and navigate to the folder where you extracted the contents of the data from step 1. | ||
1. Execute the following command: | ||
`adb push US_State_Capitals.kml /sdcard/ArcGIS/Samples/KML/US_State_Capitals.kml` | ||
|
||
|
||
Link | Local Location | ||
---------|-------| | ||
|[US State Capitals KML](https://arcgisruntime.maps.arcgis.com/home/item.html?id=324e4742820e46cfbe5029ff2c32cb1f)| `<sdcard>`/ArcGIS/Samples/KML/US_State_Capitals.kml| | ||
|
||
#### Tags | ||
Layers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
applicationId "com.esri.arcgisruntime.sample.displaykml" | ||
minSdkVersion rootProject.ext.minSdkVersion | ||
targetSdkVersion rootProject.ext.targetSdkVersion | ||
versionCode rootProject.ext.versionCode | ||
versionName rootProject.ext.versionName | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
targetCompatibility rootProject.ext.targetJavaVersion | ||
sourceCompatibility rootProject.ext.sourceJavaVersion | ||
} | ||
} | ||
|
||
dependencies { | ||
// arcgis-android & appcompat lib dependencies from rootProject build.gradle | ||
implementation "com.android.support.constraint:constraint-layout:$constraintLayoutVersion" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.esri.arcgisruntime.displaykml"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
|
||
<uses-feature | ||
android:glEsVersion="0x00020000" | ||
android:required="true" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
214 changes: 214 additions & 0 deletions
214
java/display-kml/src/main/java/com/esri/arcgisruntime/displaykml/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
/* Copyright 2018 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.esri.arcgisruntime.displaykml; | ||
|
||
import android.Manifest; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuInflater; | ||
import android.view.MenuItem; | ||
import android.widget.Toast; | ||
|
||
import com.esri.arcgisruntime.layers.KmlLayer; | ||
import com.esri.arcgisruntime.loadable.LoadStatus; | ||
import com.esri.arcgisruntime.mapping.ArcGISMap; | ||
import com.esri.arcgisruntime.mapping.Basemap; | ||
import com.esri.arcgisruntime.mapping.view.MapView; | ||
import com.esri.arcgisruntime.ogc.kml.KmlDataset; | ||
import com.esri.arcgisruntime.portal.Portal; | ||
import com.esri.arcgisruntime.portal.PortalItem; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = MainActivity.class.getSimpleName(); | ||
|
||
private MapView mMapView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
// get the reference to the map view | ||
mMapView = findViewById(R.id.mapView); | ||
|
||
// create a map with the dark gray canvas basemap | ||
ArcGISMap map = new ArcGISMap(Basemap.Type.DARK_GRAY_CANVAS_VECTOR, 39, -98, 4); | ||
|
||
// set the map to the map view | ||
mMapView.setMap(map); | ||
|
||
requestReadPermission(); | ||
} | ||
|
||
/** | ||
* Clear all operational layers and add the kml layer to the map as an operational layer. | ||
* | ||
* @param kmlLayer to add to the map | ||
*/ | ||
private void display(KmlLayer kmlLayer) { | ||
// clear the existing layers from the map | ||
mMapView.getMap().getOperationalLayers().clear(); | ||
|
||
// add the KML layer to the map | ||
mMapView.getMap().getOperationalLayers().add(kmlLayer); | ||
} | ||
|
||
/** | ||
* Display a kml layer from a URL. | ||
*/ | ||
private void changeSourceToURL() { | ||
// create a kml data set from a URL | ||
KmlDataset kmlDataset = new KmlDataset(getString(R.string.kml_url)); | ||
|
||
// a KML layer created from a remote KML file | ||
KmlLayer kmlLayer = new KmlLayer(kmlDataset); | ||
display(kmlLayer); | ||
|
||
// report errors if failed to load | ||
kmlDataset.addDoneLoadingListener(() -> { | ||
if (kmlDataset.getLoadStatus() != LoadStatus.LOADED) { | ||
String error = "Failed to load kml layer from URL: " + kmlDataset.getLoadError().getMessage(); | ||
Toast.makeText(this, error, Toast.LENGTH_LONG).show(); | ||
Log.e(TAG, error); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Display a kml layer from a portal item. | ||
*/ | ||
private void changeSourceToPortalItem() { | ||
// create a portal to ArcGIS Online | ||
Portal portal = new Portal(getString(R.string.arcgis_online_url)); | ||
|
||
// create a portal item from a kml item id | ||
PortalItem portalItem = new PortalItem(portal, getString(R.string.kml_item_id)); | ||
|
||
// a KML layer created from an ArcGIS Online portal item | ||
KmlLayer kmlLayer = new KmlLayer(portalItem); | ||
display(kmlLayer); | ||
|
||
// report errors if failed to load | ||
kmlLayer.addDoneLoadingListener(() -> { | ||
if (kmlLayer.getLoadStatus() != LoadStatus.LOADED) { | ||
String error = "Failed to load kml layer from portal item: " + kmlLayer.getLoadError().getCause().getMessage(); | ||
Toast.makeText(this, error, Toast.LENGTH_LONG).show(); | ||
Log.e(TAG, error); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Display a kml layer from external storage. | ||
*/ | ||
private void changeSourceToFileExternalStorage() { | ||
// a data set made from data in external storage | ||
KmlDataset kmlDataset = new KmlDataset(Environment.getExternalStorageDirectory() + getString(R.string.kml_path)); | ||
|
||
// a KML layer created from a local KML file | ||
KmlLayer kmlLayer = new KmlLayer(kmlDataset); | ||
display(kmlLayer); | ||
|
||
// report errors if failed to load | ||
kmlDataset.addDoneLoadingListener(() -> { | ||
if (kmlDataset.getLoadStatus() != LoadStatus.LOADED) { | ||
String error = | ||
"Failed to load kml data set from external storage: " + kmlDataset.getLoadError().getCause().getMessage(); | ||
Toast.makeText(this, error, Toast.LENGTH_LONG).show(); | ||
Log.e(TAG, error); | ||
} | ||
}); | ||
} | ||
|
||
@Override public boolean onCreateOptionsMenu(Menu menu) { | ||
MenuInflater inflater = getMenuInflater(); | ||
inflater.inflate(R.menu.kml_sources, menu); | ||
return super.onCreateOptionsMenu(menu); | ||
} | ||
|
||
@Override public boolean onOptionsItemSelected(MenuItem item) { | ||
int i = item.getItemId(); | ||
if (i == R.id.kmlFromUrl) { | ||
changeSourceToURL(); | ||
} else if (i == R.id.kmlFromPortal) { | ||
changeSourceToPortalItem(); | ||
} else if (i == R.id.kmlFromExternalStorage) { | ||
changeSourceToFileExternalStorage(); | ||
} else { | ||
Log.e(TAG, "Menu option not implemented"); | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
/** | ||
* Request read external storage for API level 23+. | ||
*/ | ||
private void requestReadPermission() { | ||
// define permission to request | ||
String[] reqPermission = { Manifest.permission.READ_EXTERNAL_STORAGE }; | ||
int requestCode = 2; | ||
if (ContextCompat.checkSelfPermission(this, reqPermission[0]) == PackageManager.PERMISSION_GRANTED) { | ||
// set initial KML to URL | ||
changeSourceToURL(); | ||
} else { | ||
// request permission | ||
ActivityCompat.requestPermissions(this, reqPermission, requestCode); | ||
} | ||
} | ||
|
||
/** | ||
* Handle the permissions request response. | ||
*/ | ||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
// set initial KML to URL | ||
changeSourceToURL(); | ||
} else { | ||
// report to user that permission was denied | ||
Toast.makeText(this, getString(R.string.kml_read_permission_denied), Toast.LENGTH_SHORT).show(); | ||
} | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
mMapView.pause(); | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mMapView.resume(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
mMapView.dispose(); | ||
super.onDestroy(); | ||
} | ||
} | ||
|
Oops, something went wrong.