Ignore:
Timestamp:
2023-08-10T22:53:52+02:00 (3 years ago)
Author:
taylor.smock
Message:

Fill in source details for OSM changesets

Location:
applications/editors/josm/plugins/pmtiles/src/main/java/org/openstreetmap/josm/plugins/pmtiles/gui/layers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pmtiles/src/main/java/org/openstreetmap/josm/plugins/pmtiles/gui/layers/PMTilesImageLayer.java

    r36112 r36115  
    5959        return new PMTilesImageSource((PMTilesImageryInfo) this.info);
    6060    }
     61
     62    @Override
     63    public PMTilesImageryInfo getInfo() {
     64        return (PMTilesImageryInfo) super.getInfo();
     65    }
     66
     67    @Override
     68    public String getChangesetSourceTag() {
     69        return PMTilesLayer.super.getChangesetSourceTag();
     70    }
    6171}
  • applications/editors/josm/plugins/pmtiles/src/main/java/org/openstreetmap/josm/plugins/pmtiles/gui/layers/PMTilesLayer.java

    r36112 r36115  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.pmtiles.gui.layers;
     3
     4import static org.openstreetmap.josm.tools.Utils.getSystemProperty;
     5
     6import org.openstreetmap.josm.plugins.pmtiles.data.imagery.PMTilesImageryInfo;
     7import org.openstreetmap.josm.tools.TextUtils;
     8import org.openstreetmap.josm.tools.Utils;
    39
    410/**
     
    612 */
    713interface PMTilesLayer {
     14
     15    /**
     16     * Returns imagery info.
     17     * @return imagery info
     18     */
     19    PMTilesImageryInfo getInfo();
     20
     21    /**
     22     * Get the source tag for the layer
     23     * @return The source tag
     24     */
     25    default String getChangesetSourceTag() {
     26        final var sb = new StringBuilder();
     27        final var info = getInfo();
     28        if (info.hasAttribution()) {
     29            sb.append(getInfo().getAttributionText(0, null, null)
     30                    .replaceAll("<a [^>]*>|</a>", "")
     31                    .replaceAll("  +", " "));
     32        }
     33        if (info.getName() != null) {
     34            if (!sb.isEmpty()) {
     35                sb.append(" - ");
     36            }
     37            sb.append(info.getName());
     38        }
     39        if (sb.isEmpty()) {
     40            final var location = info.header().location().toString();
     41            if (Utils.isLocalUrl(location)) {
     42                final String userName = getSystemProperty("user.name");
     43                final String userNameAlt = "<user.name>";
     44                sb.append(location.replace(userName, userNameAlt));
     45            } else {
     46                sb.append(TextUtils.stripUrl(location));
     47            }
     48        }
     49        return sb.toString();
     50    }
    851}
  • applications/editors/josm/plugins/pmtiles/src/main/java/org/openstreetmap/josm/plugins/pmtiles/gui/layers/PMTilesMVTLayer.java

    r36112 r36115  
    6060        return new PMTilesMVTTileSource((PMTilesImageryInfo) this.info);
    6161    }
     62
     63    @Override
     64    public PMTilesImageryInfo getInfo() {
     65        return (PMTilesImageryInfo) super.getInfo();
     66    }
     67
     68    @Override
     69    public String getChangesetSourceTag() {
     70        return PMTilesLayer.super.getChangesetSourceTag();
     71    }
    6272}
Note: See TracChangeset for help on using the changeset viewer.