Select to view content in your preferred language

How to Draw a track where a vehicle has gone

3516
2
Jump to solution
09-04-2014 01:43 PM
WillyanSchultz_Dworak
New Contributor

I am developing a GPS application for use in precision agriculture. I need to save the path where the vehicle passed. The drawing must contain the width of the vehicle. I tried using:

gpsLayer.setTrailSymbol(new SimpleLineSymbol(new Color(200, 0, 0, 160), 20));

But the problem is that the polylines are disconnected, therefore remain gaps in the track.

Trail_ArcGIS.jpg

I need to track is equal to an automotive GPS. Does anyone have any idea how to do it?

Thank you

0 Kudos
1 Solution

Accepted Solutions
VijayGandhi
New Contributor III

I suggest you create a GraphicsLayer that contains the trail Graphic, and turn off trail in the GPSLayer.

You could add a listener to the GPSWatcher that is passed on the GPSLayer. Whenever the position changes you could update the trail Graphic's geometry.

The trail Graphic could be of type Polyline, and you could append new position to it. Something like this:

private Polyline trail = null;

private int trailGraphicId;

// on position change

if (trail == null) {

    trail = new Polyline();

    trail.startPath(prevLocationOnMap);

    trail.lineTo(currLocationOnMap);

    Graphic trailGraphic = new Graphic(trail, symTrail);

    trailGraphicId = graphicsLayer.addGraphic(trailGraphic);

} else {

    trail.lineTo(currLocationOnMap);

    graphicsLayer.updateGraphic(trailGraphicId, trail);

  }

Output will now look like

gps_trail.png

View solution in original post

0 Kudos
2 Replies
VijayGandhi
New Contributor III

I suggest you create a GraphicsLayer that contains the trail Graphic, and turn off trail in the GPSLayer.

You could add a listener to the GPSWatcher that is passed on the GPSLayer. Whenever the position changes you could update the trail Graphic's geometry.

The trail Graphic could be of type Polyline, and you could append new position to it. Something like this:

private Polyline trail = null;

private int trailGraphicId;

// on position change

if (trail == null) {

    trail = new Polyline();

    trail.startPath(prevLocationOnMap);

    trail.lineTo(currLocationOnMap);

    Graphic trailGraphic = new Graphic(trail, symTrail);

    trailGraphicId = graphicsLayer.addGraphic(trailGraphic);

} else {

    trail.lineTo(currLocationOnMap);

    graphicsLayer.updateGraphic(trailGraphicId, trail);

  }

Output will now look like

gps_trail.png

0 Kudos
WillyanSchultz_Dworak
New Contributor

Thanks VGandhi-esristaff,

Your answer solved my problem 

0 Kudos