Line with an arrow head

793
2
Jump to solution
11-10-2021 11:14 PM
VanyaIvanov
Occasional Contributor

I want to draw a line with an arrow on the end. 

            PointCollection polylinePoints = new PointCollection(SpatialReferences.getWgs84());
polylinePoints.add(new Point(10, 10));
polylinePoints.add(new Point(20, 20));

Polyline polyline = new Polyline(polylinePoints);

SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID,
0xFF0063FF, 7, SimpleLineSymbol.MarkerStyle.ARROW, SimpleLineSymbol.MarkerPlacement.END);

Graphic polylineGraphic = new Graphic(polyline, lineSymbol);

//as i read the sceneView should be in Static rendering mode for using SimpleLineSymbol.MarkerStyle.ARROW
sceneView.getArcGISScene().getLoadSettings().setPreferredPolylineFeatureRenderingMode(FeatureLayer.RenderingMode.STATIC);
sceneView.getArcGISScene().getLoadSettings().setPreferredPointFeatureRenderingMode(FeatureLayer.RenderingMode.STATIC);
sceneView.getArcGISScene().getLoadSettings().setPreferredPolygonFeatureRenderingMode(FeatureLayer.RenderingMode.STATIC);

graphicsOverlay.getGraphics().add(polylineGraphic);

But it doen't work. Line is drawn but without arrow on its head

VanyaIvanov_0-1636614749331.png

How to draw a line with an arrow on the Scene using arcgis runtime api for Java?

0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor

I can see the problem here, the rendering mode for a GraphicsOverlay is set when you instantiate it.  The default constructor will set it in DYNAMIC, but there is an overload which allows you to set this yourself.

The code you've written for changing the rendering mode is for feature layers.

Using the following code, I've managed to render your arrowhead:

      PointCollection polylinePoints = new PointCollection(SpatialReferences.getWgs84());
      polylinePoints.add(new Point(10, 10));
      polylinePoints.add(new Point(20, 20));

      Polyline polyline = new Polyline(polylinePoints);

      SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID,
          0xFF0063FF, 7, SimpleLineSymbol.MarkerStyle.ARROW, SimpleLineSymbol.MarkerPlacement.END);

      Graphic polylineGraphic = new Graphic(polyline, lineSymbol);

      GraphicsOverlay graphicsOverlay = new GraphicsOverlay(GraphicsOverlay.RenderingMode.STATIC);
      sceneView.getGraphicsOverlays().add(graphicsOverlay);

      graphicsOverlay.getGraphics().add(polylineGraphic);

MarkBaird_0-1636627456000.png

I am however going to look at  making the arrow head to render in the dynamic rendering mode for a future release.

Does this help?

 

View solution in original post

0 Kudos
2 Replies
MarkBaird
Esri Regular Contributor

I can see the problem here, the rendering mode for a GraphicsOverlay is set when you instantiate it.  The default constructor will set it in DYNAMIC, but there is an overload which allows you to set this yourself.

The code you've written for changing the rendering mode is for feature layers.

Using the following code, I've managed to render your arrowhead:

      PointCollection polylinePoints = new PointCollection(SpatialReferences.getWgs84());
      polylinePoints.add(new Point(10, 10));
      polylinePoints.add(new Point(20, 20));

      Polyline polyline = new Polyline(polylinePoints);

      SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID,
          0xFF0063FF, 7, SimpleLineSymbol.MarkerStyle.ARROW, SimpleLineSymbol.MarkerPlacement.END);

      Graphic polylineGraphic = new Graphic(polyline, lineSymbol);

      GraphicsOverlay graphicsOverlay = new GraphicsOverlay(GraphicsOverlay.RenderingMode.STATIC);
      sceneView.getGraphicsOverlays().add(graphicsOverlay);

      graphicsOverlay.getGraphics().add(polylineGraphic);

MarkBaird_0-1636627456000.png

I am however going to look at  making the arrow head to render in the dynamic rendering mode for a future release.

Does this help?

 

0 Kudos
VanyaIvanov
Occasional Contributor

Thank you Mark! it works!

0 Kudos