(二)arcgis runtime for android 100.3开发学习(图形、绘制图层创建)

65 篇文章 29 订阅
19 篇文章 0 订阅

今天我们来学习一下有关新版arcgis for android 100.3里面绘制图层,和定义图层符号。这里代码摘自esri在github公布的源代码,这个例子中线条可以根据地图的的缩放展示流动的效果,看了一下绘制的面填充中的格网也随着地图的缩放在不断的细分,这个例子对于学习arcgis for android绘图图层和图形是比较基础的。下面看一下实现效果。

这是实现的源代码。

package com.example.arcroid.addgraphicssymbols;

import android.app.Activity;
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.PointCollection;
import com.esri.arcgisruntime.geometry.Polygon;
import com.esri.arcgisruntime.geometry.Polyline;
import com.esri.arcgisruntime.geometry.SpatialReference;
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.TextSymbol;

import java.util.Map;

public class MainActivity extends Activity {

    private MapView mapview;
    private final SpatialReference wgs84 = SpatialReference.create(4326);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapview=findViewById(R.id.mapview);

        ArcGISMap map = new ArcGISMap(Basemap.Type.OCEANS, 56.075844,
                -2.681572, 11);

        mapview.setMap(map);

        GraphicsOverlay graphicsOverlay = addGraphicsOverlay(mapview);

        addBuoyPoints(graphicsOverlay);

        addBoatTrip(graphicsOverlay);

        addNestingGround(graphicsOverlay);

        addText(graphicsOverlay);

    }

    private GraphicsOverlay addGraphicsOverlay(MapView mapView) {

        GraphicsOverlay graphicsOverlay = new GraphicsOverlay();

        mapView.getGraphicsOverlays().add(graphicsOverlay);
        return graphicsOverlay;
    }

    private void addBuoyPoints(GraphicsOverlay graphicOverlay) {
        //定义浮标点
        Point buoy1Loc = new Point(-2.712642647560347, 56.062812566811544, wgs84);
        Point buoy2Loc = new Point(-2.6908416959572303, 56.06444173689877, wgs84);
        Point buoy3Loc = new Point(-2.6697273884990937, 56.064250073402874, wgs84);
        Point buoy4Loc = new Point(-2.6395150461199726, 56.06127916736989, wgs84);
        //创建符号
        SimpleMarkerSymbol buoyMarker = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
        //创建图形
        Graphic buoyGraphic1 = new Graphic(buoy1Loc, buoyMarker);
        Graphic buoyGraphic2 = new Graphic(buoy2Loc, buoyMarker);
        Graphic buoyGraphic3 = new Graphic(buoy3Loc, buoyMarker);
        Graphic buoyGraphic4 = new Graphic(buoy4Loc, buoyMarker);
        //将图形添加到绘制图层
        graphicOverlay.getGraphics().add(buoyGraphic1);
        graphicOverlay.getGraphics().add(buoyGraphic2);
        graphicOverlay.getGraphics().add(buoyGraphic3);
        graphicOverlay.getGraphics().add(buoyGraphic4);
    }

    private void addText(GraphicsOverlay graphicOverlay) {

        Point bassLocation = new Point(-2.640631, 56.078083, wgs84);
        Point craigleithLocation = new Point(-2.720324, 56.073569, wgs84);


        TextSymbol bassRockSymbol =
                new TextSymbol(10, "Bass Rock", Color.rgb(0, 0, 230),
                        TextSymbol.HorizontalAlignment.LEFT, TextSymbol.VerticalAlignment.BOTTOM);
        TextSymbol craigleithSymbol = new TextSymbol(10, "Craigleith", Color.rgb(0, 0, 230),
                TextSymbol.HorizontalAlignment.RIGHT, TextSymbol.VerticalAlignment.TOP);


        Graphic bassRockGraphic = new Graphic(bassLocation, bassRockSymbol);
        Graphic craigleithGraphic = new Graphic(craigleithLocation, craigleithSymbol);

        graphicOverlay.getGraphics().add(bassRockGraphic);
        graphicOverlay.getGraphics().add(craigleithGraphic);
    }

    private void addBoatTrip(GraphicsOverlay graphicOverlay) {

        Polyline boatRoute = getBoatTripGeometry();

        SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(128, 0, 128), 4);

        Graphic boatTripGraphic = new Graphic(boatRoute, lineSymbol);

        graphicOverlay.getGraphics().add(boatTripGraphic);
    }

    private void addNestingGround(GraphicsOverlay graphicOverlay) {

        Polygon nestingGround = getNestingGroundGeometry();

        SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(0, 0, 128), 1);
        SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.DIAGONAL_CROSS, Color.rgb(0, 80, 0),
                outlineSymbol);

        Graphic nestingGraphic = new Graphic(nestingGround, fillSymbol);

        graphicOverlay.getGraphics().add(nestingGraphic);
    }

    private Polyline getBoatTripGeometry() {
        //创建点集,用于绘制折线
        PointCollection boatPositions = new PointCollection(wgs84);

        boatPositions.add(new Point(-2.7184791227926772, 56.06147084563517));
        boatPositions.add(new Point(-2.7196807500463924, 56.06147084563517));
        boatPositions.add(new Point(-2.722084004553823, 56.062141712059706));
        boatPositions.add(new Point(-2.726375530459948, 56.06386674355254));
        boatPositions.add(new Point(-2.726890513568683, 56.0660708381432));
        boatPositions.add(new Point(-2.7270621746049275, 56.06779569383808));
        boatPositions.add(new Point(-2.7255172252787228, 56.068753913653914));
        boatPositions.add(new Point(-2.723113970771293, 56.069424653352335));
        boatPositions.add(new Point(-2.719165766937657, 56.07028701581465));
        boatPositions.add(new Point(-2.713672613777817, 56.070574465681325));
        boatPositions.add(new Point(-2.7093810878716917, 56.07095772883556));
        boatPositions.add(new Point(-2.7044029178205866, 56.07153261642126));
        boatPositions.add(new Point(-2.698223120515766, 56.072394931722265));
        boatPositions.add(new Point(-2.6923866452834355, 56.07325722773041));
        boatPositions.add(new Point(-2.68672183108735, 56.07335303720707));
        boatPositions.add(new Point(-2.6812286779275096, 56.07354465544585));
        boatPositions.add(new Point(-2.6764221689126497, 56.074215311778964));
        boatPositions.add(new Point(-2.6698990495353394, 56.07488595644139));
        boatPositions.add(new Point(-2.6647492184479886, 56.075748196715914));
        boatPositions.add(new Point(-2.659427726324393, 56.076131408423215));
        boatPositions.add(new Point(-2.654792878345778, 56.07622721075461));
        boatPositions.add(new Point(-2.651359657620878, 56.076514616319784));
        boatPositions.add(new Point(-2.6477547758597324, 56.07708942101955));
        boatPositions.add(new Point(-2.6450081992798125, 56.07814320736718));
        boatPositions.add(new Point(-2.6432915889173625, 56.08025069360931));
        boatPositions.add(new Point(-2.638656740938747, 56.08044227755186));
        boatPositions.add(new Point(-2.636940130576297, 56.078813783674946));
        boatPositions.add(new Point(-2.636425147467562, 56.07728102068079));
        boatPositions.add(new Point(-2.637798435757522, 56.076610417698504));
        boatPositions.add(new Point(-2.638656740938747, 56.07507756705851));
        boatPositions.add(new Point(-2.641231656482422, 56.07479015077557));
        boatPositions.add(new Point(-2.6427766058086277, 56.075748196715914));
        boatPositions.add(new Point(-2.6456948434247924, 56.07546078543464));
        boatPositions.add(new Point(-2.647239792750997, 56.074598538729404));
        boatPositions.add(new Point(-2.6492997251859376, 56.072682365868616));
        boatPositions.add(new Point(-2.6530762679833284, 56.0718200569986));
        boatPositions.add(new Point(-2.655479522490758, 56.070861913404286));
        boatPositions.add(new Point(-2.6587410821794135, 56.07047864929729));
        boatPositions.add(new Point(-2.6633759301580286, 56.07028701581465));
        boatPositions.add(new Point(-2.666637489846684, 56.07009538137926));
        boatPositions.add(new Point(-2.670070710571584, 56.06990374599109));
        boatPositions.add(new Point(-2.6741905754414645, 56.069137194910745));
        boatPositions.add(new Point(-2.678310440311345, 56.06808316228391));
        boatPositions.add(new Point(-2.682086983108735, 56.06789151689155));
        boatPositions.add(new Point(-2.6868934921235956, 56.06760404701653));
        boatPositions.add(new Point(-2.6911850180297208, 56.06722075051504));
        boatPositions.add(new Point(-2.695133221863356, 56.06702910083509));
        boatPositions.add(new Point(-2.698223120515766, 56.066837450202335));
        boatPositions.add(new Point(-2.7016563412406667, 56.06645414607839));
        boatPositions.add(new Point(-2.7061195281830366, 56.0660708381432));
        boatPositions.add(new Point(-2.7100677320166717, 56.065591697864576));
        boatPositions.add(new Point(-2.713329291705327, 56.06520838135397));
        boatPositions.add(new Point(-2.7167625124302273, 56.06453756828941));
        boatPositions.add(new Point(-2.718307461756433, 56.06348340989081));
        boatPositions.add(new Point(-2.719165766937657, 56.062812566811544));
        boatPositions.add(new Point(-2.7198524110826376, 56.06204587471371));
        boatPositions.add(new Point(-2.719165766937657, 56.06166252294756));
        boatPositions.add(new Point(-2.718307461756433, 56.06147084563517));


        return new Polyline(boatPositions);
    }

    private Polygon getNestingGroundGeometry() {

        //创建点集,用于创建面
        PointCollection points = new PointCollection(wgs84);


        points.add(new Point(-2.643077012566659, 56.077125346044475));
        points.add(new Point(-2.6428195210159444, 56.07717324600376));
        points.add(new Point(-2.6425405718360033, 56.07774804087097));
        points.add(new Point(-2.6427122328698127, 56.077927662508635));
        points.add(new Point(-2.642454741319098, 56.07829887790651));
        points.add(new Point(-2.641853927700763, 56.078526395253725));
        points.add(new Point(-2.6409741649024867, 56.078801809192434));
        points.add(new Point(-2.6399871139580795, 56.07881378366685));
        points.add(new Point(-2.6394077579689705, 56.07908919555142));
        points.add(new Point(-2.638764029092183, 56.07917301616904));
        points.add(new Point(-2.638485079912242, 56.07896945149566));
        points.add(new Point(-2.638570910429147, 56.078203080726844));
        points.add(new Point(-2.63878548672141, 56.077568418396));
        points.add(new Point(-2.6391931816767085, 56.077197195961084));
        points.add(new Point(-2.6399441986996273, 56.07675411934114));
        points.add(new Point(-2.6406523004640934, 56.076730169108444));
        points.add(new Point(-2.6406737580933193, 56.07632301287509));
        points.add(new Point(-2.6401802326211157, 56.075999679860494));
        points.add(new Point(-2.6402446055087943, 56.075844000034046));
        points.add(new Point(-2.640416266542604, 56.07578412301025));
        points.add(new Point(-2.6408883343855822, 56.075808073830935));
        points.add(new Point(-2.6417680971838577, 56.076239186057734));
        points.add(new Point(-2.642197249768383, 56.076251161328514));
        points.add(new Point(-2.6428409786451708, 56.07661041772168));
        points.add(new Point(-2.643077012566659, 56.077125346044475));


        return new Polygon(points);
    }

}

下面来看是这其中涉及到的api接口,有SimpleMarkerSymbol、SimpleLineSymbol、SimpleFillSymbol、TextSymbol。

看有关SimpleMarkerSymbol函数。

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.

SimpleLineSymbol有关函数:

Public Methods
SimpleLineSymbol.MarkerPlacementgetMarkerPlacement()

Gets the marker placement type for this symbol.

SimpleLineSymbol.MarkerStylegetMarkerStyle()

Gets the marker style for this symbol.

SimpleLineSymbol.StylegetStyle()

Gets the line style that describes how the symbol's pattern is being displayed.

voidsetMarkerPlacement(SimpleLineSymbol.MarkerPlacement markerPlacement)

Sets the marker placement type for this symbol.

voidsetMarkerStyle(SimpleLineSymbol.MarkerStyle markerStyle)

Sets the marker style for this symbol.

voidsetStyle(SimpleLineSymbol.Style style)

Sets the line style that describes how this Symbol's pattern will be displayed.

有关SimpleFillSymbol的函数:

Public Methods
SimpleLineSymbol.MarkerPlacementgetMarkerPlacement()

Gets the marker placement type for this symbol.

SimpleLineSymbol.MarkerStylegetMarkerStyle()

Gets the marker style for this symbol.

SimpleLineSymbol.StylegetStyle()

Gets the line style that describes how the symbol's pattern is being displayed.

voidsetMarkerPlacement(SimpleLineSymbol.MarkerPlacement markerPlacement)

Sets the marker placement type for this symbol.

voidsetMarkerStyle(SimpleLineSymbol.MarkerStyle markerStyle)

Sets the marker style for this symbol.

voidsetStyle(SimpleLineSymbol.Style style)

Sets the line style that describes how this Symbol's pattern will be displayed.

有关TextSymbol的函数:

Public Methods
intgetBackgroundColor()

Gets the background color of this TextSymbol as an ARGB(alpha, red, green, blue) color value.

intgetColor()

Gets the color of this TextSymbol as an ARGB(alpha, red, green, blue) color value.

TextSymbol.FontDecorationgetFontDecoration()

Gets the decoration being used by this Symbol's text.

StringgetFontFamily()

Gets the FontFamily being used by this Symbol's text.

TextSymbol.FontStylegetFontStyle()

Gets the FontStyle of the text that is being used by this Symbol.

TextSymbol.FontWeightgetFontWeight()

Gets the FontWeight of the text being displayed by this Symbol.

intgetHaloColor()

Gets the halo color as an ARGB(alpha, red, green, blue) color value.

floatgetHaloWidth()

Gets the width of the halo in density-independent pixels (dp).

TextSymbol.HorizontalAlignmentgetHorizontalAlignment()

Gets the horizontal alignment of the text relative to the Symbol's mid-point location.

intgetOutlineColor()

Gets the outline color as an ARGB(alpha, red, green, blue) color value.

floatgetOutlineWidth()

Gets the width of the outline in density-independent pixels (dp).

floatgetSize()

Gets the Symbol's text size in density-independent pixels (dp).

StringgetText()

Gets the text displayed by this Symbol.

TextSymbol.VerticalAlignmentgetVerticalAlignment()

Gets the vertical alignment of the text relative to the Symbol's mid-point location.

voidsetBackgroundColor(int color)

Sets the background color of this TextSymbol using an ARGB(alpha, red, green, blue) color value.

voidsetColor(int color)

Sets the color of this TextSymbol using an ARGB(alpha, red, green, blue) color value.

voidsetFontDecoration(TextSymbol.FontDecoration fontDecoration)

Sets the decoration for the text being used by this Symbol.

voidsetFontFamily(String fontFamily)

Sets the FontFamily for the text being used by this Symbol.

voidsetFontStyle(TextSymbol.FontStyle fontStyle)

Sets the FontStyle for the text that is being used by this Symbol.

voidsetFontWeight(TextSymbol.FontWeight fontWeight)

Sets the FontWeight for the text that is being used by this Symbol.

voidsetHaloColor(int haloColor)

Sets the halo color using an ARGB(alpha, red, green, blue) color value.

voidsetHaloWidth(float haloWidth)

Sets the width of the halo in density-independent pixels (dp).

voidsetHorizontalAlignment(TextSymbol.HorizontalAlignment horizontalAlignment)

Sets the horizontal alignment of the text relative to the Symbol's mid-point location.

voidsetOutlineColor(int outlineColor)

Sets the outline color using an ARGB(alpha, red, green, blue) color value.

voidsetOutlineWidth(float outlineWidth)

Sets the width of the outline in density-independent pixels (dp).

voidsetSize(float size)

Sets the size of the text in density-independent pixels (dp).

voidsetText(String text)

Sets the text displayed by this Symbol.

voidsetVerticalAlignment(TextSymbol.VerticalAlignment verticalAlignment)

Sets the vertical alignment of the text relative to the Symbol's mid-point location.


                                                                                  更多内容,请关注公众号

                                                                         

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

yGIS

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

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

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

打赏作者

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

抵扣说明:

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

余额充值