If you think the Android project arcgis-runtime-samples-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/* Copyright 2013 ESRI
*/*www.java2s.com*/
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
*
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
*
* See the sample code usage restrictions document for further information.
*/package com.arcgis.android.samples.geometrysample;
import com.esri.android.map.GraphicsLayer;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.MultiPoint;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.Polyline;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.SimpleFillSymbol;
import com.esri.core.symbol.SimpleLineSymbol;
import com.esri.core.symbol.SimpleMarkerSymbol;
import com.esri.core.symbol.SimpleMarkerSymbol.STYLE;
publicclass GeometryUtil {
/**
* highlight graphic objects in random colors
*/publicstaticvoid highlightGeometriesWithColor(Geometry[] results,
GraphicsLayer graphicsLayer, int color) throws Exception {
highlightGeometriesWithColor(results, graphicsLayer, color, 16);
}
publicstaticvoid highlightGeometriesWithColor(Geometry[] results,
GraphicsLayer graphicsLayer, int color, int size) throws Exception {
if (results == null || results.length == 0)
return;
for (int i = 0; i < results.length; i++) {
Geometry geom = results[i];
String typeName = geom.getType().name();
/*
* Create appropriate symbol, based on geometry type
*/if (typeName.equalsIgnoreCase("point")) {
addPointToGraphicsLayer((Point) geom, graphicsLayer, color,
size, STYLE.CIRCLE);
} elseif (typeName.equalsIgnoreCase("polyline")) {
addPolylineToGraphicsLayer((Polyline) geom, color, size / 4,
graphicsLayer);
} elseif (typeName.equalsIgnoreCase("multipoint")) {
addMultiPointToGraphicsLayer((MultiPoint) geom, STYLE.CIRCLE,
size, color, graphicsLayer);
}
elseif (typeName.equalsIgnoreCase("polygon")) {
SimpleFillSymbol sfs = new SimpleFillSymbol(color);
sfs.getOutline().setWidth(size / 4);
// sfs.setAlpha(50);
graphicsLayer.addGraphic(new Graphic(geom, sfs));
}
elseif (typeName.equalsIgnoreCase("envelope")) {
SimpleFillSymbol sfs = new SimpleFillSymbol(color);
sfs.getOutline().setWidth(size / 4);
graphicsLayer.addGraphic(new Graphic(geom, sfs));
}
}
}// end of method
publicstaticvoid addPolylineToGraphicsLayer(Polyline pl, int color,
int size, GraphicsLayer graphicsLayer) throws Exception {
SimpleLineSymbol sls = new SimpleLineSymbol(color, size,
com.esri.core.symbol.SimpleLineSymbol.STYLE.SOLID);
Graphic g = new Graphic(pl, sls);
graphicsLayer.addGraphic(g);
}
publicstaticvoid addPolygonToGraphicsLayer(Polygon pg, int color,
int size, int alpha, GraphicsLayer graphicsLayer) throws Exception {
SimpleFillSymbol sfs = new SimpleFillSymbol(color);
sfs.setAlpha(alpha);
Graphic g = new Graphic(pg, sfs);
graphicsLayer.addGraphic(g);
}
/**
* add points to graphic layer
*/publicstaticvoid addPointToGraphicsLayer(Point point,
GraphicsLayer graphicsLayer, int color, int size, STYLE style)
throws Exception {
SimpleMarkerSymbol sms = new SimpleMarkerSymbol(color, size, style);
Graphic graphic = new Graphic(point, sms);
graphicsLayer.addGraphic(graphic);
}// end of method
/**
* add multipoint to a graphic layer
*/publicstaticvoid addMultiPointToGraphicsLayer(MultiPoint mPoint,
STYLE style, int size, int color, GraphicsLayer graphicsLayer)
throws Exception {
int len = mPoint.getPointCount();
Graphic[] graphics = new Graphic[len];
for (int i = 0; i < len; i++) {
Point geom = mPoint.getPoint(i);
SimpleMarkerSymbol sms = new SimpleMarkerSymbol(color, size, style);
graphics[i] = new Graphic(geom, sms);
graphicsLayer.addGraphic(graphics[i]);
}
}// end of method
}