Ticket #14921: 14921.patch

File 14921.patch, 5.5 KB (added by simon04, 6 years ago)
  • src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java b/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
    index 0c14ff0a8..53f557aab 100644
    a b  
    1111import java.io.IOException;
    1212import java.net.MalformedURLException;
    1313import java.nio.file.InvalidPathException;
     14import java.time.Year;
     15import java.time.ZoneOffset;
    1416import java.util.Collection;
    1517import java.util.Collections;
    1618import java.util.List;
    public AddImageryLayerAction(ImageryInfo info) {  
    9496     */
    9597    private static ImageryInfo convertImagery(ImageryInfo info) {
    9698        try {
     99            if (info.getUrl().contains("{time}")) {
     100                final String instant = Year.now().atDay(1).atStartOfDay(ZoneOffset.UTC).toInstant().toString();
     101                final String example = String.join("/", instant, instant);
     102                final String initialSelectionValue = info.getDate() != null ? info.getDate() : example;
     103                final String userDate = JOptionPane.showInputDialog(MainApplication.getMainFrame(),
     104                        tr("Time filter for {0} such as {1}", info.getName(), example),
     105                        initialSelectionValue);
     106                if (userDate == null) {
     107                    return null;
     108                }
     109                info.setDate(userDate);
     110                // TODO ImageryLayerInfo.save
     111            }
    97112            switch(info.getImageryType()) {
    98113            case WMS_ENDPOINT:
    99114                // convert to WMS type
  • src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    diff --git a/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java b/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
    index 6bf1c45d1..50cfb87ed 100644
    a b public boolean equals(Object o) {  
    276276    private String countryCode = "";
    277277    /**
    278278      * creation date of the imagery (in the form YYYY-MM-DD;YYYY-MM-DD, where
    279       * DD and MM as well as a second date are optional)
     279      * DD and MM as well as a second date are optional).
     280      *
     281      * Also used as time filter for WMS time={time} parameter (such as Sentinel-2)
    280282      * @since 11570
    281283      */
    282284    private String date;
  • src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java

    diff --git a/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java b/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
    index 23f1103f5..94391d4fa 100644
    a b  
    2121import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2222import org.openstreetmap.josm.gui.layer.WMSLayer;
    2323import org.openstreetmap.josm.tools.CheckParameterUtil;
     24import org.openstreetmap.josm.tools.Utils;
    2425
    2526/**
    2627 * Tile Source handling WMS providers
     
    2930 * @since 8526
    3031 */
    3132public class TemplatedWMSTileSource extends AbstractWMSTileSource implements TemplatedTileSource {
    32     private final Map<String, String> headers = new ConcurrentHashMap<>();
    33     private final Set<String> serverProjections;
    3433    // CHECKSTYLE.OFF: SingleSpaceSeparator
    3534    private static final Pattern PATTERN_HEADER = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}");
    3635    private static final Pattern PATTERN_PROJ   = Pattern.compile("\\{proj\\}");
     
    4241    private static final Pattern PATTERN_N      = Pattern.compile("\\{n\\}");
    4342    private static final Pattern PATTERN_WIDTH  = Pattern.compile("\\{width\\}");
    4443    private static final Pattern PATTERN_HEIGHT = Pattern.compile("\\{height\\}");
     44    private static final Pattern PATTERN_TIME   = Pattern.compile("\\{time\\}"); // Sentinel-2
    4545    private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{([^}]+)\\}");
    4646    // CHECKSTYLE.ON: SingleSpaceSeparator
    4747
    4848    private static final NumberFormat LATLON_FORMAT = new DecimalFormat("###0.0000000", new DecimalFormatSymbols(Locale.US));
    4949
    5050    private static final Pattern[] ALL_PATTERNS = {
    51         PATTERN_HEADER, PATTERN_PROJ, PATTERN_WKID, PATTERN_BBOX, PATTERN_W, PATTERN_S, PATTERN_E, PATTERN_N, PATTERN_WIDTH, PATTERN_HEIGHT
     51            PATTERN_HEADER, PATTERN_PROJ, PATTERN_WKID, PATTERN_BBOX,
     52            PATTERN_W, PATTERN_S, PATTERN_E, PATTERN_N,
     53            PATTERN_WIDTH, PATTERN_HEIGHT, PATTERN_TIME,
    5254    };
    5355
     56    private final Set<String> serverProjections;
     57    private final Map<String, String> headers = new ConcurrentHashMap<>();
     58    private final String date;
    5459    private final boolean switchLatLon;
     60
    5561    /**
    5662     * Creates a tile source based on imagery info
    5763     * @param info imagery info
    public TemplatedWMSTileSource(ImageryInfo info, Projection tileProjection) {  
    6167        super(info, tileProjection);
    6268        this.serverProjections = new TreeSet<>(info.getServerProjections());
    6369        this.headers.putAll(info.getCustomHttpHeaders());
     70        this.date = info.getDate();
    6471        handleTemplate();
    6572        initProjection();
    6673        // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326.
    public String getTileUrl(int zoom, int tilex, int tiley) {  
    143150            case "height":
    144151                replacement = String.valueOf(getTileSize());
    145152                break;
     153            case "time":
     154                replacement = Utils.encodeUrl(date);
     155                break;
    146156            default:
    147157                replacement = '{' + matcher.group(1) + '}';
    148158            }