Changeset 15560 in josm for trunk


Ignore:
Timestamp:
2019-12-07T16:38:26+01:00 (5 years ago)
Author:
GerdP
Message:

fix #18389: GPX track with color black is invisible (Patch by Bjoeni)
Show popup that track is not visible because color matches backgroud color. This shows a popup only if

  • background color of all tracks in the file equals background color and
  • no imagery layer is currently visible

"I noticed that Garmin actually uses gpxx:TrackExtension instead of gpxx:TrackExtensions, so the abbreviations don't work and files are sometimes not written according to the standard."

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxConstants.java

    r15496 r15560  
    239239    static Map<String, String> getExtensionAbbreviations() {
    240240        TreeMap<String, String> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    241         m.put("gpx:extension:gpxx:TrackExtensions:DisplayColor", "gpxx:DisplayColor");
     241        m.put("gpx:extension:gpxx:TrackExtension:DisplayColor", "gpxx:DisplayColor");
    242242        m.put("gpx:extension:gpxd:color", "gpxd:color");
    243243        return m;
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxExtensionCollection.java

    r15497 r15560  
    148148    /**
    149149     * Adds an extension from a flat chain without prefix, e.g. when converting from OSM
    150      * @param chain the full key chain, e.g. ["extension", "gpxx", "TrackExtensions", "DisplayColor"]
     150     * @param chain the full key chain, e.g. ["extension", "gpxx", "TrackExtension", "DisplayColor"]
    151151     * @param value the value
    152152     */
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxTrack.java

    r15497 r15560  
    170170                }
    171171                closestGarminColorCache.put(c, colorString);
    172                 getExtensions().addIfNotPresent("gpxx", "TrackExtensions").getExtensions().addOrUpdate("gpxx", "DisplayColor", colorString);
     172                getExtensions().addIfNotPresent("gpxx", "TrackExtension").getExtensions().addOrUpdate("gpxx", "DisplayColor", colorString);
    173173            } else if (cFormat == ColorFormat.GPXD) {
    174174                setColor(c);
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/GpxImporter.java

    r15496 r15560  
    1313import org.openstreetmap.josm.data.gpx.GpxData;
    1414import org.openstreetmap.josm.gui.MainApplication;
     15import org.openstreetmap.josm.gui.Notification;
    1516import org.openstreetmap.josm.gui.layer.GpxLayer;
     17import org.openstreetmap.josm.gui.layer.ImageryLayer;
     18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1619import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
    1720import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    154157            }
    155158        }
     159
     160        final boolean isSameColor = MainApplication.getLayerManager()
     161                .getLayersOfType(ImageryLayer.class)
     162                .stream().noneMatch(ImageryLayer::isVisible)
     163                && data.getTracks().stream().anyMatch(t -> OsmDataLayer.getBackgroundColor().equals(t.getColor()));
     164
    156165        Runnable postLayerTask = () -> {
    157166            if (!parsedProperly) {
     
    166175                JOptionPane.showMessageDialog(null, msg);
    167176            }
     177            if (isSameColor) {
     178                new Notification(tr("The imported track \"{0}\" might not be visible because it has the same color as the background." +
     179                        "<br>You can change this in the context menu of the imported layer.", gpxLayerName))
     180                .setIcon(JOptionPane.WARNING_MESSAGE)
     181                .setDuration(Notification.TIME_LONG)
     182                .show();
     183            }
    168184        };
    169185        return new GpxImporterData(gpxLayer, markerLayer, postLayerTask);
  • trunk/test/data/tracks/tracks-extensions.gpx

    r15496 r15560  
    1818    <extensions>
    1919      <test:tag>Track extension</test:tag>
    20       <gpxx:TrackExtensions>
     20      <gpxx:TrackExtension>
    2121        <gpxx:DisplayColor>Red</gpxx:DisplayColor>
    22       </gpxx:TrackExtensions>
     22      </gpxx:TrackExtension>
    2323    </extensions>
    2424    <trkseg>
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxTrackTest.java

    r15496 r15560  
    4848        trk.invalidate();
    4949        assertNull(trk.getColor());
    50         ext.add("gpxx", "TrackExtensions").getExtensions().add("gpxx", "DisplayColor", "Blue");
     50        ext.add("gpxx", "TrackExtension").getExtensions().add("gpxx", "DisplayColor", "Blue");
    5151        trk.invalidate();
    5252        assertEquals(trk.getColor(), Color.BLUE);
  • trunk/test/unit/org/openstreetmap/josm/io/GpxWriterTest.java

    r15503 r15560  
    191191                "  <trk>\n" +
    192192                "    <extensions>\n" +
    193                 "      <gpxx:TrackExtensions>\n" +
     193                "      <gpxx:TrackExtension>\n" +
    194194                "        <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" +
    195                 "      </gpxx:TrackExtensions>\n" +
     195                "      </gpxx:TrackExtension>\n" +
    196196                "    </extensions>\n" +
    197197                "    <trkseg>\n" +
     
    263263                "  <trk>\n" +
    264264                "    <extensions>\n" +
    265                 "      <gpxx:TrackExtensions>\n" +
     265                "      <gpxx:TrackExtension>\n" +
    266266                "        <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" +
    267                 "      </gpxx:TrackExtensions>\n" +
     267                "      </gpxx:TrackExtension>\n" +
    268268                "    </extensions>\n" +
    269269                "    <trkseg>\n" +
Note: See TracChangeset for help on using the changeset viewer.