ArcGIS Runtime SDK for Android Learning (11): Symbol Renderer (2)

Keywords: Android SDK

In Android Learning (10): Symbol Rendering through SimpleRendererl (Part I) In this paper, the Renderer Renderer is introduced briefly, and the point element is taken as an example to explain the method of using SimpleRenderer to render points. This paper mainly talks about the way of using SimpleRenderer to render line and surface elements besides the point element.

Implementation steps:

1. Create an Android project

2. Adding Runtime SDK dependencies

3. Adding permissions and OpenGL ES support

The first three steps are omitted. Beginners can refer to them. ArcGIS Runtime SDK for Android Learning Notes (1): First Map Application (2-D)

4. Setting up the interface layout

Add:

    <!-- MapView control -->
    <com.esri.arcgisruntime.mapping.view.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </com.esri.arcgisruntime.mapping.view.MapView>

5. Write code:

Idea: Create Graphics (Graphics) by geometric objects (Point, Polyline, Polygon...), Renderer (Renderer) by Symbol (Symbol), and then pass Graphics to Graphics Overlay to provide graphics, Renderer to Graphics Overlay to complete the unified rendering of graphics.

Steps:

(1) In Activity's onCreate:

        // Getting MapView Control through Layout
        mMapView = (MapView) findViewById(R.id.mapView);
        //Creating Map Objects with Topographic Map as Base Map
        ArcGISMap mMap = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 15.169193, 16.333479, 2);
        // Add Graphics Overlay after rendering
        addGraphicsOverlay();
        // Setting up the map to display in MapView control
        mMapView.setMap(mMap);

(2) Method of rendering:

private void addGraphicsOverlay(){
        // Point element
        Point pointGeometry = new Point(40e5, 40e5, SpatialReferences.getWebMercator());
        // Set simple symbols, red
        SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.DIAMOND, Color.RED, 10);
        // New graphic
        Graphic pointGraphic = new Graphic(pointGeometry);
        // Create a Point Set Layer Graphics Overlay
        GraphicsOverlay pointGraphicOverlay = new GraphicsOverlay();
        // Create a simple renderer
        SimpleRenderer pointRenderer = new SimpleRenderer(pointSymbol);
        pointGraphicOverlay.setRenderer(pointRenderer);
        // Add Graphic to Graphics Overlay
        pointGraphicOverlay.getGraphics().add(pointGraphic);

        // Add to MapView display
        mMapView.getGraphicsOverlays().add(pointGraphicOverlay);

        // Line Graphics
        PolylineBuilder lineGeometry = new PolylineBuilder(SpatialReferences.getWebMercator());
        lineGeometry.addPoint(-10e5, 40e5);
        lineGeometry.addPoint(20e5, 50e5);
        // Blue Solid Line Symbol
        SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 5);
        // Creating Multilinear Graphics Objects
        Graphic lineGraphic = new Graphic(lineGeometry.toGeometry());
        // Create Graphic Overlay for Multiline
        GraphicsOverlay lineGraphicOverlay = new GraphicsOverlay();
        // Create simple renderer
        SimpleRenderer lineRenderer = new SimpleRenderer(lineSymbol);
        // Add renderer to Graphic Overlay
        lineGraphicOverlay.setRenderer(lineRenderer);
        // Add graphics to graphic Overlay
        lineGraphicOverlay.getGraphics().add(lineGraphic);
        // Add Graphics Overlay to MapView
        mMapView.getGraphicsOverlays().add(lineGraphicOverlay);

        //Polygon graphics
        PolygonBuilder polygonGeometry = new PolygonBuilder(SpatialReferences.getWebMercator());
        polygonGeometry.addPoint(-20e5, 20e5);
        polygonGeometry.addPoint(20e5, 20e5);
        polygonGeometry.addPoint(20e5, -20e5);
        polygonGeometry.addPoint(-20e5, -20e5);
        // Yellow Solid Polygon Symbol
        SimpleFillSymbol polygonSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, null);
        //Create Graphic for Polygons
        Graphic polygonGraphic = new Graphic(polygonGeometry.toGeometry());
        //Create Graphic Overlay for Polygons
        GraphicsOverlay polygonGraphicOverlay = new GraphicsOverlay();
        // Create simple renderer
        SimpleRenderer polygonRenderer = new SimpleRenderer(polygonSymbol);
        // Add renderer to Graphic Overlay
        polygonGraphicOverlay.setRenderer(polygonRenderer);
        // Add graphics to graphic Overlay
        polygonGraphicOverlay.getGraphics().add(polygonGraphic);
        // Add Graphics Overlay to MapView
        mMapView.getGraphicsOverlays().add(polygonGraphicOverlay);

    }

6. Running APP: You can view the result of symbol rendering

Posted by balistic on Mon, 04 Feb 2019 14:51:15 -0800