Ticket #6540: gpx_color_direction.2--color-mod.patch

File gpx_color_direction.2--color-mod.patch, 6.4 KB (added by bastiK, 23 months ago)
  • src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/GpxLayer.java b/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
    index 1443089..df042d8 100644
    a b import org.openstreetmap.josm.tools.DateUtils; 
    7777import org.openstreetmap.josm.tools.GBC; 
    7878import org.openstreetmap.josm.tools.ImageProvider; 
    7979import org.openstreetmap.josm.tools.UrlLabel; 
     80import org.openstreetmap.josm.tools.Utils; 
    8081 
    8182public class GpxLayer extends Layer { 
    8283 
    public class GpxLayer extends Layer { 
    310311        } 
    311312    } 
    312313 
     314    private final static Color[] colors_cyclic = new Color[256]; 
     315    static { 
     316        for (int i = 0; i < colors_cyclic.length; i++) { 
     317            //                    red   yellow  green   blue    red 
     318            int[] h = new int[] { 0,    59,     127,    244,    360}; 
     319            int[] s = new int[] { 100,  84,     99,     100 }; 
     320            int[] b = new int[] { 90,   93,     74,     83 }; 
     321 
     322            float angle = i / 256f * 4; 
     323            int sector = (int) angle; 
     324            angle -= sector; 
     325            sector = Utils.mod(sector+1, 4); 
     326 
     327            float vh = h[sector] * w(angle) + h[sector+1] * w(1-angle); 
     328            float vs = s[sector] * w(angle) + s[Utils.mod(sector+1, 4)] * w(1-angle); 
     329            float vb = b[sector] * w(angle) + b[Utils.mod(sector+1, 4)] * w(1-angle); 
     330 
     331            colors_cyclic[i] = Color.getHSBColor(vh/360f, vs/100f, vb/100f); 
     332        } 
     333    } 
     334 
     335    /** 
     336     * weight function:  
     337     *  w(0)=1, w(1)=0, 0<=w(x)<=1, w(x)+w(1-x)==1 
     338     * @param x number: 0<=x<=1 
     339     * @return the weighted value 
     340     */ 
     341    private static float w(float x) { 
     342        if (x < 0.5) { 
     343            return 1-4*x*x*x; 
     344        } else { 
     345            return 4*(1-x)*(1-x)*(1-x); 
     346        } 
     347    } 
     348     
    313349    // lookup array to draw arrows without doing any math 
    314350    private static int ll0 = 9; 
    315351    private static int sl4 = 5; 
    public class GpxLayer extends Layer { 
    321357 
    322358    // the different color modes 
    323359    enum colorModes { 
    324         none, velocity, dilution 
     360        none, velocity, dilution, direction 
    325361    } 
    326362 
    327363    @Override 
    public class GpxLayer extends Layer { 
    429465                                } 
    430466                                break; 
    431467 
     468                            case direction: 
     469                                // unfortunately "heading" misses a cos-factor in the 
     470                                // longitudes to account for the convergence of meridians 
     471                                double dirColor = oldWp.getCoor().heading(trkPnt.getCoor()) / (2.0 * Math.PI) * 256; 
     472                                // Bad case first 
     473                                if (dirColor != dirColor || dirColor < 0.0 || dirColor >= 256.0) { 
     474                                    trkPnt.customColoring = colors_cyclic[0]; 
     475                                } else { 
     476                                    trkPnt.customColoring = colors_cyclic[(int) (dirColor)]; 
     477                                } 
     478                                break; 
    432479                            case dilution: 
    433480                                if (trkPnt.attr.get("hdop") != null) { 
    434481                                    float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue(); 
  • src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    diff --git a/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java b/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java
    index 785026d..69fdd14 100644
    a b public class DrawingPreference implements PreferenceSetting { 
    4444    private JCheckBox hdopCircleGpsPoints = new JCheckBox(tr("Draw a circle form HDOP value.")); 
    4545    private ButtonGroup colorGroup; 
    4646    private JRadioButton colorTypeVelocity = new JRadioButton(tr("Velocity (red = slow, green = fast)")); 
     47    private JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = north, purple = west)")); 
    4748    private JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)")); 
    4849    private JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)")); 
    4950    private JComboBox colorTypeVelocityTune = new JComboBox(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")}); 
    public class DrawingPreference implements PreferenceSetting { 
    169170        colorGroup = new ButtonGroup(); 
    170171        colorGroup.add(colorTypeNone); 
    171172        colorGroup.add(colorTypeVelocity); 
     173        colorGroup.add(colorTypeDirection); 
    172174        colorGroup.add(colorTypeDilution); 
    173175 
    174176        colorTypeVelocity.addChangeListener(new ChangeListener(){ 
    public class DrawingPreference implements PreferenceSetting { 
    187189        case 2: 
    188190            colorTypeDilution.setSelected(true); 
    189191            break; 
     192        case 3: 
     193            colorTypeDirection.setSelected(true); 
     194            break; 
    190195        } 
    191196 
    192197        colorTypeNone.setToolTipText(tr("All points and track segments will have the same color. Can be customized in Layer Manager.")); 
    193198        colorTypeVelocity.setToolTipText(tr("Colors points and track segments by velocity.")); 
     199        colorTypeDirection.setToolTipText(tr("Colors points and track segments by direction.")); 
    194200        colorTypeDilution.setToolTipText(tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information.")); 
    195201 
    196202        // color Tracks by Velocity Tune 
    public class DrawingPreference implements PreferenceSetting { 
    205211        panel.add(colorTypeNone, GBC.eol().insets(40,0,0,0)); 
    206212        panel.add(colorTypeVelocity, GBC.std().insets(40,0,0,0)); 
    207213        panel.add(colorTypeVelocityTune, GBC.eop().insets(5,0,0,5)); 
     214        panel.add(colorTypeDirection, GBC.eol().insets(40,0,0,0)); 
    208215        panel.add(colorTypeDilution, GBC.eol().insets(40,0,0,0)); 
    209216 
    210217        // waypointLabel 
    public class DrawingPreference implements PreferenceSetting { 
    299306            Main.pref.putInteger("draw.rawgps.colors", 1); 
    300307        } else if(colorTypeDilution.isSelected()) { 
    301308            Main.pref.putInteger("draw.rawgps.colors", 2); 
     309        } else if(colorTypeDirection.isSelected()) { 
     310            Main.pref.putInteger("draw.rawgps.colors", 3); 
    302311        } else { 
    303312            Main.pref.putInteger("draw.rawgps.colors", 0); 
    304313        }