1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import javax.json.Json;
|
---|
7 | import javax.json.JsonObject;
|
---|
8 | import javax.json.JsonObjectBuilder;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | *
|
---|
14 | * Simple class representing default layer that might be set in imagery information
|
---|
15 | *
|
---|
16 | * This simple class is needed - as for WMS there is different information needed to specify layer than for WMTS
|
---|
17 | *
|
---|
18 | * @author Wiktor Niesiobedzki
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public class DefaultLayer {
|
---|
22 | private final String layerName;
|
---|
23 | private final String tileMatrixSet;
|
---|
24 | private final String style;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Constructor
|
---|
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
|
---|
32 | */
|
---|
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 != 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;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * @return layer name of the default layer
|
---|
44 | */
|
---|
45 | public String getLayerName() {
|
---|
46 | return layerName;
|
---|
47 | }
|
---|
48 |
|
---|
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 | }
|
---|
83 | }
|
---|