arcgis runtime for android 100.3开发学习(一)(点、线、面,图层的创建)

19 篇文章 0 订阅

本节我们来学习一下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 PointcreateWithM(double x, double y, double m)

Creates a new immutable Point with the given x,y coordinates, and m-value.

static PointcreateWithM(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 PointcreateWithM(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 PointcreateWithM(double x, double y, double m, SpatialReference spatialReference)

Creates a new immutable Point with the given x,y coordinates, m-value, and SpatialReference.

booleanequals(Geometry geometry, double tolerance)

Checks if a given geometry is equal to this one within a given tolerance.

booleanequals(Object obj)

This method is more stringent than the equals(Geometry, Geometry) 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.

GeometryDimensiongetDimension()

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

GeometryTypegetGeometryType()

Gets the type of this Geometry, indicating the subclass, and the type of geometrical shape it can represent.

doublegetM()

Gets the m-value of this Point.

doublegetX()

Gets the x-coordinate of this Point.

doublegetY()

Gets the y-coordinate of this Point.

doublegetZ()

Gets the z-value of this Point.

booleanhasM()

Indicates if this Geometry has m-values.

booleanhasZ()

Indicates if this Geometry has z-values.

inthashCode()
StringtoString()

Returns a string representation of this Point instance.

 

SimpleMarkerSymbol类的api
Public Methods
intgetColor()

Gets the interior color of this Symbol as a ARGB(alpha, red, green, blue) value.

SimpleLineSymbolgetOutline()

Gets the SimpleLineSymbol used to create the border of this Symbol, if any border is present.

floatgetSize()

Gets the height and width in density-independent pixels (dp) of the symbol.

SimpleMarkerSymbol.StylegetStyle()

Gets the marker style that describes what shape this Symbol is displayed as.

voidsetColor(int color)

Sets the interior color of this Symbol to a ARGB(alpha, red, green, blue) value.

voidsetOutline(SimpleLineSymbol outline)

Sets the SimpleLineSymbol used to create the border of the Symbol.

voidsetSize(float size)

Sets the height and width in density-independent pixels (dp) of the symbol.

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

GeometrygetGeometry()

Gets the geometry of this geoelement.

GraphicsOverlaygetGraphicsOverlay()

Gets the graphics overlay that contains this graphic.

SymbolgetSymbol()

Gets the symbol.

intgetZIndex()

Gets the z index.

booleanisSelected()

Checks if the graphic is selected.

booleanisVisible()

Checks if the graphic is visible.

voidsetGeometry(Geometry geometry)

Sets the GeoElement's geometry.

voidsetSelected(boolean selected)

Controls if the graphic is selected or not

voidsetSymbol(Symbol symbol)

Sets the symbol.

voidsetVisible(boolean visible)

Controls the visibility of the graphic.

voidsetZIndex(int index)

Sets the z index.

GraphicsOverlay

Public Methods
voidclearSelection()

Deselect all graphics in the graphics overlay.

EnvelopegetExtent()

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.

doublegetMaxScale()

Gets the maximum scale for the graphics overlay.

doublegetMinScale()

Gets the minimum scale for the graphics overlay.

floatgetOpacity()

Gets the opacity - a value between 0 to 1.0 with 1.0 being opaque and 0 being transparent.

PopupDefinitiongetPopupDefinition()

Gets the PopupDefinition set via setPopupDefinition(PopupDefinition), or null if one has not been set.

RenderergetRenderer()

Gets the renderer for the graphics overlay.

GraphicsOverlay.RenderingModegetRenderingMode()

Gets the rendering mode used to render this overlay.

LayerScenePropertiesgetSceneProperties()

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.

intgetSelectionColor()

This method is deprecated. as of 100.4.0, use getColor() from your GeoView

booleanisLabelsEnabled()

Gets whether labels are enabled.

booleanisPopupEnabled()

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

booleanisVisible()

Checks if this graphics overlay is visible.

voidsetLabelsEnabled(boolean enabled)

Enables or disables the labeling for the graphics overlay.

voidsetMaxScale(double maxScale)

Sets the maximum scale for the graphics overlay.

voidsetMinScale(double minScale)

Sets the minimum scale for the graphics overlay.

voidsetOpacity(float opacity)

Sets the opacity - a value between 0 to 1.0 with 1.0 being solid or opaque and 0 being transparent.

voidsetPopupDefinition(PopupDefinition popupDefinition)

Sets the PopupDefinition for the GraphicsOverlay, overriding any previous one set.

voidsetPopupEnabled(boolean enabled)

Sets a flag indicating whether the PopupDefinition returned from getPopupDefinition() is enabled or disabled.

voidsetRenderer(Renderer renderer)

Sets a renderer to the graphics overlay.

voidsetSelectionColor(int selectionColor)

This method is deprecated. as of 100.4.0, use setColor(int) from your GeoView

voidsetVisible(boolean visible)

Sets if this graphics overlay is visible.

 

Public Methods
StringgetDescription()

Gets the description that describes what this Renderer's does.

StringgetLabel()

Gets the name of this Renderer.

SymbolgetSymbol(Graphic graphic)

Gets the Symbol used to display the given Graphic.

SymbolgetSymbol()

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

SymbolgetSymbol(Feature feature)

Gets the Symbol used to display the given Feature.

voidsetDescription(String description)

Sets the description, which gives detail information about what this Renderer's does.

voidsetLabel(String label)

Sets a name that this Renderer can be referred to.

voidsetSymbol(Symbol symbol)

Sets the Symbol to be used by this Renderer to draw Features/Graphics to the GeoView.

 


                                                                          更多内容,请关注公众号

                                                                

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yGIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值