You are on page 1of 54

ESRI

ArcGIS API for Android

2011/2/22

Windows 7 + ArcGIS Server 10 + ArcGIS API for Android 1.0 beta


I.

................................................................................ 3
Android .......................................................................... 3
ArcGIS ........................................................................... 6

II. ................................................................................ 8
Hello World .............................................................. 8
Android .............................................................. 9
ArcGIS Android ....................................................... 13
III.

MapView ......................................................................... 18
........................................................................ 18
........................................................................... 21

IV.

.............................................................................. 25
........................................................................... 25
.................................................................. 28

V. ................................................................................. 33
..................................................................... 33
................................................................................... 35
VI.

............................................................. 37
........................................................................... 37
.............................................................................. 39

VII. ................................................................................. 42
Feature Layer ........................................................................... 42
1

................................................................................... 44
................................................................................... 45
VIII. Android ............................................................ 51
................................................................................... 51
IX.

...................................................................................... 53
................................................................................ 53

I.
ArcGIS API for Android ArcGIS Android API
Android +ArcGIS Android Eclipse
Eclipse

Android 1
Android Eclipse ArcGIS Android API Eclipse
3.5(Galileo) 3.6(Helios) Android

JDK6 Eclipse(3.5/3.6http://www.eclipse.org/downloads/
Classic 3.5 ,3.6 )
Eclipse Android SDKAndroid SDK
http://androidappdocs.appspot.com/sdk/index.html
Android SDK
D:\Software\Develop\Android\android-sdk-windows
Eclipse Android SDK Eclipse
Android SDK Eclipse Android
Eclipse Android Development ToolADT
Android https://dl-ssl.google.com/android/eclipse/
Eclipse Help->Install New Software

http://androidappdocs.appspot.com/sdk/installing.html
3

1 Eclipse ADT

Eclipse Window->References
Eclipse Android Android SDK
Eclipse ADT Android SDK
D:\Software\Develop\Android\android-sdk-windows

2 ADT Android SDK

Android Android
2.1 Android 2.2 Eclipse
Android SDK SDK Manager
Window->Android SDK and AVD Manager
2

3 Android

AVDAndroid Virtual Devices


5

ArcGIS
Android ArcGIS
Eclipse Android 2.1 2.1
ArcGIS Android API 3
Esri
http://downloads.esri.com/software/arcgis/android
ArcGIS Eclipse Help->Install New Software

5 ArcGIS

http://help.arcgis.com/en/arcgismobile/10.0/apis/android/help/#/System_requirements/0
11900000004000000/
6

ArcGIS ArcGIS
Project for AndroidArcGIS Samples for AndroidArcGIS Android
API

6 ArcGIS Android API

II.
ArcGIS Android API ArcGIS Server
REST ArcGIS Server REST
ArcGIS JavaScript APIFlex APISilverlight APIWindows Phone API
ArcGIS Server REST
ArcGIS Server
REST ArcGIS Server
ArcGIS Server REST

ArcGIS Android API Hello World API

Hello World
ArcGIS Android API Hello
World Eclipse File->New->ArcGIS
Samples for Android

8 Hello World

8
AgsSampleHelloWorldHello World
ArcGIS
Android

Android

9 Hello World
9

Eclipse AgsSampleHelloWorld 9
srcHelloWorld.java
Java Android Linux
Android Java Java
Linux Dalvik4
default.properties
AndroidManifest.xml
default.properties

target=android-8

Android android-8
Android 2.2

10 Android API

AndroidManifest.xml Android

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.esri.arcgis.android.samples"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">

http://zh.wikipedia.org/zh-cn/Dalvik
10

<activity android:name=".HelloWorld"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-sdk android:minSdkVersion="7" />
</manifest>

<user-permission>
AgsSampleHelloWorld
Internet
android.permission.INTERNET
Android Internet

Android Android Manifest Editor


11

11 Android
11

<application>
<application>
<application android:icon="@drawable/icon" android:label="@string/app_name">

@drawable/icon
res
drawable-
hdpi5mdpi6ldpi7

12 res

@string/app_nameres/values
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloWorld!</string>
<string name="app_name">HelloWorld Sample</string>
</resources>

HelloWorld Sample

WVGA480x800FWVGA480x854

HVGA320x480

QVGA240x320
12

XML Android
Android R.java
R
Java R.xxx.xxx

13 R.java

<application><activity> Android
Activity
Android

ArcGIS Android

AgsSampleHelloWorld

14 Android

Java Android Application


Android
AVD

13

15

AgsSampleHelloWorld
HelloWorld Sample

16 Android Hello World

AgsSampleHelloWorld

14

17 Hello World

AgsSampleHelloWorld
Activity Activity
Android Activity
Activity Android
Activity Android Activity Windows
Activity
http://androidappdocs-staging.appspot.com/reference/android/app/Activit
y.htmlOK
AgsSampleHelloWorld Activity
com.esri.arcgis.android.sample.HelloWorld Activity
package com.esri.arcgis.android.samples;
import android.app.Activity;
import android.os.Bundle;
import com.esri.android.map.MapView;
public class HelloWorld extends Activity {
MapView map = null;
/** Called when the activity is first created. */
15

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
Object init = getLastNonConfigurationInstance();
if (init != null) {
map.restoreState((String) init);
}
}
/** Called by the system, as part of destroying an activity due to a configuration
change. */
public Object onRetainNonConfigurationInstance() {
return map.retainState();
}
}

Android Activity
onCreate Activity onCreate

setContentView(R.layout.main);

setContentView XML
Activity RR.layout.main
res/layoutmain.xml
Flex MXML Silverlight XAML
main.xml
<?xml version="1.0" encoding="utf-8"?>
<com.esri.android.map.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map" android:layout_width="fill_parent"
android:layout_height="fill_parent"
initExtent="-1.3296373526814876E7 3930962.41823043
-1.2807176545789773E7 4201243.7502468005">

16

<com.esri.android.map.ags.ArcGISTiledMapServiceLayer
url="http://services.arcgisonline.com/ArcGIS/rest/services/
World_Street_Map/MapServer"/>
</com.esri.android.map.MapView>

MapView8
MapView Android ViewGroup

View ViewGroup ArcGIS Android API


MapView ArcGIS API MapMapControl

MapView ArcGISTiledMapServiceLayer url


REST

ArcGIS
Web API
MapView android:id@+id/map
xml MapView id map MapView
HelloWorld.java
map = (MapView) findViewById(R.id.map);

Java findViewById Activity


MapView View
ArcGIS Android Activity XML
MapView ArcGISTiledMapServicesLayer Hello
World 16

http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/android/map/Map
View.html
17

III. MapView
GIS ArcGIS Android
MapView

ArcGIS Android API AddLayer


Map_View/AddLayer

18 AddLayer

Hello World
XML
Activity
public class AddLayer extends Activity {
private MapView map = null;
18

String dynamicMapURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/


services/Specialty/ESRI_StateCityHighway_USA/MapServer";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.map = (MapView) findViewById(R.id.map);
ArcGISDynamicMapServiceLayer dynamicLayer = new ArcGISDynamicMapServiceLayer(
this, this.dynamicMapURL);
this.map.addLayer(dynamicLayer);
}
}

Activity

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.esri.android.map.MapView android:id="@+id/map"
android:layout_width="fill_parent" android:layout_height="fill_parent"
initExtent="-1.3296373526814876E7 3930962.41823043
-1.2807176545789773E7 4201243.7502468005">
<com.esri.android.map.ags.ArcGISTiledMapServiceLayer
android:id="@+id/tiles1"
url="http://services.arcgisonline.com/ArcGIS/rest/services
/World_Street_Map/MapServer" />
</com.esri.android.map.MapView>
<Button android:id="@+id/buttonAdd"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="" />
</RelativeLayout>

Activity
19

public class AddLayer extends Activity {


String dynamicMapURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest
/services/Specialty/ESRI_StateCityHighway_USA/MapServer";
private MapView map = null;
private Button buttonAdd = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.map = (MapView) findViewById(R.id.map);
this.buttonAdd = (Button)findViewById(R.id.buttonAdd);
this.buttonAdd.setOnClickListener(new OnClickListener(){
public void onClick(View v){
ArcGISDynamicMapServiceLayer dynamicLayer =
new ArcGISDynamicMapServiceLayer(
AddLayer.this, AddLayer.this.dynamicMapURL);
AddLayer.this.map.addLayer(dynamicLayer);
}
});
}
}

19

19
20

MapView API removeLayer


reorderLayer

MapView
ArcGIS Android MapView
Hello World

<Button android:id="@+id/buttonZoomIn" android:text=""


android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<Button android:id="@+id/buttonZoomOut" android:text=""
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
public class Navigation extends Activity {
private MapView map = null;
private Button buttonZoomIn = null;
private Button buttonZoomOut = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.map = (MapView) findViewById(R.id.map);
this.buttonZoomIn = (Button) findViewById(R.id.buttonZoomIn);
this.buttonZoomOut = (Button) findViewById(R.id.buttonZoomOut);
this.buttonZoomIn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
21

Navigation.this.map.zoomin();
}
});
this.buttonZoomOut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Navigation.this.map.zoomout();
}
});
}
}

MapView zoomin zoomout


20

20

22

ArcGIS Android API OnLongPressListener


MapView
MapView
<TextView android:id="@+id/label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#ffffff" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />
this.map.setOnLongPressListener(new OnLongPressListener() {
public void onLongPress(float x, float y) {
Point pt = Navigation.this.map.toMapPoint(x, y);
Navigation.this.label.setText("X:"+pt.getX() + " Y:" + pt.getY());
}
});

21

21

MapView

OnLongPressListener

MapView

23

OnMapExtentChangedListener

MapView

OnPanListener

MapView

OnPinchListener

MapView

OnSingleTapListener

MapView

OnStatusChangedListener

MapView

OnZoomListener

MapView

MapOnTouchListener

MapView

24

IV.

ArcGIS Android GraphicsLayer ArcGIS


Web
MapView GraphicsLayer
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/buttonAddGraphic" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="" />
<com.esri.android.map.MapView android:id="@+id/map"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.esri.android.map.ags.ArcGISTiledMapServiceLayer
url="http://server.arcgisonline.com/ArcGIS/rest/services
/World_Imagery/MapServer" />
<com.esri.android.map.GraphicsLayer android:id="@+id/gLayer" />
</com.esri.android.map.MapView>
</LinearLayout>

GraphicsLayer
Graphic Activity
gLayer = (GraphicsLayer) findViewById(R.id.gLayer);
gLayer.setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(Color.RED,
20, SimpleMarkerSymbol.STYLE.SQUARE)));
buttonAddGraphic = (Button) findViewById(R.id.buttonAddGraphic);
buttonAddGraphic.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Graphic g = new Graphic();
g.setGeometry(AgsGraphicsLayer.this.map.getCenter());
25

AgsGraphicsLayer.this.gLayer.addGraphic(g);
AgsGraphicsLayer.this.gLayer.postInvalidate();
}
});

GraphicsLayer
20

22

API
PictureMarkerSymbol
Drawable image = AgsGraphicsLayer.this.getBaseContext().getResources()
.getDrawable(R.drawable.icon);
gLayer.setRenderer(new SimpleRenderer(new PictureMarkerSymbol(image)));

PictureMarkerSymbol

26

23

ClassBreaksRenderer renderer = new ClassBreaksRenderer();


renderer.setField("class");
renderer.setMinValue(0);
ClassBreak class1 = new ClassBreak();
class1.setClassMaxValue(0.5);
class1.setSymbol(new SimpleMarkerSymbol(Color.RED, 20,
SimpleMarkerSymbol.STYLE.CIRCLE));
renderer.addClassBreak(class1);
ClassBreak class2 = new ClassBreak();
class2.setClassMaxValue(1);
class2.setSymbol(new SimpleMarkerSymbol(Color.GREEN, 20,
SimpleMarkerSymbol.STYLE.CIRCLE));
renderer.addClassBreak(class2);
gLayer.setRenderer(renderer);
buttonAddGraphic = (Button) findViewById(R.id.buttonAddGraphic);
buttonAddGraphic.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Graphic g = new Graphic();
g.setAttributeValue("class", Math.random());
g.setGeometry(AgsGraphicsLayer.this.map.getCenter());
AgsGraphicsLayer.this.gLayer.addGraphic(g);
AgsGraphicsLayer.this.gLayer.postInvalidate();
27

}
});

class
24

24

ArcGIS Android
DrawGraphicElements

28

25

Graphic
Select Geometry
Java
geometryButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(0);
}
});

showDialog Activity onCreateDialog

protected Dialog onCreateDialog(int id) {


return new AlertDialog.Builder(DrawGraphicElements.this)
.setTitle("Select Geometry")
.setItems(geometryTypes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
graphicsLayer.clear();
String geomType = geometryTypes[which];
label.setText(geomType + " selected.");
selectedGeometryIndex = which;
29

if (geomType.equalsIgnoreCase("Polygon")) {
SimpleFillSymbol sfs = new SimpleFillSymbol(Color.GREEN);
sfs.setAlpha(60);
graphicsLayer.setRenderer(new SimpleRenderer(sfs));
myListener.setType("POLYGON");
} else if (geomType.equalsIgnoreCase("Polyline")) {
graphicsLayer.setRenderer(new SimpleRenderer(new
SimpleLineSymbol(Color.RED, 5)));
myListener.setType("POLYLINE");
} else if (geomType.equalsIgnoreCase("Point")) {
graphicsLayer.setRenderer(new SimpleRenderer(new
SimpleMarkerSymbol(Color.BLUE, 15, STYLE.CIRCLE)));
myListener.setType("POINT");
}
}
}).create();
}

setItems 3 PointPolyline
Polygon Item Item

myListener
myListener
myListener = new MyTouchListener(DrawGraphicElements.this, mapView);
mapView.setOnTouchListener(myListener);
class MyTouchListener extends MapOnTouchListener {
MultiPath poly;
String type = "";
Point startPoint = null;
public MyTouchListener(Context context, MapView view) {
super(context, view);
}
public void setType(String geometryType) {
this.type = geometryType;
}

30

public String getType() {


return this.type;
}
@Override
public boolean onSingleTap(MotionEvent e) {
if (type.length() > 1 && type.equalsIgnoreCase("POINT")) {
graphicsLayer.clear();
Graphic graphic = new Graphic();
graphic.setGeometry(mapView.toMapPoint(new Point(e.getX(), e.getY())));
graphicsLayer.addGraphic(graphic);
graphicsLayer.postInvalidate();
clearButton.setEnabled(true);
return true;
}
return false;
}
@Override
public boolean onDragPointerMove(MotionEvent from, MotionEvent to) {
if (type.length() > 1 && (type.equalsIgnoreCase("POLYLINE") ||
type.equalsIgnoreCase("POLYGON"))) {
Point mapPt = mapView.toMapPoint(to.getX(), to.getY());
if (startPoint == null) {
graphicsLayer.clear();
poly = type.equalsIgnoreCase("POLYLINE")?new Polyline():new Polygon();
startPoint = mapView.toMapPoint(from.getX(), from.getY());
poly.startPath((float) startPoint.getX(), (float) startPoint.getY());
Graphic graphic = new Graphic();
graphic.setGeometry(poly);
graphicsLayer.addGraphic(graphic);
}
poly.lineTo((float) mapPt.getX(), (float) mapPt.getY());
graphicsLayer.postInvalidate();
return true;
}
return super.onDragPointerMove(from, to);
}
@Override
31

public boolean onDragPointerUp(MotionEvent from, MotionEvent to) {


if (type.length() > 1 && (type.equalsIgnoreCase("POLYLINE") ||
type.equalsIgnoreCase("POLYGON"))) {
if (type.equalsIgnoreCase("POLYGON")) {
poly.lineTo((float) startPoint.getX(), (float) startPoint.getY());
}
startPoint = null;
graphicsLayer.postInvalidate();
clearButton.setEnabled(true);
return true;
}
return false;
}
}

PolygontypePolygon
onDragPointerMove
startPoint
Polygon
lineTo Polygon
onDragPointerUp Graphic

32

V.

Query
Query QueryTask ArcGIS
Server
Query QueryTask execute
FeatureSet
this.map.setOnLongPressListener(new OnLongPressListener() {
public void onLongPress(float x, float y) {
Point pt = AgsQuery.this.map.toMapPoint(x, y);
Query query = new Query("http://server.arcgisonline.com/ArcGIS/rest/services
/Demographics/USA_1990-2000_Population_Change/MapServer/4");
query.setGeometry(pt);
query.setReturnGeometry(true);
query
.setSpatialRelationship(Query.SpatialRelationship.INTERSECTS);
QueryTask queryTask = new QueryTask(query);
try {
FeatureSet fs = queryTask.execute();

33

SimpleFillSymbol symbol = new SimpleFillSymbol(Color.BLACK);


AgsQuery.this.gLayer
.setRenderer(new SimpleRenderer(symbol));
AgsQuery.this.gLayer.clear();
AgsQuery.this.gLayer.addGraphics(fs.getGraphics());
AgsQuery.this.gLayer.postInvalidate();
} catch (Exception e) {
e.printStackTrace();
}
}
});

FeatureSet Graphic
GraphicsLayer

26

QueryTask

Query query = new Query(queryUrl);


query.setWhere("RATE_POP<0.2");
query.setReturnGeometry(true);
QueryTask queryTask = new QueryTask(query);

GraphicsLayer
34

27

ArcGIS Identify Query


ArcGIS Android API
HighlightFeatures

28

35

QueryTask IdentifyTask

IdentifyParameters inputParameters = new IdentifyParameters();


inputParameters.setGeometry(pointClicked);
inputParameters.setUrl("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services
/PublicSafety/PublicSafetyBasemap/MapServer/identify");
inputParameters.setLayers(new int[] { layerIndexes[selectedLayerIndex] });
inputParameters.setMapExtent(mapView.getExtent());
inputParameters.setDPI(96);
inputParameters.setMapHeight(mapView.getHeight());
inputParameters.setMapWidth(mapView.getWidth());
inputParameters.setTolerance(10);
final IdentifyTask identifyAction = new IdentifyTask(inputParameters);
IdentifyResult[] results = identifyAction.execute();

Identify ArcGIS Server API


Identify
setLayers setTolerance ArcGIS
Android API

36

VI.
GeometryGeoProcessing/GP
GIS ArcGIS Android API
GP

ArcGIS Android API ArcGIS Web API


ArcGIS Sever Geometry Service API

buffer Geometry
Service ArcGIS Android API GeometryEngine

buffer
map.setOnLongPressListener(new OnLongPressListener() {
public void onLongPress(float x, float y) {
Point pt = map.toMapPoint(new Point(x, y));
Polygon pg = GeometryEngine.buffer(pt, map
.getSpatialReference(), 1000000, null); //null
Graphic g = new Graphic();
g.setGeometry(pg);
AgsGeometryEngine.this.gLayer.addGraphic(g);
AgsGeometryEngine.this.gLayer.postInvalidate();
}
});

GeometryEngine buffer
GraphicsLayer
37

29 GeometryEngine

GeometryEngine

map.setOnLongPressListener(new OnLongPressListener() {
public void onLongPress(float x, float y) {
Point pt = map.toMapPoint(new Point(x, y));
Polygon pg = GeometryEngine.buffer(pt, map
.getSpatialReference(), 2000000, null);
Geometry geo = GeometryEngine.clip(pg, map.getExtent(), map
.getSpatialReference());//
Graphic g = new Graphic();
g.setGeometry(geo);
AgsGeometryEngine.this.gLayer.addGraphic(g);
AgsGeometryEngine.this.gLayer.postInvalidate();
}
});

GeometryEngine clip

30
38

30 GeometryEngine

31 GP ViewShed

ArcGIS Android API GP ViewShed


GP

39

GP

go
GP
GPFeatureRecordSetLayer gpf = new GPFeatureRecordSetLayer(
"Input_Observation_Point");
gpf.setSpatialReference(map.getSpatialReference());
gpf.setGeometryType("esriGeometryPoint");
Graphic f = new Graphic();
f.setGeometry(mappoint);
gpf.addGraphic(f);
GPLinearUnit gpl = new GPLinearUnit("Viewshed_Distance");
gpl.setUnits("esriMeters");
gpl.setDistance(8046.72);
params = new ArrayList<GPParameter>();
params.add(gpf);
params.add(gpl);
try {
dialog = ProgressDialog.show(Viewshed.this, "",
"Loading. Please wait...", true, true);
new ViewShedQuery().execute(params);
cancelViewShed = new Timer();
cancelViewShed.schedule(new TimerTask() {
@Override
public void run() {
uiHandler.sendEmptyMessage(CANCEL_LOADING_WINDOW);
}
}, 60000);
} catch (Exception e) {
e.printStackTrace();
}

GP
ArrayList<GPParameter> GP

40

GP

class ViewShedQuery extends


AsyncTask<ArrayList<GPParameter>, Void, GPParameter[]> {
GPParameter[] outParams = null;
@Override
protected void onPostExecute(GPParameter[] result) {

}
@Override
protected GPParameter[] doInBackground(
ArrayList<GPParameter>... params1) {
gp = new GeoProcessor("http://sampleserver1.arcgisonline.com/ArcGIS
/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed");
gp.setOutSR(map.getSpatialReference().getID());
try {
GPResultResource gprr = gp.execute(params1[0]);
outParams = gprr.getOutputParameters();
} catch (Exception e) {
e.printStackTrace();
}
return outParams;
}

GP
GeoProcessor execute GP
GeoProcessor submitJob

41

VII.
ArcGIS 10
Capability
Feature Access

Feature Layer
ArcGIS Android API Feature Layer

Feature Layer
ArcGIS Android API SelectFeatures
Feature Layer

32 Feature Layer

Feature Layer

Feature Layer

42


Query
ArcGISFeatureLayer selectFeature
fLayer.clearSelection();
Query q = new Query();
q.setWhere("PROD_GAS='Yes'");
q.setReturnGeometry(true);
q.setInSpatialReference(map.getSpatialReference());
q.setGeometry(g.getGeometry());
q.setSpatialRelationship(SpatialRelationship.INTERSECTS);
fLayer.selectFeatures(q, SELECTION_METHOD.NEW, callback);

selectFeature ArcGISFeatureLayer
Query
FeatureSet ArcGISFeatureLayer
ArcGISFeatureLayer GraphicsLayer

Options o = new Options();


o.mode = MODE.ONDEMAND;
o.outFields = new String[] {"FIELD_KID", "APPROXACRE", "FIELD_NAME"};
fLayer = new ArcGISFeatureLayer(this,
"http://sampleserver3.arcgisonline.com/ArcGIS/rest
/services/Petroleum/KSPetro/MapServer/1",o);

ArcGISFeatureLayer URL MapServer


Feature Layer
ArcGISFeatureLayer URL FeatureServer

43


ArcGIS Android API
AttributeEditor

33

Apply

Graphic newGraphic = new Graphic();


//
newGraphic.setAttributeValue(featureLayer.getObjectIdField(),
listAdapter.featureSet.getGraphics()[0]
.getAttributeValue(featureLayer.getObjectIdField()));
featureLayer.applyEdits(null, null, new Graphic[] { newGraphic },
createEditCallbackListener(updateMapLayer));
44

ArcGIS Web API


Graphic Graphic ObjectID
ArcGISFeatureLayer applyEdits
Feature Layer Feature Server
applyEdits

ArcGIS Android API


AttributeEditor API
Feature Layer

AgsEditFeatureLayer Activity MapView

<com.esri.android.map.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent" android:layout_height="fill_parent"
initExtent="-10868502.895856911 4470034.144641369
-10837928.084542884 4492965.25312689">
<com.esri.android.map.ags.ArcGISTiledMapServiceLayer
url="http://services.arcgisonline.com/ArcGIS/rest
/services/World_Topo_Map/MapServer" />
<com.esri.android.map.ags.ArcGISDynamicMapServiceLayer
url="http://sampleserver3.arcgisonline.com/ArcGIS/rest
/services/Petroleum/KSFields/MapServer" />

45

<com.esri.android.map.ags.ArcGISFeatureLayer android:id="@+id/fLayer"
url="http://sampleserver3.arcgisonline.com/ArcGIS/rest
/services/Petroleum/KSFields/FeatureServer/0"
mode="selection" />
<com.esri.android.map.GraphicsLayer android:id="@+id/gLayer"/>
</com.esri.android.map.MapView>

public class AgsEditFeatureLayer extends Activity {


MapView map = null;
ArcGISFeatureLayer fLayer = null;
GraphicsLayer gLayer = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
fLayer = (ArcGISFeatureLayer) findViewById(R.id.fLayer);
gLayer = (GraphicsLayer) findViewById(R.id.gLayer);
SimpleFillSymbol fSymbol = new SimpleFillSymbol(Color.YELLOW);
fSymbol.setOutline(new SimpleLineSymbol(Color.RED, 2));
fLayer.setSelectionSymbol(fSymbol);
SimpleFillSymbol gSymbol = new SimpleFillSymbol(Color.BLACK);
gSymbol.setOutline(new SimpleLineSymbol(Color.RED, 2));
gLayer.setRenderer(new SimpleRenderer(gSymbol));
map.setOnLongPressListener(new OnLongPressListener() {
public void onLongPress(float x, float y) {
Point pt = map.toMapPoint(new Point(x, y));
Query q = new Query();
q.setReturnGeometry(true);
q.setGeometry(pt);
q.setInSpatialReference(map.getSpatialReference());
q.setSpatialRelationship(SpatialRelationship.INTERSECTS);
fLayer.selectFeatures(q, SELECTION_METHOD.NEW, null);
}
});
}
}
46

selectFeatures ArcGIS Server


fLayer ArcGISFeatureLayer
GraphicsLayer Graphic 32

34 Feature Layer

Graphic

GraphicsLayer gLayer
gLayer

fLayer.selectFeatures(q, SELECTION_METHOD.NEW, new CallbackListener<FeatureSet>(){


public void onCallback(FeatureSet fs) {
gLayer.clear();
gLayer.addGraphics(fs.getGraphics());
gLayer.postInvalidate();
}
public void onError(Throwable t) {
t.printStackTrace();
}
});
47


MapOnTouchListener
MapView
map.setOnTouchListener(new MyMapOnTouchListener(this, map, fLayer, gLayer));
public class MyMapOnTouchListener extends MapOnTouchListener {
private Context context = null;
private MapView map = null;
private ArcGISFeatureLayer fLayer = null;
private GraphicsLayer gLayer = null;
private Graphic g = null;
private int editIndex = -1;
public MyMapOnTouchListener(Context context, MapView map,
ArcGISFeatureLayer fLayer, GraphicsLayer gLayer) {
super(context, map);
this.context = context;
this.map = map;
this.fLayer = fLayer;
this.gLayer = gLayer;
}
@Override
public boolean onDragPointerMove(MotionEvent from, MotionEvent to) {
Graphic[] gs = gLayer.getGraphics();
if(gs==null || gs.length==0){
return false;
}
Graphic g = gs[0];
Polygon pg = (Polygon)g.getGeometry();

if (editIndex<0) {//
Point ptClick = map.toMapPoint(from.getX(), from.getY());
Proximity2DResult pr = GeometryEngine.getNearestVertex(pg, ptClick);
editIndex = pr.getVertexIndex();
}
if(g!=null && editIndex>=0){
Point ptTo = map.toMapPoint(to.getX(), to.getY());
pg.setPoint(editIndex, ptTo);//
48

}
gLayer.postInvalidate();
return true;
}
@Override
public boolean onDragPointerUp(MotionEvent from, MotionEvent to) {
editIndex = -1;
gLayer.postInvalidate();
return true;
}
}

35 3
77

35

ArcGIS Server

buttonApply.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
49

fLayer.applyEdits(null, null, gLayer.getGraphics(),


new CallbackListener<FeatureEditResult[][]>() {
public void onCallback(FeatureEditResult[][] results) {
System.out.println("Updated");
}
public void onError(Throwable t) {
t.printStackTrace();
}
});
}
});

LogCat
02-21 14:18:02.358: DEBUG/ArcGIS.ThreadPool(736): Updated Features:1

applyEdits
CallbackListener

36

50

VIII. Android

Android
GPSWIFI
LocationManager Android
public class AgsLocation extends Activity {
MapView map = null;
LocationManager loc = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
loc = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
loc.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
new LocationListener() {
public void onLocationChanged(Location l) {
Point ptLatLon = new Point(l.getLongitude(), l
.getLatitude());
SpatialReference sr4326 = SpatialReference.create(4326);
Point ptMap = (Point)GeometryEngine.project(ptLatLon, sr4326,
map.getSpatialReference());
map.centerAt(ptMap);
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
});
}
}

51

GPS Android
LOCATION_SERVICE Android
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>

Android
GeometryEngine Emulator Control
GPS

37 GPS

52

IX.

ArcGIS for AndroidResource Center


http://help.arcgis.com/en/arcgismobile/10.0/apis/android/help/

ArcGIS Android API


http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/index.html

http://blog.csdn.net/warrenwyf/category/784554.aspx

53

You might also like