本节我们来学习一下arcgis runtime for android方面的相关内容,一一学习相关方面的api知识。这个案例是摘取github官网上面的。主要创建图形案例的点、线、面,当然还有图层的创建。来看一下实现的代码。
package com.example.arcroid.addgraphicsrenderer;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.PolygonBuilder;
import com.esri.arcgisruntime.geometry.PolylineBuilder;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
import com.esri.arcgisruntime.symbology.SimpleRenderer;
public class MainActivity extends AppCompatActivity {
private MapView mapview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapview=findViewById(R.id.mapview);
ArcGISMap mMap = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 15.169193,
16.333479, 2);
mapview.setMap(mMap);
addGraphicsOverlay();
}
private void addGraphicsOverlay(){
Point pointGeometry = new Point(40e5, 40e5, SpatialReferences.getWebMercator());
SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.DIAMOND, Color.RED, 10);
Graphic pointGraphic = new Graphic(pointGeometry);
GraphicsOverlay pointGraphicOverlay = new GraphicsOverlay();
SimpleRenderer pointRenderer = new SimpleRenderer(pointSymbol);
pointGraphicOverlay.setRenderer(pointRenderer);
pointGraphicOverlay.getGraphics().add(pointGraphic);
mapview.getGraphicsOverlays().add(pointGraphicOverlay);
PolylineBuilder lineGeometry = new PolylineBuilder(SpatialReferences.getWebMercator());
lineGeometry.addPoint(-10e5, 40e5);
lineGeometry.addPoint(20e5, 50e5);
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 5);
Graphic lineGraphic = new Graphic(lineGeometry.toGeometry());
GraphicsOverlay lineGraphicOverlay = new GraphicsOverlay();
SimpleRenderer lineRenderer = new SimpleRenderer(lineSymbol);
lineGraphicOverlay.setRenderer(lineRenderer);
lineGraphicOverlay.getGraphics().add(lineGraphic);
mapview.getGraphicsOverlays().add(lineGraphicOverlay);
PolygonBuilder polygonGeometry = new PolygonBuilder(SpatialReferences.getWebMercator());
polygonGeometry.addPoint(-20e5, 20e5);
polygonGeometry.addPoint(20e5, 20e5);
polygonGeometry.addPoint(20e5, -20e5);
polygonGeometry.addPoint(-20e5, -20e5);
SimpleFillSymbol polygonSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, null);
Graphic polygonGraphic = new Graphic(polygonGeometry.toGeometry());
GraphicsOverlay polygonGraphicOverlay = new GraphicsOverlay();
SimpleRenderer polygonRenderer = new SimpleRenderer(polygonSymbol);
polygonGraphicOverlay.setRenderer(polygonRenderer);
polygonGraphicOverlay.getGraphics().add(polygonGraphic);
mapview.getGraphicsOverlays().add(polygonGraphicOverlay);
}
@Override
protected void onDestroy() {
super.onDestroy();
mapview.dispose();
}
@Override
protected void onResume() {
super.onResume();
mapview.resume();
}
@Override
protected void onPause() {
super.onPause();
}
}
首先来看一下对象点Point相关的api
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static Point | createWithM(double x, double y, double m) Creates a new immutable Point with the given x,y coordinates, and m-value. | ||||||||||
static Point | createWithM(double x, double y, double z, double m) Creates a new immutable Point with the given x,y coordinates, z-value, and m-value. | ||||||||||
static Point | createWithM(double x, double y, double z, double m, SpatialReference spatialReference) Creates a new immutable Point with the given x,y coordinates, z-value, m-value, and SpatialReference. | ||||||||||
static Point | createWithM(double x, double y, double m, SpatialReference spatialReference) Creates a new immutable Point with the given x,y coordinates, m-value, and SpatialReference. | ||||||||||
boolean | equals(Geometry geometry, double tolerance) Checks if a given geometry is equal to this one within a given tolerance. | ||||||||||
boolean | equals(Object obj) This method is more stringent than the | ||||||||||
GeometryDimension | getDimension() Gets the dimension of this Geometry, relating to the number of spatial dimensions in which the geometry may have a size. | ||||||||||
GeometryType | getGeometryType() Gets the type of this Geometry, indicating the subclass, and the type of geometrical shape it can represent. | ||||||||||
double | getM() Gets the m-value of this Point. | ||||||||||
double | getX() Gets the x-coordinate of this Point. | ||||||||||
double | getY() Gets the y-coordinate of this Point. | ||||||||||
double | getZ() Gets the z-value of this Point. | ||||||||||
boolean | hasM() Indicates if this Geometry has m-values. | ||||||||||
boolean | hasZ() Indicates if this Geometry has z-values. | ||||||||||
int | hashCode() | ||||||||||
String | toString() Returns a string representation of this Point instance. |
SimpleMarkerSymbol类的api
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | getColor() Gets the interior color of this Symbol as a ARGB(alpha, red, green, blue) value. | ||||||||||
SimpleLineSymbol | getOutline() Gets the SimpleLineSymbol used to create the border of this Symbol, if any border is present. | ||||||||||
float | getSize() Gets the height and width in density-independent pixels (dp) of the symbol. | ||||||||||
SimpleMarkerSymbol.Style | getStyle() Gets the marker style that describes what shape this Symbol is displayed as. | ||||||||||
void | setColor(int color) Sets the interior color of this Symbol to a ARGB(alpha, red, green, blue) value. | ||||||||||
void | setOutline(SimpleLineSymbol outline) Sets the SimpleLineSymbol used to create the border of the Symbol. | ||||||||||
void | setSize(float size) Sets the height and width in density-independent pixels (dp) of the symbol. | ||||||||||
void | setStyle(SimpleMarkerSymbol.Style style) Sets the marker style that describes what shape this Symbol is going to be displayed as. |
graphic类函数
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Map<String, Object> | getAttributes() Gets a java.util.Map of all the available attributes as name value pairs. | ||||||||||
Geometry | getGeometry() Gets the geometry of this geoelement. | ||||||||||
GraphicsOverlay | getGraphicsOverlay() Gets the graphics overlay that contains this graphic. | ||||||||||
Symbol | getSymbol() Gets the symbol. | ||||||||||
int | getZIndex() Gets the z index. | ||||||||||
boolean | isSelected() Checks if the graphic is selected. | ||||||||||
boolean | isVisible() Checks if the graphic is visible. | ||||||||||
void | setGeometry(Geometry geometry) Sets the GeoElement's geometry. | ||||||||||
void | setSelected(boolean selected) Controls if the graphic is selected or not | ||||||||||
void | setSymbol(Symbol symbol) Sets the symbol. | ||||||||||
void | setVisible(boolean visible) Controls the visibility of the graphic. | ||||||||||
void | setZIndex(int index) Sets the z index. |
GraphicsOverlay
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | clearSelection() Deselect all graphics in the graphics overlay. | ||||||||||
Envelope | getExtent() Calculates and returns the extent of the graphics currently contained in this overlay. | ||||||||||
ListenableList<Graphic> | getGraphics() Gets a modifiable list of the graphics in this overlay. | ||||||||||
List<LabelDefinition> | getLabelDefinitions() Gets a modifiable list of label definitions of this graphics overlay. | ||||||||||
double | getMaxScale() Gets the maximum scale for the graphics overlay. | ||||||||||
double | getMinScale() Gets the minimum scale for the graphics overlay. | ||||||||||
float | getOpacity() Gets the opacity - a value between 0 to 1.0 with 1.0 being opaque and 0 being transparent. | ||||||||||
PopupDefinition | getPopupDefinition() Gets the PopupDefinition set via | ||||||||||
Renderer | getRenderer() Gets the renderer for the graphics overlay. | ||||||||||
GraphicsOverlay.RenderingMode | getRenderingMode() Gets the rendering mode used to render this overlay. | ||||||||||
LayerSceneProperties | getSceneProperties() Gets a layer scene properties object that can be used to make changes to how graphics are displayed in a SceneView. | ||||||||||
List<Graphic> | getSelectedGraphics() Gets a read only list of the currently selected graphics in this overlay. | ||||||||||
int | getSelectionColor() This method is deprecated. as of 100.4.0, use | ||||||||||
boolean | isLabelsEnabled() Gets whether labels are enabled. | ||||||||||
boolean | isPopupEnabled() Gets a flag indicating whether the PopupDefinition returned from | ||||||||||
boolean | isVisible() Checks if this graphics overlay is visible. | ||||||||||
void | setLabelsEnabled(boolean enabled) Enables or disables the labeling for the graphics overlay. | ||||||||||
void | setMaxScale(double maxScale) Sets the maximum scale for the graphics overlay. | ||||||||||
void | setMinScale(double minScale) Sets the minimum scale for the graphics overlay. | ||||||||||
void | setOpacity(float opacity) Sets the opacity - a value between 0 to 1.0 with 1.0 being solid or opaque and 0 being transparent. | ||||||||||
void | setPopupDefinition(PopupDefinition popupDefinition) Sets the PopupDefinition for the GraphicsOverlay, overriding any previous one set. | ||||||||||
void | setPopupEnabled(boolean enabled) Sets a flag indicating whether the PopupDefinition returned from | ||||||||||
void | setRenderer(Renderer renderer) Sets a renderer to the graphics overlay. | ||||||||||
void | setSelectionColor(int selectionColor) This method is deprecated. as of 100.4.0, use | ||||||||||
void | setVisible(boolean visible) Sets if this graphics overlay is visible. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | getDescription() Gets the description that describes what this Renderer's does. | ||||||||||
String | getLabel() Gets the name of this Renderer. | ||||||||||
Symbol | getSymbol(Graphic graphic) Gets the Symbol used to display the given Graphic. | ||||||||||
Symbol | getSymbol() Gets the Symbol that is being used by this Renderer to draw Features/Graphics to the GeoView. | ||||||||||
Symbol | getSymbol(Feature feature) Gets the Symbol used to display the given Feature. | ||||||||||
void | setDescription(String description) Sets the description, which gives detail information about what this Renderer's does. | ||||||||||
void | setLabel(String label) Sets a name that this Renderer can be referred to. | ||||||||||
void | setSymbol(Symbol symbol) Sets the Symbol to be used by this Renderer to draw Features/Graphics to the GeoView. |
更多内容,请关注公众号