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

Fill in source details for OSM changesets

Location:
applications/editors/josm/plugins/pmtiles/src
Files:
6 added
4 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}
  • applications/editors/josm/plugins/pmtiles/src/test/java/org/openstreetmap/josm/plugins/pmtiles/lib/PMTilesTest.java

    r36112 r36115  
    77import static org.junit.jupiter.api.Assertions.assertSame;
    88import static org.junit.jupiter.api.Assertions.assertTrue;
     9import static org.openstreetmap.josm.plugins.pmtiles.PMTestUtils.ODBL_RASTER_STAMEN;
     10import static org.openstreetmap.josm.plugins.pmtiles.PMTestUtils.ODBL_VECTOR_FIRENZE;
    911
    10 import java.io.File;
    1112import java.io.IOException;
    12 import java.net.URI;
    1313
    1414import org.junit.jupiter.api.Test;
     
    1818 */
    1919class PMTilesTest {
    20     private static final URI ODBL_VECTOR_FIRENZE = new File("protomaps(vector)ODbL_firenze.pmtiles").exists() ?
    21             new File("protomaps(vector)ODbL_firenze.pmtiles").toURI() :
    22             URI.create("https://github.com/protomaps/PMTiles/raw/main/spec/v3/protomaps(vector)ODbL_firenze.pmtiles");
    23 
    24     private static final URI ODBL_RASTER_STAMEN = new File("stamen_toner(raster)CC-BY%2BODbL_z3.pmtiles").exists() ?
    25             new File("stamen_toner(raster)CC-BY%2BODbL_z3.pmtiles").toURI() :
    26             URI.create("https://github.com/protomaps/PMTiles/raw/main/spec/v3/stamen_toner(raster)CC-BY%2BODbL_z3.pmtiles");
    27 
    2820    @Test
    2921    void testHeader() {
Note: See TracChangeset for help on using the changeset viewer.