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