1. 程式人生 > >arcgis runtime for android 100.3開發學習(一)(點、線、面,圖層的建立)

arcgis runtime for android 100.3開發學習(一)(點、線、面,圖層的建立)

本節我們來學習一下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  method, as in addition to these checks, this method checks that each vertex in a Multipoint or Multipart geometry is in the same order; parts of Multiparts must also begin and end at the same Point.

getDimension()

Gets the dimension of this Geometry, relating to the number of spatial dimensions in which the geometry may have a size.

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.

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.

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.

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.

getGeometry()

Gets the geometry of this geoelement.

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
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.

getExtent()

Calculates and returns the extent of the graphics currently contained in this overlay.

getGraphics()

Gets a modifiable list of the graphics in this overlay.

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.

getRenderer()

Gets the renderer for the graphics overlay.

getSceneProperties()

Gets a layer scene properties object that can be used to make changes to how graphics are displayed in a SceneView.

getSelectedGraphics()

Gets a read only list of the currently selected graphics in this overlay.

int
boolean isLabelsEnabled()

Gets whether labels are enabled.

boolean isPopupEnabled()

Gets a flag indicating whether the PopupDefinition returned from  is enabled or disabled.

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  is enabled or disabled.

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  from your 

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.

getSymbol(Graphic graphic)

Gets the Symbol used to display the given Graphic.

getSymbol()

Gets the Symbol that is being used by this Renderer to draw Features/Graphics to the GeoView.

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.

                                                                          更多內容,請關注公眾號