Ticket #494: gpx_draw.patch

File gpx_draw.patch, 2.7 KB (added by frank@…, 19 years ago)

Patch for fixing up the display of the GPS tracks

  • src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    old new  
    4343import org.openstreetmap.josm.actions.SaveAction;
    4444import org.openstreetmap.josm.actions.SaveAsAction;
    4545import org.openstreetmap.josm.actions.RenameLayerAction;
     46import org.openstreetmap.josm.data.coor.LatLon;
    4647import org.openstreetmap.josm.data.gpx.GpxData;
    4748import org.openstreetmap.josm.data.gpx.GpxTrack;
    4849import org.openstreetmap.josm.data.gpx.GpxRoute;
     
    229230                boolean large = Main.pref.getBoolean("draw.rawgps.large");
    230231
    231232                Point old = null;
     233                LatLon oldlatlon = null;
    232234                for (GpxTrack trk : data.tracks) {
    233235                        if (!forceLines) {
    234236                                old = null;
     
    237239                                for (WayPoint trkPnt : segment) {
    238240                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    239241                                        if (lines && old != null) {
    240                                                 g.drawLine(old.x, old.y, screen.x, screen.y);
     242                                                /* Calculate approximate line distance in meters */
     243                                                double d;
     244                                                d = Math.pow(trkPnt.latlon.lat()-oldlatlon.lat(),2) +
     245                                                    Math.pow(Math.cos(Math.toRadians(trkPnt.latlon.lat())),2) *
     246                                                    Math.pow(trkPnt.latlon.lon()-oldlatlon.lon(),2);
     247                                                d = Math.pow(d,0.5) * 111111.1;
     248                                                if(d<100.0)
     249                                                        g.drawLine(old.x, old.y, screen.x, screen.y);
    241250                                        } else if (!large) {
    242251                                                g.drawRect(screen.x, screen.y, 0, 0);
    243252                                        }
    244253                                        if (large)
    245254                                                g.fillRect(screen.x-1, screen.y-1, 3, 3);
    246255                                        old = screen;
     256                                        oldlatlon = trkPnt.latlon;
    247257                                }
    248258                        }
    249259                }
  • src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    old new  
    244244                else
    245245                        g.setColor(Color.GRAY);
    246246                Point old = null;
     247                LatLon oldlatlon = null;
    247248
    248249                boolean force = Main.pref.getBoolean("draw.rawgps.lines.force");
    249250                boolean lines = Main.pref.getBoolean("draw.rawgps.lines");
     
    256257                                old = null;
    257258                        for (GpsPoint p : c) {
    258259                                Point screen = mv.getPoint(p.eastNorth);
    259                                 if (lines && old != null)
    260                                         g.drawLine(old.x, old.y, screen.x, screen.y);
     260                                if (lines && old != null) {
     261                                        /* Calculate approximate line distance in meters */
     262                                        double d;
     263                                        d = Math.pow(p.latlon.lat()-oldlatlon.lat(),2) +
     264                                            Math.pow(Math.cos(Math.toRadians(p.latlon.lat())),2) *
     265                                            Math.pow(p.latlon.lon()-oldlatlon.lon(),2);
     266                                        d = Math.pow(d,0.5) * 111111.1;
     267                                        if(d<100.0)
     268                                                g.drawLine(old.x, old.y, screen.x, screen.y);
     269                                }
    261270                                else if (!large)
    262271                                        g.drawRect(screen.x, screen.y, 0, 0);
    263272                                if (large)
    264273                                        g.fillRect(screen.x-1, screen.y-1, 3, 3);
    265274                                old = screen;
     275                                oldlatlon = p.latlon;
    266276                        }
    267277                }
    268278        }