Buzov / mytracks

Automatically exported from code.google.com/p/mytracks
0 stars 0 forks source link

multi color track path with gradient color on line draw on map #1416

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi MyTracks team,

I've downloaded the source code of mytracks and tried to add a new feature to 
the track path draw. This feature consist in the ability to draw the multicolor 
line of the path on the map with a gradient color based on the speed values. 
The color of the gradient starts at green goes to yellow then orange and stops 
at red.

In order to achieve that, for the moment, I rewrote the getColor(int speed) 
function from MutiColorTrackPath.java as in the code below:

protected int getColor(int speed) {
    if (speed <= trackPathDescriptor.getSlowSpeed()) {
        ArgbEvaluator ev = new ArgbEvaluator();
        return (Integer)ev.evaluate((float)speed/(float)trackPathDescriptor.getSlowSpeed(), slowColor, normalColor);
        //return slowColor;
    } else if (speed <= trackPathDescriptor.getNormalSpeed()) {
        ArgbEvaluator ev = new ArgbEvaluator();
        return (Integer)ev.evaluate((float)(speed - (float)trackPathDescriptor.getSlowSpeed()) / (float)trackPathDescriptor.getNormalSpeed(), normalColor, normalColor2);
        //return normalColor;
    } else {
        ArgbEvaluator ev = new ArgbEvaluator();
        return (Integer)ev.evaluate((float)(speed - trackPathDescriptor.getSlowSpeed()) / (float)speed, normalColor2, fastColor);
        //return fastColor;
    }
  }

 where the colors slowColor, normalColor, normalColor2 and fastColor are initialized in the MultiColorTrackPath constructor:
       slowColor = context.getResources().getColor(R.color.track_color_slow);
     normalColor = context.getResources().getColor(R.color.track_color_normal);
    normalColor2 = context.getResources().getColor(R.color.track_color_normal2);
       fastColor = context.getResources().getColor(R.color.track_color_fast);

and 
R.color.track_color_slow     - defined in colors.xml as green
R.color.track_color_normal   - defined in colors.xml as yellow
R.color.track_color_normal2  - defined in colors.xml as orange
R.color.track_color_fast     - defined in colors.xml as red

My Problem is that the map loads very slow (10 seconds with a track that has 
~2300 points and ~8km distance) and responds slow to gestures after the path is 
drawn as opposed to the case in which the path is single colored.
Does anyone has a better solution to this?
Will it be available a feature in the Android Google Maps Api v2 or future v3 
that will allow to set a gradient/shader to the PolylineOptions instead of 
single "int color" value?

Thanks,
Radian

Original issue reported on code.google.com by radian.p...@gmail.com on 30 Oct 2013 at 12:25

GoogleCodeExporter commented 9 years ago
Sorry there is a mistake in the code snipped:
in the last else it should be "return (Integer)ev.evaluate((float)(speed - 
trackPathDescriptor.getNormalSpeed()) / (float)speed, normalColor2, 
fastColor);" instead of "return (Integer)ev.evaluate((float)(speed - 
trackPathDescriptor.getSlowSpeed()) / (float)speed, normalColor2, fastColor);"

Original comment by radian.p...@gmail.com on 30 Oct 2013 at 12:27

GoogleCodeExporter commented 9 years ago
Hi,

I developed the initial implementation of the colored tracks and later wished 
too to implement a grandient option (as a replacement or as an alternative view 
for colored tracks). (Unluckily didnt had the time later).

I just saw your suggestion (thanks for the grandient logic ^^) and would like 
to give you two tips:

1-If you want the mytracks team to include your code suggestions you have to 
follow the development guide: 
https://code.google.com/p/mytracks/wiki/DevelopmentProcess (Altought it says 
deprecated, its the one i followed to submit code suggestions)

2- Could you try a new build with the following optimizations over your code 
and report back if it loads faster?

protected int getColor(int speed) {
    int slowsSpeed = trackPathDescriptor.getSlowSpeed();
    if (speed <= slowsSpeed) {
        ArgbEvaluator ev = new ArgbEvaluator();
        return (Integer)ev.evaluate((float)speed/(float)slowsSpeed, slowColor, normalColor);
        //return slowColor;
    } 
    int normalSpeed = trackPathDescriptor.getNormalSpeed()
    if (speed <= normalSpeed) {
        ArgbEvaluator ev = new ArgbEvaluator();
        return (Integer)ev.evaluate((float)(speed - (float)slowsSpeed) / (float)normalSpeed, normalColor, normalColor2);
        //return normalColor;
    } else {
        ArgbEvaluator ev = new ArgbEvaluator();
        return (Integer)ev.evaluate((float)(speed - normalSpeed) / (float)speed, normalColor2, fastColor);
        //return fastColor;
    }
  }

Original comment by ase...@gmail.com on 28 Jun 2014 at 4:26

GoogleCodeExporter commented 9 years ago
Thanks for the code. We will give it a try. If it is too slow, we will wait 
till the map view api provides ability to do this.

Original comment by jshih@google.com on 14 Oct 2014 at 8:19

GoogleCodeExporter commented 9 years ago
any progress on this?

Original comment by radian.p...@gmail.com on 23 Dec 2014 at 3:57