Ignore:
Timestamp:
2018-05-12T14:18:57+02:00 (6 years ago)
Author:
wiktorn
Message:

Imagery definition refactor

Extend imagery definitions by:

  • allowing setting default layers for WMS_ENDPOINT and WMTS
  • allowing setting minimum expires time for tile for this imagery
  • allowing setting custom headers that will be sent for all requests

(get map, get capabilities) for this imagery

Additional changes in code:

  • use TileJobOptions to pass miscellaneous options to loaders
  • refactor WMSImagery to use SAX parser

See: #15981, #7953, #16224, #15940, #16249

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/DefaultLayer.java

    r11257 r13733  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.imagery;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import javax.json.Json;
     7import javax.json.JsonObject;
     8import javax.json.JsonObjectBuilder;
     9
     10import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    311
    412/**
     
    1220 */
    1321public class DefaultLayer {
    14 
    15     protected String layerName;
     22    private final String layerName;
     23    private final String tileMatrixSet;
     24    private final String style;
    1625
    1726    /**
    1827     * Constructor
    19      * @param layerName that is the DefaultLayer
     28     * @param imageryType for which this layer is defined
     29     * @param layerName as returned by getIdentifier for WMTS and getName for WMS
     30     * @param style of the layer
     31     * @param tileMatrixSet only for WMTS - tileMatrixSet to use
    2032     */
    21     public DefaultLayer(String layerName) {
    22         this.layerName = layerName;
     33    public DefaultLayer(ImageryType imageryType, String layerName, String style, String tileMatrixSet) {
     34        this.layerName = layerName == null ? "" : layerName;
     35        this.style = style == null ? "" : style;
     36        if (!imageryType.equals(ImageryType.WMTS) && !(tileMatrixSet == null || "".equals(tileMatrixSet))) {
     37            throw new IllegalArgumentException(tr("{0} imagery has tileMatrixSet defined to: {1}", imageryType, tileMatrixSet));
     38        }
     39        this.tileMatrixSet = tileMatrixSet == null ? "" : tileMatrixSet;
    2340    }
    2441
     
    3047    }
    3148
     49    /**
     50     * @return default tileMatrixSet. Only usable for WMTS
     51     */
     52    public String getTileMatrixSet() {
     53        return tileMatrixSet;
     54    }
     55
     56    /**
     57     * @return style for this WMS / WMTS layer to use
     58     */
     59    public String getStyle() {
     60        return style;
     61    }
     62
     63    /**
     64     * @return JSON representation of the default layer object
     65     */
     66    public JsonObject toJson() {
     67        JsonObjectBuilder ret = Json.createObjectBuilder();
     68        ret.add("layerName", layerName);
     69        ret.add("style", style);
     70        ret.add("tileMatrixSet", tileMatrixSet);
     71        return ret.build();
     72    }
     73
     74    /**
     75     * Factory method creating DefaultLayer from JSON objects
     76     * @param o serialized DefaultLayer object
     77     * @param type of ImageryType serialized
     78     * @return DefaultLayer instance based on JSON object
     79     */
     80    public static DefaultLayer fromJson(JsonObject o, ImageryType type) {
     81        return new DefaultLayer(type, o.getString("layerName"), o.getString("style"), o.getString("tileMatrixSet"));
     82    }
    3283}
Note: See TracChangeset for help on using the changeset viewer.