|
| 1 | +package com.vaadin.flow.component.map.configuration.source; |
| 2 | + |
| 3 | +import com.vaadin.flow.component.map.configuration.Constants; |
| 4 | + |
| 5 | +import java.util.Map; |
| 6 | +import java.util.Objects; |
| 7 | + |
| 8 | +/** |
| 9 | + * Source for WMS servers providing single, untiled images |
| 10 | + */ |
| 11 | +public class ImageWMSSource extends ImageSource { |
| 12 | + |
| 13 | + private String url; |
| 14 | + private final Map<String, Object> params; |
| 15 | + private final String serverType; |
| 16 | + private final String crossOrigin; |
| 17 | + private final float ratio; |
| 18 | + |
| 19 | + public ImageWMSSource(Options options) { |
| 20 | + super(options); |
| 21 | + Objects.requireNonNull(options.params, |
| 22 | + "WMS request parameters must not be null"); |
| 23 | + Objects.requireNonNull(options.params.get("LAYERS"), |
| 24 | + "WMS request parameter LAYERS must not be null"); |
| 25 | + this.url = options.url; |
| 26 | + this.params = options.params; |
| 27 | + this.serverType = options.serverType; |
| 28 | + this.crossOrigin = options.crossOrigin; |
| 29 | + this.ratio = options.ratio; |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public String getType() { |
| 34 | + return Constants.OL_SOURCE_IMAGE_WMS; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * The WMS service URL |
| 39 | + * |
| 40 | + * @return the current URL |
| 41 | + */ |
| 42 | + public String getUrl() { |
| 43 | + return url; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Sets the WMS service URL |
| 48 | + * |
| 49 | + * @param url |
| 50 | + * the new URL |
| 51 | + */ |
| 52 | + public void setUrl(String url) { |
| 53 | + this.url = url; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * The WMS request parameters for requesting images from the WMS server. At |
| 58 | + * least the {@code LAYERS} parameter is required. By default, |
| 59 | + * {@code VERSION} is {@code 1.3.0}, and {@code STYLES} is {@code ""}. |
| 60 | + * {@code WIDTH}, {@code HEIGHT}, {@code BBOX}, and {@code CRS} / |
| 61 | + * {@code SRS} will be set dynamically. |
| 62 | + * <p> |
| 63 | + * For individual parameters please refer to the documentation of the WMS |
| 64 | + * server as well as the <a href="https://www.ogc.org/standards/wms">WMS |
| 65 | + * specification</a>. |
| 66 | + * <p> |
| 67 | + * This value can not be changed after constructing an instance, it can only |
| 68 | + * be set initially by passing an options object to the constructor. |
| 69 | + * |
| 70 | + * @return the WMS parameters |
| 71 | + */ |
| 72 | + public Map<String, Object> getParams() { |
| 73 | + return params; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * The type of WMS server. |
| 78 | + * <p> |
| 79 | + * This value can not be changed after constructing an instance, it can only |
| 80 | + * be set initially by passing an options object to the constructor. |
| 81 | + * |
| 82 | + * @return the type of WMS server |
| 83 | + */ |
| 84 | + public String getServerType() { |
| 85 | + return serverType; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * The {@code crossOrigin} attribute for loaded images. |
| 90 | + * <p> |
| 91 | + * This value can not be changed after constructing an instance, it can only |
| 92 | + * be set initially by passing an options object to the constructor. |
| 93 | + * |
| 94 | + * @return the crossOrigin attribute used for loaded images |
| 95 | + */ |
| 96 | + public String getCrossOrigin() { |
| 97 | + return crossOrigin; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * The ratio for the size of requested images compared to the map's |
| 102 | + * viewport. Ratio {@code 1} means image requests are the size of the |
| 103 | + * viewport, a ratio of {@code 2} means twice the size of the viewport, and |
| 104 | + * so on. Default is {code 1.5}. |
| 105 | + * <p> |
| 106 | + * This value can not be changed after constructing an instance, it can only |
| 107 | + * be set initially by passing an options object to the constructor. |
| 108 | + * |
| 109 | + * @return the ratio |
| 110 | + */ |
| 111 | + public float getRatio() { |
| 112 | + return ratio; |
| 113 | + } |
| 114 | + |
| 115 | + public static class Options extends ImageSource.BaseOptions<Options> { |
| 116 | + private String url; |
| 117 | + private Map<String, Object> params; |
| 118 | + private String serverType; |
| 119 | + private String crossOrigin; |
| 120 | + private float ratio = 1.5f; |
| 121 | + |
| 122 | + /** |
| 123 | + * @see ImageWMSSource#getUrl() |
| 124 | + */ |
| 125 | + public Options setUrl(String url) { |
| 126 | + this.url = url; |
| 127 | + return getThis(); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @see ImageWMSSource#getParams() |
| 132 | + */ |
| 133 | + public Options setParams(Map<String, Object> params) { |
| 134 | + this.params = params; |
| 135 | + return getThis(); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @see ImageWMSSource#getServerType() |
| 140 | + */ |
| 141 | + public Options setServerType(String serverType) { |
| 142 | + this.serverType = serverType; |
| 143 | + return getThis(); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * @see ImageWMSSource#getCrossOrigin() |
| 148 | + */ |
| 149 | + public Options setCrossOrigin(String crossOrigin) { |
| 150 | + this.crossOrigin = crossOrigin; |
| 151 | + return getThis(); |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * @see ImageWMSSource#getRatio() |
| 156 | + */ |
| 157 | + public Options setRatio(float ratio) { |
| 158 | + this.ratio = ratio; |
| 159 | + return getThis(); |
| 160 | + } |
| 161 | + } |
| 162 | +} |
0 commit comments