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 java.awt.Image;
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.Collections;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Locale;
|
---|
13 | import java.util.Map;
|
---|
14 | import java.util.Objects;
|
---|
15 | import java.util.Set;
|
---|
16 | import java.util.TreeSet;
|
---|
17 | import java.util.regex.Matcher;
|
---|
18 | import java.util.regex.Pattern;
|
---|
19 | import java.util.stream.Collectors;
|
---|
20 |
|
---|
21 | import javax.swing.ImageIcon;
|
---|
22 |
|
---|
23 | import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
|
---|
24 | import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
|
---|
25 | import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource;
|
---|
26 | import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik;
|
---|
27 | import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
|
---|
28 | import org.openstreetmap.josm.Main;
|
---|
29 | import org.openstreetmap.josm.data.Bounds;
|
---|
30 | import org.openstreetmap.josm.data.Preferences.pref;
|
---|
31 | import org.openstreetmap.josm.io.Capabilities;
|
---|
32 | import org.openstreetmap.josm.io.OsmApi;
|
---|
33 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
34 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
35 | import org.openstreetmap.josm.tools.LanguageInfo;
|
---|
36 | import org.openstreetmap.josm.tools.MultiMap;
|
---|
37 | import org.openstreetmap.josm.tools.Utils;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Class that stores info about an image background layer.
|
---|
41 | *
|
---|
42 | * @author Frederik Ramm
|
---|
43 | */
|
---|
44 | public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInfo>, Attributed {
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Type of imagery entry.
|
---|
48 | */
|
---|
49 | public enum ImageryType {
|
---|
50 | /** A WMS (Web Map Service) entry. **/
|
---|
51 | WMS("wms"),
|
---|
52 | /** A TMS (Tile Map Service) entry. **/
|
---|
53 | TMS("tms"),
|
---|
54 | /** TMS entry for Microsoft Bing. */
|
---|
55 | BING("bing"),
|
---|
56 | /** TMS entry for Russian company <a href="https://wiki.openstreetmap.org/wiki/WikiProject_Russia/kosmosnimki">ScanEx</a>. **/
|
---|
57 | SCANEX("scanex"),
|
---|
58 | /** A WMS endpoint entry only stores the WMS server info, without layer, which are chosen later by the user. **/
|
---|
59 | WMS_ENDPOINT("wms_endpoint"),
|
---|
60 | /** WMTS stores GetCapabilities URL. Does not store any information about the layer **/
|
---|
61 | WMTS("wmts");
|
---|
62 |
|
---|
63 |
|
---|
64 | private final String typeString;
|
---|
65 |
|
---|
66 | ImageryType(String urlString) {
|
---|
67 | this.typeString = urlString;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Returns the unique string identifying this type.
|
---|
72 | * @return the unique string identifying this type
|
---|
73 | * @since 6690
|
---|
74 | */
|
---|
75 | public final String getTypeString() {
|
---|
76 | return typeString;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Returns the imagery type from the given type string.
|
---|
81 | * @param s The type string
|
---|
82 | * @return the imagery type matching the given type string
|
---|
83 | */
|
---|
84 | public static ImageryType fromString(String s) {
|
---|
85 | for (ImageryType type : ImageryType.values()) {
|
---|
86 | if (type.getTypeString().equals(s)) {
|
---|
87 | return type;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | return null;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Multi-polygon bounds for imagery backgrounds.
|
---|
96 | * Used to display imagery coverage in preferences and to determine relevant imagery entries based on edit location.
|
---|
97 | */
|
---|
98 | public static class ImageryBounds extends Bounds {
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Constructs a new {@code ImageryBounds} from string.
|
---|
102 | * @param asString The string containing the list of shapes defining this bounds
|
---|
103 | * @param separator The shape separator in the given string, usually a comma
|
---|
104 | */
|
---|
105 | public ImageryBounds(String asString, String separator) {
|
---|
106 | super(asString, separator);
|
---|
107 | }
|
---|
108 |
|
---|
109 | private List<Shape> shapes = new ArrayList<>();
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Adds a new shape to this bounds.
|
---|
113 | * @param shape The shape to add
|
---|
114 | */
|
---|
115 | public final void addShape(Shape shape) {
|
---|
116 | this.shapes.add(shape);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Sets the list of shapes defining this bounds.
|
---|
121 | * @param shapes The list of shapes defining this bounds.
|
---|
122 | */
|
---|
123 | public final void setShapes(List<Shape> shapes) {
|
---|
124 | this.shapes = shapes;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Returns the list of shapes defining this bounds.
|
---|
129 | * @return The list of shapes defining this bounds
|
---|
130 | */
|
---|
131 | public final List<Shape> getShapes() {
|
---|
132 | return shapes;
|
---|
133 | }
|
---|
134 |
|
---|
135 | @Override
|
---|
136 | public int hashCode() {
|
---|
137 | return Objects.hash(super.hashCode(), shapes);
|
---|
138 | }
|
---|
139 |
|
---|
140 | @Override
|
---|
141 | public boolean equals(Object o) {
|
---|
142 | if (this == o) return true;
|
---|
143 | if (o == null || getClass() != o.getClass()) return false;
|
---|
144 | if (!super.equals(o)) return false;
|
---|
145 | ImageryBounds that = (ImageryBounds) o;
|
---|
146 | return Objects.equals(shapes, that.shapes);
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | /** original name of the imagery entry in case of translation call, for multiple languages English when possible */
|
---|
151 | private String origName;
|
---|
152 | /** (original) language of the translated name entry */
|
---|
153 | private String langName;
|
---|
154 | /** whether this is a entry activated by default or not */
|
---|
155 | private boolean defaultEntry;
|
---|
156 | /** The data part of HTTP cookies header in case the service requires cookies to work */
|
---|
157 | private String cookies;
|
---|
158 | /** Whether this service requires a explicit EULA acceptance before it can be activated */
|
---|
159 | private String eulaAcceptanceRequired;
|
---|
160 | /** type of the imagery servics - WMS, TMS, ... */
|
---|
161 | private ImageryType imageryType = ImageryType.WMS;
|
---|
162 | private double pixelPerDegree;
|
---|
163 | /** maximum zoom level for TMS imagery */
|
---|
164 | private int defaultMaxZoom;
|
---|
165 | /** minimum zoom level for TMS imagery */
|
---|
166 | private int defaultMinZoom;
|
---|
167 | /** display bounds of imagery, displayed in prefs and used for automatic imagery selection */
|
---|
168 | private ImageryBounds bounds;
|
---|
169 | /** projections supported by WMS servers */
|
---|
170 | private List<String> serverProjections = Collections.emptyList();
|
---|
171 | /** description of the imagery entry, should contain notes what type of data it is */
|
---|
172 | private String description;
|
---|
173 | /** language of the description entry */
|
---|
174 | private String langDescription;
|
---|
175 | /** Text of a text attribution displayed when using the imagery */
|
---|
176 | private String attributionText;
|
---|
177 | /** Link behing the text attribution displayed when using the imagery */
|
---|
178 | private String attributionLinkURL;
|
---|
179 | /** Image of a graphical attribution displayed when using the imagery */
|
---|
180 | private String attributionImage;
|
---|
181 | /** Link behind the graphical attribution displayed when using the imagery */
|
---|
182 | private String attributionImageURL;
|
---|
183 | /** Text with usage terms displayed when using the imagery */
|
---|
184 | private String termsOfUseText;
|
---|
185 | /** Link behind the text with usage terms displayed when using the imagery */
|
---|
186 | private String termsOfUseURL;
|
---|
187 | /** country code of the imagery (for country specific imagery) */
|
---|
188 | private String countryCode = "";
|
---|
189 | /**
|
---|
190 | * creation date of the imagery (in the form YYYY-MM-DD;YYYY-MM-DD, where
|
---|
191 | * DD and MM as well as a second date are optional)
|
---|
192 | * @since 11570
|
---|
193 | */
|
---|
194 | private String date;
|
---|
195 | /**
|
---|
196 | * marked as best in other editors
|
---|
197 | * @since 11575
|
---|
198 | */
|
---|
199 | private boolean bestMarked;
|
---|
200 | /** mirrors of different type for this entry */
|
---|
201 | private List<ImageryInfo> mirrors;
|
---|
202 | /** icon used in menu */
|
---|
203 | private String icon;
|
---|
204 | /** is the geo reference correct - don't offer offset handling */
|
---|
205 | private boolean isGeoreferenceValid;
|
---|
206 | /** which layers should be activated by default on layer addition. **/
|
---|
207 | private Collection<DefaultLayer> defaultLayers = Collections.emptyList();
|
---|
208 | // when adding a field, also adapt the ImageryInfo(ImageryInfo)
|
---|
209 | // and ImageryInfo(ImageryPreferenceEntry) constructor, equals method, and ImageryPreferenceEntry
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Auxiliary class to save an {@link ImageryInfo} object in the preferences.
|
---|
213 | */
|
---|
214 | public static class ImageryPreferenceEntry {
|
---|
215 | @pref String name;
|
---|
216 | @pref String d;
|
---|
217 | @pref String id;
|
---|
218 | @pref String type;
|
---|
219 | @pref String url;
|
---|
220 | @pref double pixel_per_eastnorth;
|
---|
221 | @pref String eula;
|
---|
222 | @pref String attribution_text;
|
---|
223 | @pref String attribution_url;
|
---|
224 | @pref String logo_image;
|
---|
225 | @pref String logo_url;
|
---|
226 | @pref String terms_of_use_text;
|
---|
227 | @pref String terms_of_use_url;
|
---|
228 | @pref String country_code = "";
|
---|
229 | @pref String date;
|
---|
230 | @pref int max_zoom;
|
---|
231 | @pref int min_zoom;
|
---|
232 | @pref String cookies;
|
---|
233 | @pref String bounds;
|
---|
234 | @pref String shapes;
|
---|
235 | @pref String projections;
|
---|
236 | @pref String icon;
|
---|
237 | @pref String description;
|
---|
238 | @pref MultiMap<String, String> noTileHeaders;
|
---|
239 | @pref MultiMap<String, String> noTileChecksums;
|
---|
240 | @pref int tileSize = -1;
|
---|
241 | @pref Map<String, String> metadataHeaders;
|
---|
242 | @pref boolean valid_georeference;
|
---|
243 | @pref boolean bestMarked;
|
---|
244 | // TODO: disabled until change of layers is implemented
|
---|
245 | // @pref String default_layers;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Constructs a new empty WMS {@code ImageryPreferenceEntry}.
|
---|
249 | */
|
---|
250 | public ImageryPreferenceEntry() {
|
---|
251 | // Do nothing
|
---|
252 | }
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Constructs a new {@code ImageryPreferenceEntry} from a given {@code ImageryInfo}.
|
---|
256 | * @param i The corresponding imagery info
|
---|
257 | */
|
---|
258 | public ImageryPreferenceEntry(ImageryInfo i) {
|
---|
259 | name = i.name;
|
---|
260 | id = i.id;
|
---|
261 | type = i.imageryType.getTypeString();
|
---|
262 | url = i.url;
|
---|
263 | pixel_per_eastnorth = i.pixelPerDegree;
|
---|
264 | eula = i.eulaAcceptanceRequired;
|
---|
265 | attribution_text = i.attributionText;
|
---|
266 | attribution_url = i.attributionLinkURL;
|
---|
267 | date = i.date;
|
---|
268 | bestMarked = i.bestMarked;
|
---|
269 | logo_image = i.attributionImage;
|
---|
270 | logo_url = i.attributionImageURL;
|
---|
271 | terms_of_use_text = i.termsOfUseText;
|
---|
272 | terms_of_use_url = i.termsOfUseURL;
|
---|
273 | country_code = i.countryCode;
|
---|
274 | max_zoom = i.defaultMaxZoom;
|
---|
275 | min_zoom = i.defaultMinZoom;
|
---|
276 | cookies = i.cookies;
|
---|
277 | icon = i.icon;
|
---|
278 | description = i.description;
|
---|
279 | if (i.bounds != null) {
|
---|
280 | bounds = i.bounds.encodeAsString(",");
|
---|
281 | StringBuilder shapesString = new StringBuilder();
|
---|
282 | for (Shape s : i.bounds.getShapes()) {
|
---|
283 | if (shapesString.length() > 0) {
|
---|
284 | shapesString.append(';');
|
---|
285 | }
|
---|
286 | shapesString.append(s.encodeAsString(","));
|
---|
287 | }
|
---|
288 | if (shapesString.length() > 0) {
|
---|
289 | shapes = shapesString.toString();
|
---|
290 | }
|
---|
291 | }
|
---|
292 | projections = i.serverProjections.stream().collect(Collectors.joining(","));
|
---|
293 | if (i.noTileHeaders != null && !i.noTileHeaders.isEmpty()) {
|
---|
294 | noTileHeaders = new MultiMap<>(i.noTileHeaders);
|
---|
295 | }
|
---|
296 |
|
---|
297 | if (i.noTileChecksums != null && !i.noTileChecksums.isEmpty()) {
|
---|
298 | noTileChecksums = new MultiMap<>(i.noTileChecksums);
|
---|
299 | }
|
---|
300 |
|
---|
301 | if (i.metadataHeaders != null && !i.metadataHeaders.isEmpty()) {
|
---|
302 | metadataHeaders = i.metadataHeaders;
|
---|
303 | }
|
---|
304 |
|
---|
305 | tileSize = i.getTileSize();
|
---|
306 |
|
---|
307 | valid_georeference = i.isGeoreferenceValid();
|
---|
308 | // TODO disabled until change of layers is implemented
|
---|
309 | // default_layers = i.defaultLayers.stream().collect(Collectors.joining(","));
|
---|
310 | }
|
---|
311 |
|
---|
312 | @Override
|
---|
313 | public String toString() {
|
---|
314 | StringBuilder s = new StringBuilder("ImageryPreferenceEntry [name=").append(name);
|
---|
315 | if (id != null) {
|
---|
316 | s.append(" id=").append(id);
|
---|
317 | }
|
---|
318 | s.append(']');
|
---|
319 | return s.toString();
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | /**
|
---|
324 | * Constructs a new WMS {@code ImageryInfo}.
|
---|
325 | */
|
---|
326 | public ImageryInfo() {
|
---|
327 | super();
|
---|
328 | }
|
---|
329 |
|
---|
330 | /**
|
---|
331 | * Constructs a new WMS {@code ImageryInfo} with a given name.
|
---|
332 | * @param name The entry name
|
---|
333 | */
|
---|
334 | public ImageryInfo(String name) {
|
---|
335 | super(name);
|
---|
336 | }
|
---|
337 |
|
---|
338 | /**
|
---|
339 | * Constructs a new WMS {@code ImageryInfo} with given name and extended URL.
|
---|
340 | * @param name The entry name
|
---|
341 | * @param url The entry extended URL
|
---|
342 | */
|
---|
343 | public ImageryInfo(String name, String url) {
|
---|
344 | this(name);
|
---|
345 | setExtendedUrl(url);
|
---|
346 | }
|
---|
347 |
|
---|
348 | /**
|
---|
349 | * Constructs a new WMS {@code ImageryInfo} with given name, extended and EULA URLs.
|
---|
350 | * @param name The entry name
|
---|
351 | * @param url The entry URL
|
---|
352 | * @param eulaAcceptanceRequired The EULA URL
|
---|
353 | */
|
---|
354 | public ImageryInfo(String name, String url, String eulaAcceptanceRequired) {
|
---|
355 | this(name);
|
---|
356 | setExtendedUrl(url);
|
---|
357 | this.eulaAcceptanceRequired = eulaAcceptanceRequired;
|
---|
358 | }
|
---|
359 |
|
---|
360 | /**
|
---|
361 | * Constructs a new {@code ImageryInfo} with given name, url, extended and EULA URLs.
|
---|
362 | * @param name The entry name
|
---|
363 | * @param url The entry URL
|
---|
364 | * @param type The entry imagery type. If null, WMS will be used as default
|
---|
365 | * @param eulaAcceptanceRequired The EULA URL
|
---|
366 | * @param cookies The data part of HTTP cookies header in case the service requires cookies to work
|
---|
367 | * @throws IllegalArgumentException if type refers to an unknown imagery type
|
---|
368 | */
|
---|
369 | public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies) {
|
---|
370 | this(name);
|
---|
371 | setExtendedUrl(url);
|
---|
372 | ImageryType t = ImageryType.fromString(type);
|
---|
373 | this.cookies = cookies;
|
---|
374 | this.eulaAcceptanceRequired = eulaAcceptanceRequired;
|
---|
375 | if (t != null) {
|
---|
376 | this.imageryType = t;
|
---|
377 | } else if (type != null && !type.isEmpty()) {
|
---|
378 | throw new IllegalArgumentException("unknown type: "+type);
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | /**
|
---|
383 | * Constructs a new {@code ImageryInfo} with given name, url, id, extended and EULA URLs.
|
---|
384 | * @param name The entry name
|
---|
385 | * @param url The entry URL
|
---|
386 | * @param type The entry imagery type. If null, WMS will be used as default
|
---|
387 | * @param eulaAcceptanceRequired The EULA URL
|
---|
388 | * @param cookies The data part of HTTP cookies header in case the service requires cookies to work
|
---|
389 | * @param id tile id
|
---|
390 | * @throws IllegalArgumentException if type refers to an unknown imagery type
|
---|
391 | */
|
---|
392 | public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies, String id) {
|
---|
393 | this(name, url, type, eulaAcceptanceRequired, cookies);
|
---|
394 | setId(id);
|
---|
395 | }
|
---|
396 |
|
---|
397 | /**
|
---|
398 | * Constructs a new {@code ImageryInfo} from an imagery preference entry.
|
---|
399 | * @param e The imagery preference entry
|
---|
400 | */
|
---|
401 | public ImageryInfo(ImageryPreferenceEntry e) {
|
---|
402 | super(e.name, e.url, e.id);
|
---|
403 | CheckParameterUtil.ensureParameterNotNull(e.name, "name");
|
---|
404 | CheckParameterUtil.ensureParameterNotNull(e.url, "url");
|
---|
405 | description = e.description;
|
---|
406 | cookies = e.cookies;
|
---|
407 | eulaAcceptanceRequired = e.eula;
|
---|
408 | imageryType = ImageryType.fromString(e.type);
|
---|
409 | if (imageryType == null) throw new IllegalArgumentException("unknown type");
|
---|
410 | pixelPerDegree = e.pixel_per_eastnorth;
|
---|
411 | defaultMaxZoom = e.max_zoom;
|
---|
412 | defaultMinZoom = e.min_zoom;
|
---|
413 | if (e.bounds != null) {
|
---|
414 | bounds = new ImageryBounds(e.bounds, ",");
|
---|
415 | if (e.shapes != null) {
|
---|
416 | try {
|
---|
417 | for (String s : e.shapes.split(";")) {
|
---|
418 | bounds.addShape(new Shape(s, ","));
|
---|
419 | }
|
---|
420 | } catch (IllegalArgumentException ex) {
|
---|
421 | Main.warn(ex);
|
---|
422 | }
|
---|
423 | }
|
---|
424 | }
|
---|
425 | if (e.projections != null && !e.projections.isEmpty()) {
|
---|
426 | // split generates null element on empty string which gives one element Array[null]
|
---|
427 | serverProjections = Arrays.asList(e.projections.split(","));
|
---|
428 | }
|
---|
429 | attributionText = e.attribution_text;
|
---|
430 | attributionLinkURL = e.attribution_url;
|
---|
431 | attributionImage = e.logo_image;
|
---|
432 | attributionImageURL = e.logo_url;
|
---|
433 | date = e.date;
|
---|
434 | bestMarked = e.bestMarked;
|
---|
435 | termsOfUseText = e.terms_of_use_text;
|
---|
436 | termsOfUseURL = e.terms_of_use_url;
|
---|
437 | countryCode = e.country_code;
|
---|
438 | icon = e.icon;
|
---|
439 | if (e.noTileHeaders != null) {
|
---|
440 | noTileHeaders = e.noTileHeaders.toMap();
|
---|
441 | }
|
---|
442 | if (e.noTileChecksums != null) {
|
---|
443 | noTileChecksums = e.noTileChecksums.toMap();
|
---|
444 | }
|
---|
445 | setTileSize(e.tileSize);
|
---|
446 | metadataHeaders = e.metadataHeaders;
|
---|
447 | isGeoreferenceValid = e.valid_georeference;
|
---|
448 | // TODO disabled until change of layers is implemented
|
---|
449 | // defaultLayers = Arrays.asList(e.default_layers.split(","));
|
---|
450 | }
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Constructs a new {@code ImageryInfo} from an existing one.
|
---|
454 | * @param i The other imagery info
|
---|
455 | */
|
---|
456 | public ImageryInfo(ImageryInfo i) {
|
---|
457 | super(i.name, i.url, i.id);
|
---|
458 | this.origName = i.origName;
|
---|
459 | this.langName = i.langName;
|
---|
460 | this.bestMarked = i.bestMarked;
|
---|
461 | this.defaultEntry = i.defaultEntry;
|
---|
462 | this.cookies = i.cookies;
|
---|
463 | this.eulaAcceptanceRequired = null;
|
---|
464 | this.imageryType = i.imageryType;
|
---|
465 | this.pixelPerDegree = i.pixelPerDegree;
|
---|
466 | this.defaultMaxZoom = i.defaultMaxZoom;
|
---|
467 | this.defaultMinZoom = i.defaultMinZoom;
|
---|
468 | this.bounds = i.bounds;
|
---|
469 | this.serverProjections = i.serverProjections;
|
---|
470 | this.attributionText = i.attributionText;
|
---|
471 | this.attributionLinkURL = i.attributionLinkURL;
|
---|
472 | this.attributionImage = i.attributionImage;
|
---|
473 | this.attributionImageURL = i.attributionImageURL;
|
---|
474 | this.termsOfUseText = i.termsOfUseText;
|
---|
475 | this.termsOfUseURL = i.termsOfUseURL;
|
---|
476 | this.countryCode = i.countryCode;
|
---|
477 | this.date = i.date;
|
---|
478 | this.icon = i.icon;
|
---|
479 | this.description = i.description;
|
---|
480 | this.noTileHeaders = i.noTileHeaders;
|
---|
481 | this.noTileChecksums = i.noTileChecksums;
|
---|
482 | this.metadataHeaders = i.metadataHeaders;
|
---|
483 | this.isGeoreferenceValid = i.isGeoreferenceValid;
|
---|
484 | this.defaultLayers = i.defaultLayers;
|
---|
485 | }
|
---|
486 |
|
---|
487 | @Override
|
---|
488 | public int hashCode() {
|
---|
489 | return Objects.hash(url, imageryType);
|
---|
490 | }
|
---|
491 |
|
---|
492 | /**
|
---|
493 | * Check if this object equals another ImageryInfo with respect to the properties
|
---|
494 | * that get written to the preference file.
|
---|
495 | *
|
---|
496 | * The field {@link #pixelPerDegree} is ignored.
|
---|
497 | *
|
---|
498 | * @param other the ImageryInfo object to compare to
|
---|
499 | * @return true if they are equal
|
---|
500 | */
|
---|
501 | public boolean equalsPref(ImageryInfo other) {
|
---|
502 | if (other == null) {
|
---|
503 | return false;
|
---|
504 | }
|
---|
505 |
|
---|
506 | // CHECKSTYLE.OFF: BooleanExpressionComplexity
|
---|
507 | return
|
---|
508 | Objects.equals(this.name, other.name) &&
|
---|
509 | Objects.equals(this.id, other.id) &&
|
---|
510 | Objects.equals(this.url, other.url) &&
|
---|
511 | Objects.equals(this.bestMarked, other.bestMarked) &&
|
---|
512 | Objects.equals(this.isGeoreferenceValid, other.isGeoreferenceValid) &&
|
---|
513 | Objects.equals(this.cookies, other.cookies) &&
|
---|
514 | Objects.equals(this.eulaAcceptanceRequired, other.eulaAcceptanceRequired) &&
|
---|
515 | Objects.equals(this.imageryType, other.imageryType) &&
|
---|
516 | Objects.equals(this.defaultMaxZoom, other.defaultMaxZoom) &&
|
---|
517 | Objects.equals(this.defaultMinZoom, other.defaultMinZoom) &&
|
---|
518 | Objects.equals(this.bounds, other.bounds) &&
|
---|
519 | Objects.equals(this.serverProjections, other.serverProjections) &&
|
---|
520 | Objects.equals(this.attributionText, other.attributionText) &&
|
---|
521 | Objects.equals(this.attributionLinkURL, other.attributionLinkURL) &&
|
---|
522 | Objects.equals(this.attributionImageURL, other.attributionImageURL) &&
|
---|
523 | Objects.equals(this.attributionImage, other.attributionImage) &&
|
---|
524 | Objects.equals(this.termsOfUseText, other.termsOfUseText) &&
|
---|
525 | Objects.equals(this.termsOfUseURL, other.termsOfUseURL) &&
|
---|
526 | Objects.equals(this.countryCode, other.countryCode) &&
|
---|
527 | Objects.equals(this.date, other.date) &&
|
---|
528 | Objects.equals(this.icon, other.icon) &&
|
---|
529 | Objects.equals(this.description, other.description) &&
|
---|
530 | Objects.equals(this.noTileHeaders, other.noTileHeaders) &&
|
---|
531 | Objects.equals(this.noTileChecksums, other.noTileChecksums) &&
|
---|
532 | Objects.equals(this.metadataHeaders, other.metadataHeaders) &&
|
---|
533 | Objects.equals(this.defaultLayers, other.defaultLayers);
|
---|
534 | // CHECKSTYLE.ON: BooleanExpressionComplexity
|
---|
535 | }
|
---|
536 |
|
---|
537 | @Override
|
---|
538 | public boolean equals(Object o) {
|
---|
539 | if (this == o) return true;
|
---|
540 | if (o == null || getClass() != o.getClass()) return false;
|
---|
541 | ImageryInfo that = (ImageryInfo) o;
|
---|
542 | return imageryType == that.imageryType && Objects.equals(url, that.url);
|
---|
543 | }
|
---|
544 |
|
---|
545 | @Override
|
---|
546 | public String toString() {
|
---|
547 | return "ImageryInfo{" +
|
---|
548 | "name='" + name + '\'' +
|
---|
549 | ", countryCode='" + countryCode + '\'' +
|
---|
550 | ", url='" + url + '\'' +
|
---|
551 | ", imageryType=" + imageryType +
|
---|
552 | '}';
|
---|
553 | }
|
---|
554 |
|
---|
555 | @Override
|
---|
556 | public int compareTo(ImageryInfo in) {
|
---|
557 | int i = countryCode.compareTo(in.countryCode);
|
---|
558 | if (i == 0) {
|
---|
559 | i = name.toLowerCase(Locale.ENGLISH).compareTo(in.name.toLowerCase(Locale.ENGLISH));
|
---|
560 | }
|
---|
561 | if (i == 0) {
|
---|
562 | i = url.compareTo(in.url);
|
---|
563 | }
|
---|
564 | if (i == 0) {
|
---|
565 | i = Double.compare(pixelPerDegree, in.pixelPerDegree);
|
---|
566 | }
|
---|
567 | return i;
|
---|
568 | }
|
---|
569 |
|
---|
570 | /**
|
---|
571 | * Determines if URL is equal to given imagery info.
|
---|
572 | * @param in imagery info
|
---|
573 | * @return {@code true} if URL is equal to given imagery info
|
---|
574 | */
|
---|
575 | public boolean equalsBaseValues(ImageryInfo in) {
|
---|
576 | return url.equals(in.url);
|
---|
577 | }
|
---|
578 |
|
---|
579 | /**
|
---|
580 | * Sets the pixel per degree value.
|
---|
581 | * @param ppd The ppd value
|
---|
582 | * @see #getPixelPerDegree()
|
---|
583 | */
|
---|
584 | public void setPixelPerDegree(double ppd) {
|
---|
585 | this.pixelPerDegree = ppd;
|
---|
586 | }
|
---|
587 |
|
---|
588 | /**
|
---|
589 | * Sets the maximum zoom level.
|
---|
590 | * @param defaultMaxZoom The maximum zoom level
|
---|
591 | */
|
---|
592 | public void setDefaultMaxZoom(int defaultMaxZoom) {
|
---|
593 | this.defaultMaxZoom = defaultMaxZoom;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /**
|
---|
597 | * Sets the minimum zoom level.
|
---|
598 | * @param defaultMinZoom The minimum zoom level
|
---|
599 | */
|
---|
600 | public void setDefaultMinZoom(int defaultMinZoom) {
|
---|
601 | this.defaultMinZoom = defaultMinZoom;
|
---|
602 | }
|
---|
603 |
|
---|
604 | /**
|
---|
605 | * Sets the imagery polygonial bounds.
|
---|
606 | * @param b The imagery bounds (non-rectangular)
|
---|
607 | */
|
---|
608 | public void setBounds(ImageryBounds b) {
|
---|
609 | this.bounds = b;
|
---|
610 | }
|
---|
611 |
|
---|
612 | /**
|
---|
613 | * Returns the imagery polygonial bounds.
|
---|
614 | * @return The imagery bounds (non-rectangular)
|
---|
615 | */
|
---|
616 | public ImageryBounds getBounds() {
|
---|
617 | return bounds;
|
---|
618 | }
|
---|
619 |
|
---|
620 | @Override
|
---|
621 | public boolean requiresAttribution() {
|
---|
622 | return attributionText != null || attributionImage != null || termsOfUseText != null || termsOfUseURL != null;
|
---|
623 | }
|
---|
624 |
|
---|
625 | @Override
|
---|
626 | public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
|
---|
627 | return attributionText;
|
---|
628 | }
|
---|
629 |
|
---|
630 | @Override
|
---|
631 | public String getAttributionLinkURL() {
|
---|
632 | return attributionLinkURL;
|
---|
633 | }
|
---|
634 |
|
---|
635 | @Override
|
---|
636 | public Image getAttributionImage() {
|
---|
637 | ImageIcon i = ImageProvider.getIfAvailable(attributionImage);
|
---|
638 | if (i != null) {
|
---|
639 | return i.getImage();
|
---|
640 | }
|
---|
641 | return null;
|
---|
642 | }
|
---|
643 |
|
---|
644 | @Override
|
---|
645 | public String getAttributionImageURL() {
|
---|
646 | return attributionImageURL;
|
---|
647 | }
|
---|
648 |
|
---|
649 | @Override
|
---|
650 | public String getTermsOfUseText() {
|
---|
651 | return termsOfUseText;
|
---|
652 | }
|
---|
653 |
|
---|
654 | @Override
|
---|
655 | public String getTermsOfUseURL() {
|
---|
656 | return termsOfUseURL;
|
---|
657 | }
|
---|
658 |
|
---|
659 | /**
|
---|
660 | * Set the attribution text
|
---|
661 | * @param text The text
|
---|
662 | * @see #getAttributionText(int, ICoordinate, ICoordinate)
|
---|
663 | */
|
---|
664 | public void setAttributionText(String text) {
|
---|
665 | attributionText = text;
|
---|
666 | }
|
---|
667 |
|
---|
668 | /**
|
---|
669 | * Set the attribution image
|
---|
670 | * @param url The url of the image.
|
---|
671 | * @see #getAttributionImageURL()
|
---|
672 | */
|
---|
673 | public void setAttributionImageURL(String url) {
|
---|
674 | attributionImageURL = url;
|
---|
675 | }
|
---|
676 |
|
---|
677 | /**
|
---|
678 | * Set the image for the attribution
|
---|
679 | * @param res The image resource
|
---|
680 | * @see #getAttributionImage()
|
---|
681 | */
|
---|
682 | public void setAttributionImage(String res) {
|
---|
683 | attributionImage = res;
|
---|
684 | }
|
---|
685 |
|
---|
686 | /**
|
---|
687 | * Sets the URL the attribution should link to.
|
---|
688 | * @param url The url.
|
---|
689 | * @see #getAttributionLinkURL()
|
---|
690 | */
|
---|
691 | public void setAttributionLinkURL(String url) {
|
---|
692 | attributionLinkURL = url;
|
---|
693 | }
|
---|
694 |
|
---|
695 | /**
|
---|
696 | * Sets the text to display to the user as terms of use.
|
---|
697 | * @param text The text
|
---|
698 | * @see #getTermsOfUseText()
|
---|
699 | */
|
---|
700 | public void setTermsOfUseText(String text) {
|
---|
701 | termsOfUseText = text;
|
---|
702 | }
|
---|
703 |
|
---|
704 | /**
|
---|
705 | * Sets a url that links to the terms of use text.
|
---|
706 | * @param text The url.
|
---|
707 | * @see #getTermsOfUseURL()
|
---|
708 | */
|
---|
709 | public void setTermsOfUseURL(String text) {
|
---|
710 | termsOfUseURL = text;
|
---|
711 | }
|
---|
712 |
|
---|
713 | /**
|
---|
714 | * Sets the extended URL of this entry.
|
---|
715 | * @param url Entry extended URL containing in addition of service URL, its type and min/max zoom info
|
---|
716 | */
|
---|
717 | public void setExtendedUrl(String url) {
|
---|
718 | CheckParameterUtil.ensureParameterNotNull(url);
|
---|
719 |
|
---|
720 | // Default imagery type is WMS
|
---|
721 | this.url = url;
|
---|
722 | this.imageryType = ImageryType.WMS;
|
---|
723 |
|
---|
724 | defaultMaxZoom = 0;
|
---|
725 | defaultMinZoom = 0;
|
---|
726 | for (ImageryType type : ImageryType.values()) {
|
---|
727 | Matcher m = Pattern.compile(type.getTypeString()+"(?:\\[(?:(\\d+)[,-])?(\\d+)\\])?:(.*)").matcher(url);
|
---|
728 | if (m.matches()) {
|
---|
729 | this.url = m.group(3);
|
---|
730 | this.imageryType = type;
|
---|
731 | if (m.group(2) != null) {
|
---|
732 | defaultMaxZoom = Integer.parseInt(m.group(2));
|
---|
733 | }
|
---|
734 | if (m.group(1) != null) {
|
---|
735 | defaultMinZoom = Integer.parseInt(m.group(1));
|
---|
736 | }
|
---|
737 | break;
|
---|
738 | }
|
---|
739 | }
|
---|
740 |
|
---|
741 | if (serverProjections.isEmpty()) {
|
---|
742 | serverProjections = new ArrayList<>();
|
---|
743 | Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase(Locale.ENGLISH));
|
---|
744 | if (m.matches()) {
|
---|
745 | for (String p : m.group(1).split(",")) {
|
---|
746 | serverProjections.add(p);
|
---|
747 | }
|
---|
748 | }
|
---|
749 | }
|
---|
750 | }
|
---|
751 |
|
---|
752 | /**
|
---|
753 | * Returns the entry name.
|
---|
754 | * @return The entry name
|
---|
755 | * @since 6968
|
---|
756 | */
|
---|
757 | public String getOriginalName() {
|
---|
758 | return this.origName != null ? this.origName : this.name;
|
---|
759 | }
|
---|
760 |
|
---|
761 | /**
|
---|
762 | * Sets the entry name and handle translation.
|
---|
763 | * @param language The used language
|
---|
764 | * @param name The entry name
|
---|
765 | * @since 8091
|
---|
766 | */
|
---|
767 | public void setName(String language, String name) {
|
---|
768 | boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language);
|
---|
769 | if (LanguageInfo.isBetterLanguage(langName, language)) {
|
---|
770 | this.name = isdefault ? tr(name) : name;
|
---|
771 | this.langName = language;
|
---|
772 | }
|
---|
773 | if (origName == null || isdefault) {
|
---|
774 | this.origName = name;
|
---|
775 | }
|
---|
776 | }
|
---|
777 |
|
---|
778 | /**
|
---|
779 | * Store the id of this info to the preferences and clear it afterwards.
|
---|
780 | */
|
---|
781 | public void clearId() {
|
---|
782 | if (this.id != null) {
|
---|
783 | Collection<String> newAddedIds = new TreeSet<>(Main.pref.getCollection("imagery.layers.addedIds"));
|
---|
784 | newAddedIds.add(this.id);
|
---|
785 | Main.pref.putCollection("imagery.layers.addedIds", newAddedIds);
|
---|
786 | }
|
---|
787 | setId(null);
|
---|
788 | }
|
---|
789 |
|
---|
790 | /**
|
---|
791 | * Determines if this entry is enabled by default.
|
---|
792 | * @return {@code true} if this entry is enabled by default, {@code false} otherwise
|
---|
793 | */
|
---|
794 | public boolean isDefaultEntry() {
|
---|
795 | return defaultEntry;
|
---|
796 | }
|
---|
797 |
|
---|
798 | /**
|
---|
799 | * Sets the default state of this entry.
|
---|
800 | * @param defaultEntry {@code true} if this entry has to be enabled by default, {@code false} otherwise
|
---|
801 | */
|
---|
802 | public void setDefaultEntry(boolean defaultEntry) {
|
---|
803 | this.defaultEntry = defaultEntry;
|
---|
804 | }
|
---|
805 |
|
---|
806 | /**
|
---|
807 | * Return the data part of HTTP cookies header in case the service requires cookies to work
|
---|
808 | * @return the cookie data part
|
---|
809 | */
|
---|
810 | @Override
|
---|
811 | public String getCookies() {
|
---|
812 | return this.cookies;
|
---|
813 | }
|
---|
814 |
|
---|
815 | /**
|
---|
816 | * Gets the pixel per degree value
|
---|
817 | * @return The ppd value.
|
---|
818 | */
|
---|
819 | public double getPixelPerDegree() {
|
---|
820 | return this.pixelPerDegree;
|
---|
821 | }
|
---|
822 |
|
---|
823 | /**
|
---|
824 | * Returns the maximum zoom level.
|
---|
825 | * @return The maximum zoom level
|
---|
826 | */
|
---|
827 | @Override
|
---|
828 | public int getMaxZoom() {
|
---|
829 | return this.defaultMaxZoom;
|
---|
830 | }
|
---|
831 |
|
---|
832 | /**
|
---|
833 | * Returns the minimum zoom level.
|
---|
834 | * @return The minimum zoom level
|
---|
835 | */
|
---|
836 | @Override
|
---|
837 | public int getMinZoom() {
|
---|
838 | return this.defaultMinZoom;
|
---|
839 | }
|
---|
840 |
|
---|
841 | /**
|
---|
842 | * Returns the description text when existing.
|
---|
843 | * @return The description
|
---|
844 | * @since 8065
|
---|
845 | */
|
---|
846 | public String getDescription() {
|
---|
847 | return this.description;
|
---|
848 | }
|
---|
849 |
|
---|
850 | /**
|
---|
851 | * Sets the description text when existing.
|
---|
852 | * @param language The used language
|
---|
853 | * @param description the imagery description text
|
---|
854 | * @since 8091
|
---|
855 | */
|
---|
856 | public void setDescription(String language, String description) {
|
---|
857 | boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language);
|
---|
858 | if (LanguageInfo.isBetterLanguage(langDescription, language)) {
|
---|
859 | this.description = isdefault ? tr(description) : description;
|
---|
860 | this.langDescription = language;
|
---|
861 | }
|
---|
862 | }
|
---|
863 |
|
---|
864 | /**
|
---|
865 | * Returns a tool tip text for display.
|
---|
866 | * @return The text
|
---|
867 | * @since 8065
|
---|
868 | */
|
---|
869 | public String getToolTipText() {
|
---|
870 | StringBuilder res = new StringBuilder(getName());
|
---|
871 | boolean html = false;
|
---|
872 | String dateStr = getDate();
|
---|
873 | if (dateStr != null && !dateStr.isEmpty()) {
|
---|
874 | res.append("<br>").append(tr("Date of imagery: {0}", dateStr));
|
---|
875 | html = true;
|
---|
876 | }
|
---|
877 | if (bestMarked) {
|
---|
878 | res.append("<br>").append(tr("This imagery is marked as best in this region in other editors."));
|
---|
879 | html = true;
|
---|
880 | }
|
---|
881 | String desc = getDescription();
|
---|
882 | if (desc != null && !desc.isEmpty()) {
|
---|
883 | res.append("<br>").append(Utils.escapeReservedCharactersHTML(desc));
|
---|
884 | html = true;
|
---|
885 | }
|
---|
886 | if (html) {
|
---|
887 | res.insert(0, "<html>").append("</html>");
|
---|
888 | }
|
---|
889 | return res.toString();
|
---|
890 | }
|
---|
891 |
|
---|
892 | /**
|
---|
893 | * Returns the EULA acceptance URL, if any.
|
---|
894 | * @return The URL to an EULA text that has to be accepted before use, or {@code null}
|
---|
895 | */
|
---|
896 | public String getEulaAcceptanceRequired() {
|
---|
897 | return eulaAcceptanceRequired;
|
---|
898 | }
|
---|
899 |
|
---|
900 | /**
|
---|
901 | * Sets the EULA acceptance URL.
|
---|
902 | * @param eulaAcceptanceRequired The URL to an EULA text that has to be accepted before use
|
---|
903 | */
|
---|
904 | public void setEulaAcceptanceRequired(String eulaAcceptanceRequired) {
|
---|
905 | this.eulaAcceptanceRequired = eulaAcceptanceRequired;
|
---|
906 | }
|
---|
907 |
|
---|
908 | /**
|
---|
909 | * Returns the ISO 3166-1-alpha-2 country code.
|
---|
910 | * @return The country code (2 letters)
|
---|
911 | */
|
---|
912 | public String getCountryCode() {
|
---|
913 | return countryCode;
|
---|
914 | }
|
---|
915 |
|
---|
916 | /**
|
---|
917 | * Sets the ISO 3166-1-alpha-2 country code.
|
---|
918 | * @param countryCode The country code (2 letters)
|
---|
919 | */
|
---|
920 | public void setCountryCode(String countryCode) {
|
---|
921 | this.countryCode = countryCode;
|
---|
922 | }
|
---|
923 |
|
---|
924 | /**
|
---|
925 | * Returns the date information.
|
---|
926 | * @return The date (in the form YYYY-MM-DD;YYYY-MM-DD, where
|
---|
927 | * DD and MM as well as a second date are optional)
|
---|
928 | * @since 11570
|
---|
929 | */
|
---|
930 | public String getDate() {
|
---|
931 | return date;
|
---|
932 | }
|
---|
933 |
|
---|
934 | /**
|
---|
935 | * Sets the date information.
|
---|
936 | * @param date The date information
|
---|
937 | * @since 11570
|
---|
938 | */
|
---|
939 | public void setDate(String date) {
|
---|
940 | this.date = date;
|
---|
941 | }
|
---|
942 |
|
---|
943 | /**
|
---|
944 | * Returns the entry icon.
|
---|
945 | * @return The entry icon
|
---|
946 | */
|
---|
947 | public String getIcon() {
|
---|
948 | return icon;
|
---|
949 | }
|
---|
950 |
|
---|
951 | /**
|
---|
952 | * Sets the entry icon.
|
---|
953 | * @param icon The entry icon
|
---|
954 | */
|
---|
955 | public void setIcon(String icon) {
|
---|
956 | this.icon = icon;
|
---|
957 | }
|
---|
958 |
|
---|
959 | /**
|
---|
960 | * Get the projections supported by the server. Only relevant for
|
---|
961 | * WMS-type ImageryInfo at the moment.
|
---|
962 | * @return null, if no projections have been specified; the list
|
---|
963 | * of supported projections otherwise.
|
---|
964 | */
|
---|
965 | public List<String> getServerProjections() {
|
---|
966 | return Collections.unmodifiableList(serverProjections);
|
---|
967 | }
|
---|
968 |
|
---|
969 | /**
|
---|
970 | * Sets the list of collections the server supports
|
---|
971 | * @param serverProjections The list of supported projections
|
---|
972 | */
|
---|
973 | public void setServerProjections(Collection<String> serverProjections) {
|
---|
974 | CheckParameterUtil.ensureParameterNotNull(serverProjections, "serverProjections");
|
---|
975 | this.serverProjections = new ArrayList<>(serverProjections);
|
---|
976 | }
|
---|
977 |
|
---|
978 | /**
|
---|
979 | * Returns the extended URL, containing in addition of service URL, its type and min/max zoom info.
|
---|
980 | * @return The extended URL
|
---|
981 | */
|
---|
982 | public String getExtendedUrl() {
|
---|
983 | return imageryType.getTypeString() + (defaultMaxZoom != 0
|
---|
984 | ? ('['+(defaultMinZoom != 0 ? (Integer.toString(defaultMinZoom) + ',') : "")+defaultMaxZoom+']') : "") + ':' + url;
|
---|
985 | }
|
---|
986 |
|
---|
987 | /**
|
---|
988 | * Gets a unique toolbar key to store this layer as toolbar item
|
---|
989 | * @return The kay.
|
---|
990 | */
|
---|
991 | public String getToolbarName() {
|
---|
992 | String res = name;
|
---|
993 | if (pixelPerDegree != 0) {
|
---|
994 | res += "#PPD="+pixelPerDegree;
|
---|
995 | }
|
---|
996 | return res;
|
---|
997 | }
|
---|
998 |
|
---|
999 | /**
|
---|
1000 | * Gets the name that should be displayed in the menu to add this imagery layer.
|
---|
1001 | * @return The text.
|
---|
1002 | */
|
---|
1003 | public String getMenuName() {
|
---|
1004 | String res = name;
|
---|
1005 | if (pixelPerDegree != 0) {
|
---|
1006 | res += " ("+pixelPerDegree+')';
|
---|
1007 | }
|
---|
1008 | return res;
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | /**
|
---|
1012 | * Determines if this entry requires attribution.
|
---|
1013 | * @return {@code true} if some attribution text has to be displayed, {@code false} otherwise
|
---|
1014 | */
|
---|
1015 | public boolean hasAttribution() {
|
---|
1016 | return attributionText != null;
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | /**
|
---|
1020 | * Copies attribution from another {@code ImageryInfo}.
|
---|
1021 | * @param i The other imagery info to get attribution from
|
---|
1022 | */
|
---|
1023 | public void copyAttribution(ImageryInfo i) {
|
---|
1024 | this.attributionImage = i.attributionImage;
|
---|
1025 | this.attributionImageURL = i.attributionImageURL;
|
---|
1026 | this.attributionText = i.attributionText;
|
---|
1027 | this.attributionLinkURL = i.attributionLinkURL;
|
---|
1028 | this.termsOfUseText = i.termsOfUseText;
|
---|
1029 | this.termsOfUseURL = i.termsOfUseURL;
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | /**
|
---|
1033 | * Applies the attribution from this object to a tile source.
|
---|
1034 | * @param s The tile source
|
---|
1035 | */
|
---|
1036 | public void setAttribution(AbstractTileSource s) {
|
---|
1037 | if (attributionText != null) {
|
---|
1038 | if ("osm".equals(attributionText)) {
|
---|
1039 | s.setAttributionText(new Mapnik().getAttributionText(0, null, null));
|
---|
1040 | } else {
|
---|
1041 | s.setAttributionText(attributionText);
|
---|
1042 | }
|
---|
1043 | }
|
---|
1044 | if (attributionLinkURL != null) {
|
---|
1045 | if ("osm".equals(attributionLinkURL)) {
|
---|
1046 | s.setAttributionLinkURL(new Mapnik().getAttributionLinkURL());
|
---|
1047 | } else {
|
---|
1048 | s.setAttributionLinkURL(attributionLinkURL);
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | if (attributionImage != null) {
|
---|
1052 | ImageIcon i = ImageProvider.getIfAvailable(null, attributionImage);
|
---|
1053 | if (i != null) {
|
---|
1054 | s.setAttributionImage(i.getImage());
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | if (attributionImageURL != null) {
|
---|
1058 | s.setAttributionImageURL(attributionImageURL);
|
---|
1059 | }
|
---|
1060 | if (termsOfUseText != null) {
|
---|
1061 | s.setTermsOfUseText(termsOfUseText);
|
---|
1062 | }
|
---|
1063 | if (termsOfUseURL != null) {
|
---|
1064 | if ("osm".equals(termsOfUseURL)) {
|
---|
1065 | s.setTermsOfUseURL(new Mapnik().getTermsOfUseURL());
|
---|
1066 | } else {
|
---|
1067 | s.setTermsOfUseURL(termsOfUseURL);
|
---|
1068 | }
|
---|
1069 | }
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | /**
|
---|
1073 | * Returns the imagery type.
|
---|
1074 | * @return The imagery type
|
---|
1075 | */
|
---|
1076 | public ImageryType getImageryType() {
|
---|
1077 | return imageryType;
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | /**
|
---|
1081 | * Sets the imagery type.
|
---|
1082 | * @param imageryType The imagery type
|
---|
1083 | */
|
---|
1084 | public void setImageryType(ImageryType imageryType) {
|
---|
1085 | this.imageryType = imageryType;
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | /**
|
---|
1089 | * Returns true if this layer's URL is matched by one of the regular
|
---|
1090 | * expressions kept by the current OsmApi instance.
|
---|
1091 | * @return {@code true} is this entry is blacklisted, {@code false} otherwise
|
---|
1092 | */
|
---|
1093 | public boolean isBlacklisted() {
|
---|
1094 | Capabilities capabilities = OsmApi.getOsmApi().getCapabilities();
|
---|
1095 | return capabilities != null && capabilities.isOnImageryBlacklist(this.url);
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | /**
|
---|
1099 | * Sets the map of <header name, header value> that if any of this header
|
---|
1100 | * will be returned, then this tile will be treated as "no tile at this zoom level"
|
---|
1101 | *
|
---|
1102 | * @param noTileHeaders Map of <header name, header value> which will be treated as "no tile at this zoom level"
|
---|
1103 | * @since 9613
|
---|
1104 | */
|
---|
1105 | public void setNoTileHeaders(MultiMap<String, String> noTileHeaders) {
|
---|
1106 | if (noTileHeaders == null || noTileHeaders.isEmpty()) {
|
---|
1107 | this.noTileHeaders = null;
|
---|
1108 | } else {
|
---|
1109 | this.noTileHeaders = noTileHeaders.toMap();
|
---|
1110 | }
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | @Override
|
---|
1114 | public Map<String, Set<String>> getNoTileHeaders() {
|
---|
1115 | return noTileHeaders;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /**
|
---|
1119 | * Sets the map of <checksum type, checksum value> that if any tile with that checksum
|
---|
1120 | * will be returned, then this tile will be treated as "no tile at this zoom level"
|
---|
1121 | *
|
---|
1122 | * @param noTileChecksums Map of <checksum type, checksum value> which will be treated as "no tile at this zoom level"
|
---|
1123 | * @since 9613
|
---|
1124 | */
|
---|
1125 | public void setNoTileChecksums(MultiMap<String, String> noTileChecksums) {
|
---|
1126 | if (noTileChecksums == null || noTileChecksums.isEmpty()) {
|
---|
1127 | this.noTileChecksums = null;
|
---|
1128 | } else {
|
---|
1129 | this.noTileChecksums = noTileChecksums.toMap();
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | @Override
|
---|
1134 | public Map<String, Set<String>> getNoTileChecksums() {
|
---|
1135 | return noTileChecksums;
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | /**
|
---|
1139 | * Returns the map of <header name, metadata key> indicating, which HTTP headers should
|
---|
1140 | * be moved to metadata
|
---|
1141 | *
|
---|
1142 | * @param metadataHeaders map of <header name, metadata key> indicating, which HTTP headers should be moved to metadata
|
---|
1143 | * @since 8418
|
---|
1144 | */
|
---|
1145 | public void setMetadataHeaders(Map<String, String> metadataHeaders) {
|
---|
1146 | if (metadataHeaders == null || metadataHeaders.isEmpty()) {
|
---|
1147 | this.metadataHeaders = null;
|
---|
1148 | } else {
|
---|
1149 | this.metadataHeaders = metadataHeaders;
|
---|
1150 | }
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | /**
|
---|
1154 | * Gets the flag if the georeference is valid.
|
---|
1155 | * @return <code>true</code> if it is valid.
|
---|
1156 | */
|
---|
1157 | public boolean isGeoreferenceValid() {
|
---|
1158 | return isGeoreferenceValid;
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | /**
|
---|
1162 | * Sets an indicator that the georeference is valid
|
---|
1163 | * @param isGeoreferenceValid <code>true</code> if it is marked as valid.
|
---|
1164 | */
|
---|
1165 | public void setGeoreferenceValid(boolean isGeoreferenceValid) {
|
---|
1166 | this.isGeoreferenceValid = isGeoreferenceValid;
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | /**
|
---|
1170 | * Returns the status of "best" marked status in other editors.
|
---|
1171 | * @return <code>true</code> if it is marked as best.
|
---|
1172 | * @since 11575
|
---|
1173 | */
|
---|
1174 | public boolean isBestMarked() {
|
---|
1175 | return bestMarked;
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | /**
|
---|
1179 | * Sets an indicator that in other editors it is marked as best imagery
|
---|
1180 | * @param bestMarked <code>true</code> if it is marked as best in other editors.
|
---|
1181 | * @since 11575
|
---|
1182 | */
|
---|
1183 | public void setBestMarked(boolean bestMarked) {
|
---|
1184 | this.bestMarked = bestMarked;
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 | /**
|
---|
1188 | * Adds a mirror entry. Mirror entries are completed with the data from the master entry
|
---|
1189 | * and only describe another method to access identical data.
|
---|
1190 | *
|
---|
1191 | * @param entry the mirror to be added
|
---|
1192 | * @since 9658
|
---|
1193 | */
|
---|
1194 | public void addMirror(ImageryInfo entry) {
|
---|
1195 | if (mirrors == null) {
|
---|
1196 | mirrors = new ArrayList<>();
|
---|
1197 | }
|
---|
1198 | mirrors.add(entry);
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | /**
|
---|
1202 | * Returns the mirror entries. Entries are completed with master entry data.
|
---|
1203 | *
|
---|
1204 | * @return the list of mirrors
|
---|
1205 | * @since 9658
|
---|
1206 | */
|
---|
1207 | public List<ImageryInfo> getMirrors() {
|
---|
1208 | List<ImageryInfo> l = new ArrayList<>();
|
---|
1209 | if (mirrors != null) {
|
---|
1210 | int num = 1;
|
---|
1211 | for (ImageryInfo i : mirrors) {
|
---|
1212 | ImageryInfo n = new ImageryInfo(this);
|
---|
1213 | if (i.defaultMaxZoom != 0) {
|
---|
1214 | n.defaultMaxZoom = i.defaultMaxZoom;
|
---|
1215 | }
|
---|
1216 | if (i.defaultMinZoom != 0) {
|
---|
1217 | n.defaultMinZoom = i.defaultMinZoom;
|
---|
1218 | }
|
---|
1219 | n.setServerProjections(i.getServerProjections());
|
---|
1220 | n.url = i.url;
|
---|
1221 | n.imageryType = i.imageryType;
|
---|
1222 | if (i.getTileSize() != 0) {
|
---|
1223 | n.setTileSize(i.getTileSize());
|
---|
1224 | }
|
---|
1225 | if (n.id != null) {
|
---|
1226 | n.id = n.id + "_mirror"+num;
|
---|
1227 | }
|
---|
1228 | if (num > 1) {
|
---|
1229 | n.name = tr("{0} mirror server {1}", n.name, num);
|
---|
1230 | if (n.origName != null) {
|
---|
1231 | n.origName += " mirror server " + num;
|
---|
1232 | }
|
---|
1233 | } else {
|
---|
1234 | n.name = tr("{0} mirror server", n.name);
|
---|
1235 | if (n.origName != null) {
|
---|
1236 | n.origName += " mirror server";
|
---|
1237 | }
|
---|
1238 | }
|
---|
1239 | l.add(n);
|
---|
1240 | ++num;
|
---|
1241 | }
|
---|
1242 | }
|
---|
1243 | return l;
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | /**
|
---|
1247 | * Returns default layers that should be shown for this Imagery (if at all supported by imagery provider)
|
---|
1248 | * If no layer is set to default and there is more than one imagery available, then user will be asked to choose the layer
|
---|
1249 | * to work on
|
---|
1250 | * @return Collection of the layer names
|
---|
1251 | */
|
---|
1252 | public Collection<DefaultLayer> getDefaultLayers() {
|
---|
1253 | return defaultLayers;
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | /**
|
---|
1257 | * Sets the default layers that user will work with
|
---|
1258 | * @param layers set the list of default layers
|
---|
1259 | */
|
---|
1260 | public void setDefaultLayers(Collection<DefaultLayer> layers) {
|
---|
1261 | if (ImageryType.WMTS.equals(this.imageryType)) {
|
---|
1262 | CheckParameterUtil.ensureThat(layers == null ||
|
---|
1263 | layers.isEmpty() ||
|
---|
1264 | layers.iterator().next() instanceof WMTSDefaultLayer, "Incorrect default layer");
|
---|
1265 | }
|
---|
1266 | this.defaultLayers = layers;
|
---|
1267 | }
|
---|
1268 | }
|
---|