source: josm/trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java@ 9600

Last change on this file since 9600 was 9371, checked in by simon04, 8 years ago

Java 7: use Objects.equals and Objects.hash

  • Property svn:eol-style set to native
File size: 33.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Image;
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.Collections;
11import java.util.List;
12import java.util.Locale;
13import java.util.Map;
14import java.util.Objects;
15import java.util.TreeSet;
16import java.util.regex.Matcher;
17import java.util.regex.Pattern;
18
19import javax.swing.ImageIcon;
20
21import org.openstreetmap.gui.jmapviewer.OsmMercator;
22import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
23import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
24import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource;
25import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik;
26import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
27import org.openstreetmap.josm.Main;
28import org.openstreetmap.josm.data.Bounds;
29import org.openstreetmap.josm.data.Preferences.pref;
30import org.openstreetmap.josm.io.Capabilities;
31import org.openstreetmap.josm.io.OsmApi;
32import org.openstreetmap.josm.tools.CheckParameterUtil;
33import org.openstreetmap.josm.tools.ImageProvider;
34import org.openstreetmap.josm.tools.LanguageInfo;
35
36/**
37 * Class that stores info about an image background layer.
38 *
39 * @author Frederik Ramm
40 */
41public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInfo>, Attributed {
42
43 /**
44 * Type of imagery entry.
45 */
46 public enum ImageryType {
47 /** A WMS (Web Map Service) entry. **/
48 WMS("wms"),
49 /** A TMS (Tile Map Service) entry. **/
50 TMS("tms"),
51 /** An HTML proxy (previously used for Yahoo imagery) entry. **/
52 HTML("html"),
53 /** TMS entry for Microsoft Bing. */
54 BING("bing"),
55 /** TMS entry for Russian company <a href="https://wiki.openstreetmap.org/wiki/WikiProject_Russia/kosmosnimki">ScanEx</a>. **/
56 SCANEX("scanex"),
57 /** A WMS endpoint entry only stores the WMS server info, without layer, which are chosen later by the user. **/
58 WMS_ENDPOINT("wms_endpoint"),
59 /** WMTS stores GetCapabilities URL. Does not store any information about the layer **/
60 WMTS("wmts");
61
62
63 private final String typeString;
64
65 ImageryType(String urlString) {
66 this.typeString = urlString;
67 }
68
69 /**
70 * Returns the unique string identifying this type.
71 * @return the unique string identifying this type
72 * @since 6690
73 */
74 public final String getTypeString() {
75 return typeString;
76 }
77
78 /**
79 * Returns the imagery type from the given type string.
80 * @param s The type string
81 * @return the imagery type matching the given type string
82 */
83 public static ImageryType fromString(String s) {
84 for (ImageryType type : ImageryType.values()) {
85 if (type.getTypeString().equals(s)) {
86 return type;
87 }
88 }
89 return null;
90 }
91 }
92
93 /**
94 * Multi-polygon bounds for imagery backgrounds.
95 * Used to display imagery coverage in preferences and to determine relevant imagery entries based on edit location.
96 */
97 public static class ImageryBounds extends Bounds {
98
99 /**
100 * Constructs a new {@code ImageryBounds} from string.
101 * @param asString The string containing the list of shapes defining this bounds
102 * @param separator The shape separator in the given string, usually a comma
103 */
104 public ImageryBounds(String asString, String separator) {
105 super(asString, separator);
106 }
107
108 private List<Shape> shapes = new ArrayList<>();
109
110 /**
111 * Adds a new shape to this bounds.
112 * @param shape The shape to add
113 */
114 public final void addShape(Shape shape) {
115 this.shapes.add(shape);
116 }
117
118 /**
119 * Sets the list of shapes defining this bounds.
120 * @param shapes The list of shapes defining this bounds.
121 */
122 public final void setShapes(List<Shape> shapes) {
123 this.shapes = shapes;
124 }
125
126 /**
127 * Returns the list of shapes defining this bounds.
128 * @return The list of shapes defining this bounds
129 */
130 public final List<Shape> getShapes() {
131 return shapes;
132 }
133
134 @Override
135 public int hashCode() {
136 return Objects.hash(super.hashCode(), shapes);
137 }
138
139 @Override
140 public boolean equals(Object o) {
141 if (this == o) return true;
142 if (o == null || getClass() != o.getClass()) return false;
143 if (!super.equals(o)) return false;
144 ImageryBounds that = (ImageryBounds) o;
145 return Objects.equals(shapes, that.shapes);
146 }
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;
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 /** icon used in menu */
190 private String icon;
191 private boolean isGeoreferenceValid = false;
192 private boolean isEpsg4326To3857Supported = false;
193 // when adding a field, also adapt the ImageryInfo(ImageryInfo)
194 // and ImageryInfo(ImageryPreferenceEntry) constructor, equals method, and ImageryPreferenceEntry
195
196 /**
197 * Auxiliary class to save an {@link ImageryInfo} object in the preferences.
198 */
199 public static class ImageryPreferenceEntry {
200 @pref String name;
201 @pref String id;
202 @pref String type;
203 @pref String url;
204 @pref double pixel_per_eastnorth;
205 @pref String eula;
206 @pref String attribution_text;
207 @pref String attribution_url;
208 @pref String logo_image;
209 @pref String logo_url;
210 @pref String terms_of_use_text;
211 @pref String terms_of_use_url;
212 @pref String country_code = "";
213 @pref int max_zoom;
214 @pref int min_zoom;
215 @pref String cookies;
216 @pref String bounds;
217 @pref String shapes;
218 @pref String projections;
219 @pref String icon;
220 @pref String description;
221 @pref Map<String, String> noTileHeaders;
222 @pref int tileSize = OsmMercator.DEFAUL_TILE_SIZE;
223 @pref Map<String, String> metadataHeaders;
224 @pref boolean valid_georeference;
225 @pref boolean supports_epsg_4326_to_3857_conversion;
226
227 /**
228 * Constructs a new empty WMS {@code ImageryPreferenceEntry}.
229 */
230 public ImageryPreferenceEntry() {
231 }
232
233 /**
234 * Constructs a new {@code ImageryPreferenceEntry} from a given {@code ImageryInfo}.
235 * @param i The corresponding imagery info
236 */
237 public ImageryPreferenceEntry(ImageryInfo i) {
238 name = i.name;
239 id = i.id;
240 type = i.imageryType.getTypeString();
241 url = i.url;
242 pixel_per_eastnorth = i.pixelPerDegree;
243 eula = i.eulaAcceptanceRequired;
244 attribution_text = i.attributionText;
245 attribution_url = i.attributionLinkURL;
246 logo_image = i.attributionImage;
247 logo_url = i.attributionImageURL;
248 terms_of_use_text = i.termsOfUseText;
249 terms_of_use_url = i.termsOfUseURL;
250 country_code = i.countryCode;
251 max_zoom = i.defaultMaxZoom;
252 min_zoom = i.defaultMinZoom;
253 cookies = i.cookies;
254 icon = i.icon;
255 description = i.description;
256 if (i.bounds != null) {
257 bounds = i.bounds.encodeAsString(",");
258 StringBuilder shapesString = new StringBuilder();
259 for (Shape s : i.bounds.getShapes()) {
260 if (shapesString.length() > 0) {
261 shapesString.append(';');
262 }
263 shapesString.append(s.encodeAsString(","));
264 }
265 if (shapesString.length() > 0) {
266 shapes = shapesString.toString();
267 }
268 }
269 if (i.serverProjections != null && !i.serverProjections.isEmpty()) {
270 StringBuilder val = new StringBuilder();
271 for (String p : i.serverProjections) {
272 if (val.length() > 0) {
273 val.append(',');
274 }
275 val.append(p);
276 }
277 projections = val.toString();
278 }
279 if (i.noTileHeaders != null && !i.noTileHeaders.isEmpty()) {
280 noTileHeaders = i.noTileHeaders;
281 }
282
283 if (i.metadataHeaders != null && !i.metadataHeaders.isEmpty()) {
284 metadataHeaders = i.metadataHeaders;
285 }
286
287 tileSize = i.getTileSize();
288
289 valid_georeference = i.isGeoreferenceValid();
290 supports_epsg_4326_to_3857_conversion = i.isEpsg4326To3857Supported();
291
292 }
293
294 @Override
295 public String toString() {
296 StringBuilder s = new StringBuilder("ImageryPreferenceEntry [name=").append(name);
297 if (id != null) {
298 s.append(" id=").append(id);
299 }
300 s.append(']');
301 return s.toString();
302 }
303 }
304
305 /**
306 * Constructs a new WMS {@code ImageryInfo}.
307 */
308 public ImageryInfo() {
309 super();
310 }
311
312 /**
313 * Constructs a new WMS {@code ImageryInfo} with a given name.
314 * @param name The entry name
315 */
316 public ImageryInfo(String name) {
317 super(name);
318 }
319
320 /**
321 * Constructs a new WMS {@code ImageryInfo} with given name and extended URL.
322 * @param name The entry name
323 * @param url The entry extended URL
324 */
325 public ImageryInfo(String name, String url) {
326 this(name);
327 setExtendedUrl(url);
328 }
329
330 /**
331 * Constructs a new WMS {@code ImageryInfo} with given name, extended and EULA URLs.
332 * @param name The entry name
333 * @param url The entry URL
334 * @param eulaAcceptanceRequired The EULA URL
335 */
336 public ImageryInfo(String name, String url, String eulaAcceptanceRequired) {
337 this(name);
338 setExtendedUrl(url);
339 this.eulaAcceptanceRequired = eulaAcceptanceRequired;
340 }
341
342 /**
343 * Constructs a new {@code ImageryInfo} with given name, url, extended and EULA URLs.
344 * @param name The entry name
345 * @param url The entry URL
346 * @param type The entry imagery type. If null, WMS will be used as default
347 * @param eulaAcceptanceRequired The EULA URL
348 * @param cookies The data part of HTTP cookies header in case the service requires cookies to work
349 * @throws IllegalArgumentException if type refers to an unknown imagery type
350 */
351 public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies) {
352 this(name);
353 setExtendedUrl(url);
354 ImageryType t = ImageryType.fromString(type);
355 this.cookies = cookies;
356 this.eulaAcceptanceRequired = eulaAcceptanceRequired;
357 if (t != null) {
358 this.imageryType = t;
359 } else if (type != null && !type.trim().isEmpty()) {
360 throw new IllegalArgumentException("unknown type: "+type);
361 }
362 }
363
364 public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies, String id) {
365 this(name, url, type, eulaAcceptanceRequired, cookies);
366 setId(id);
367 }
368
369 /**
370 * Constructs a new {@code ImageryInfo} from an imagery preference entry.
371 * @param e The imagery preference entry
372 */
373 public ImageryInfo(ImageryPreferenceEntry e) {
374 super(e.name, e.url, e.id);
375 CheckParameterUtil.ensureParameterNotNull(e.name, "name");
376 CheckParameterUtil.ensureParameterNotNull(e.url, "url");
377 description = e.description;
378 cookies = e.cookies;
379 eulaAcceptanceRequired = e.eula;
380 imageryType = ImageryType.fromString(e.type);
381 if (imageryType == null) throw new IllegalArgumentException("unknown type");
382 pixelPerDegree = e.pixel_per_eastnorth;
383 defaultMaxZoom = e.max_zoom;
384 defaultMinZoom = e.min_zoom;
385 if (e.bounds != null) {
386 bounds = new ImageryBounds(e.bounds, ",");
387 if (e.shapes != null) {
388 try {
389 for (String s : e.shapes.split(";")) {
390 bounds.addShape(new Shape(s, ","));
391 }
392 } catch (IllegalArgumentException ex) {
393 Main.warn(ex);
394 }
395 }
396 }
397 if (e.projections != null) {
398 serverProjections = Arrays.asList(e.projections.split(","));
399 }
400 attributionText = e.attribution_text;
401 attributionLinkURL = e.attribution_url;
402 attributionImage = e.logo_image;
403 attributionImageURL = e.logo_url;
404 termsOfUseText = e.terms_of_use_text;
405 termsOfUseURL = e.terms_of_use_url;
406 countryCode = e.country_code;
407 icon = e.icon;
408 if (e.noTileHeaders != null) {
409 noTileHeaders = e.noTileHeaders;
410 }
411 setTileSize(e.tileSize);
412 metadataHeaders = e.metadataHeaders;
413 isEpsg4326To3857Supported = e.supports_epsg_4326_to_3857_conversion;
414 isGeoreferenceValid = e.valid_georeference;
415 }
416
417 /**
418 * Constructs a new {@code ImageryInfo} from an existing one.
419 * @param i The other imagery info
420 */
421 public ImageryInfo(ImageryInfo i) {
422 super(i.name, i.url, i.id);
423 this.defaultEntry = i.defaultEntry;
424 this.cookies = i.cookies;
425 this.eulaAcceptanceRequired = null;
426 this.imageryType = i.imageryType;
427 this.pixelPerDegree = i.pixelPerDegree;
428 this.defaultMaxZoom = i.defaultMaxZoom;
429 this.defaultMinZoom = i.defaultMinZoom;
430 this.bounds = i.bounds;
431 this.serverProjections = i.serverProjections;
432 this.attributionText = i.attributionText;
433 this.attributionLinkURL = i.attributionLinkURL;
434 this.attributionImage = i.attributionImage;
435 this.attributionImageURL = i.attributionImageURL;
436 this.termsOfUseText = i.termsOfUseText;
437 this.termsOfUseURL = i.termsOfUseURL;
438 this.countryCode = i.countryCode;
439 this.icon = i.icon;
440 this.description = i.description;
441 this.noTileHeaders = i.noTileHeaders;
442 this.metadataHeaders = i.metadataHeaders;
443 this.isEpsg4326To3857Supported = i.isEpsg4326To3857Supported;
444 this.isGeoreferenceValid = i.isGeoreferenceValid;
445 }
446
447 @Override
448 public int hashCode() {
449 return Objects.hash(url, imageryType);
450 }
451
452 /**
453 * Check if this object equals another ImageryInfo with respect to the properties
454 * that get written to the preference file.
455 *
456 * The field {@link #pixelPerDegree} is ignored.
457 *
458 * @param other the ImageryInfo object to compare to
459 * @return true if they are equal
460 */
461 public boolean equalsPref(ImageryInfo other) {
462 if (other == null) {
463 return false;
464 }
465
466 return
467 Objects.equals(this.name, other.name) &&
468 Objects.equals(this.id, other.id) &&
469 Objects.equals(this.url, other.url) &&
470 Objects.equals(this.cookies, other.cookies) &&
471 Objects.equals(this.eulaAcceptanceRequired, other.eulaAcceptanceRequired) &&
472 Objects.equals(this.imageryType, other.imageryType) &&
473 Objects.equals(this.defaultMaxZoom, other.defaultMaxZoom) &&
474 Objects.equals(this.defaultMinZoom, other.defaultMinZoom) &&
475 Objects.equals(this.bounds, other.bounds) &&
476 Objects.equals(this.serverProjections, other.serverProjections) &&
477 Objects.equals(this.attributionText, other.attributionText) &&
478 Objects.equals(this.attributionLinkURL, other.attributionLinkURL) &&
479 Objects.equals(this.attributionImageURL, other.attributionImageURL) &&
480 Objects.equals(this.attributionImage, other.attributionImage) &&
481 Objects.equals(this.termsOfUseText, other.termsOfUseText) &&
482 Objects.equals(this.termsOfUseURL, other.termsOfUseURL) &&
483 Objects.equals(this.countryCode, other.countryCode) &&
484 Objects.equals(this.icon, other.icon) &&
485 Objects.equals(this.description, other.description) &&
486 Objects.equals(this.noTileHeaders, other.noTileHeaders) &&
487 Objects.equals(this.metadataHeaders, other.metadataHeaders);
488 }
489
490 @Override
491 public boolean equals(Object o) {
492 if (this == o) return true;
493 if (o == null || getClass() != o.getClass()) return false;
494 ImageryInfo that = (ImageryInfo) o;
495 return imageryType == that.imageryType && Objects.equals(url, that.url);
496 }
497
498 @Override
499 public String toString() {
500 return "ImageryInfo{" +
501 "name='" + name + '\'' +
502 ", countryCode='" + countryCode + '\'' +
503 ", url='" + url + '\'' +
504 ", imageryType=" + imageryType +
505 '}';
506 }
507
508 @Override
509 public int compareTo(ImageryInfo in) {
510 int i = countryCode.compareTo(in.countryCode);
511 if (i == 0) {
512 i = name.toLowerCase(Locale.ENGLISH).compareTo(in.name.toLowerCase(Locale.ENGLISH));
513 }
514 if (i == 0) {
515 i = url.compareTo(in.url);
516 }
517 if (i == 0) {
518 i = Double.compare(pixelPerDegree, in.pixelPerDegree);
519 }
520 return i;
521 }
522
523 public boolean equalsBaseValues(ImageryInfo in) {
524 return url.equals(in.url);
525 }
526
527 public void setPixelPerDegree(double ppd) {
528 this.pixelPerDegree = ppd;
529 }
530
531 /**
532 * Sets the maximum zoom level.
533 * @param defaultMaxZoom The maximum zoom level
534 */
535 public void setDefaultMaxZoom(int defaultMaxZoom) {
536 this.defaultMaxZoom = defaultMaxZoom;
537 }
538
539 /**
540 * Sets the minimum zoom level.
541 * @param defaultMinZoom The minimum zoom level
542 */
543 public void setDefaultMinZoom(int defaultMinZoom) {
544 this.defaultMinZoom = defaultMinZoom;
545 }
546
547 /**
548 * Sets the imagery polygonial bounds.
549 * @param b The imagery bounds (non-rectangular)
550 */
551 public void setBounds(ImageryBounds b) {
552 this.bounds = b;
553 }
554
555 /**
556 * Returns the imagery polygonial bounds.
557 * @return The imagery bounds (non-rectangular)
558 */
559 public ImageryBounds getBounds() {
560 return bounds;
561 }
562
563 @Override
564 public boolean requiresAttribution() {
565 return attributionText != null || attributionImage != null || termsOfUseText != null || termsOfUseURL != null;
566 }
567
568 @Override
569 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
570 return attributionText;
571 }
572
573 @Override
574 public String getAttributionLinkURL() {
575 return attributionLinkURL;
576 }
577
578 @Override
579 public Image getAttributionImage() {
580 ImageIcon i = ImageProvider.getIfAvailable(attributionImage);
581 if (i != null) {
582 return i.getImage();
583 }
584 return null;
585 }
586
587 @Override
588 public String getAttributionImageURL() {
589 return attributionImageURL;
590 }
591
592 @Override
593 public String getTermsOfUseText() {
594 return termsOfUseText;
595 }
596
597 @Override
598 public String getTermsOfUseURL() {
599 return termsOfUseURL;
600 }
601
602 public void setAttributionText(String text) {
603 attributionText = text;
604 }
605
606 public void setAttributionImageURL(String text) {
607 attributionImageURL = text;
608 }
609
610 public void setAttributionImage(String text) {
611 attributionImage = text;
612 }
613
614 public void setAttributionLinkURL(String text) {
615 attributionLinkURL = text;
616 }
617
618 public void setTermsOfUseText(String text) {
619 termsOfUseText = text;
620 }
621
622 public void setTermsOfUseURL(String text) {
623 termsOfUseURL = text;
624 }
625
626 /**
627 * Sets the extended URL of this entry.
628 * @param url Entry extended URL containing in addition of service URL, its type and min/max zoom info
629 */
630 public void setExtendedUrl(String url) {
631 CheckParameterUtil.ensureParameterNotNull(url);
632
633 // Default imagery type is WMS
634 this.url = url;
635 this.imageryType = ImageryType.WMS;
636
637 defaultMaxZoom = 0;
638 defaultMinZoom = 0;
639 for (ImageryType type : ImageryType.values()) {
640 Matcher m = Pattern.compile(type.getTypeString()+"(?:\\[(?:(\\d+),)?(\\d+)\\])?:(.*)").matcher(url);
641 if (m.matches()) {
642 this.url = m.group(3);
643 this.imageryType = type;
644 if (m.group(2) != null) {
645 defaultMaxZoom = Integer.parseInt(m.group(2));
646 }
647 if (m.group(1) != null) {
648 defaultMinZoom = Integer.parseInt(m.group(1));
649 }
650 break;
651 }
652 }
653
654 if (serverProjections == null || serverProjections.isEmpty()) {
655 try {
656 serverProjections = new ArrayList<>();
657 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase(Locale.ENGLISH));
658 if (m.matches()) {
659 for (String p : m.group(1).split(",")) {
660 serverProjections.add(p);
661 }
662 }
663 } catch (Exception e) {
664 Main.warn(e);
665 }
666 }
667 }
668
669 /**
670 * Returns the entry name.
671 * @return The entry name
672 * @since 6968
673 */
674 public String getOriginalName() {
675 return this.origName != null ? this.origName : this.name;
676 }
677
678 /**
679 * Sets the entry name and handle translation.
680 * @param language The used language
681 * @param name The entry name
682 * @since 8091
683 */
684 public void setName(String language, String name) {
685 boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language);
686 if (LanguageInfo.isBetterLanguage(langName, language)) {
687 this.name = isdefault ? tr(name) : name;
688 this.langName = language;
689 }
690 if (origName == null || isdefault) {
691 this.origName = name;
692 }
693 }
694
695 public void clearId() {
696 if (this.id != null) {
697 Collection<String> newAddedIds = new TreeSet<>(Main.pref.getCollection("imagery.layers.addedIds"));
698 newAddedIds.add(this.id);
699 Main.pref.putCollection("imagery.layers.addedIds", newAddedIds);
700 }
701 setId(null);
702 }
703
704 /**
705 * Determines if this entry is enabled by default.
706 * @return {@code true} if this entry is enabled by default, {@code false} otherwise
707 */
708 public boolean isDefaultEntry() {
709 return defaultEntry;
710 }
711
712 /**
713 * Sets the default state of this entry.
714 * @param defaultEntry {@code true} if this entry has to be enabled by default, {@code false} otherwise
715 */
716 public void setDefaultEntry(boolean defaultEntry) {
717 this.defaultEntry = defaultEntry;
718 }
719
720 /**
721 * Return the data part of HTTP cookies header in case the service requires cookies to work
722 * @return the cookie data part
723 */
724 @Override
725 public String getCookies() {
726 return this.cookies;
727 }
728
729 public double getPixelPerDegree() {
730 return this.pixelPerDegree;
731 }
732
733 /**
734 * Returns the maximum zoom level.
735 * @return The maximum zoom level
736 */
737 @Override
738 public int getMaxZoom() {
739 return this.defaultMaxZoom;
740 }
741
742 /**
743 * Returns the minimum zoom level.
744 * @return The minimum zoom level
745 */
746 @Override
747 public int getMinZoom() {
748 return this.defaultMinZoom;
749 }
750
751 /**
752 * Returns the description text when existing.
753 * @return The description
754 * @since 8065
755 */
756 public String getDescription() {
757 return this.description;
758 }
759
760 /**
761 * Sets the description text when existing.
762 * @param language The used language
763 * @param description the imagery description text
764 * @since 8091
765 */
766 public void setDescription(String language, String description) {
767 boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language);
768 if (LanguageInfo.isBetterLanguage(langDescription, language)) {
769 this.description = isdefault ? tr(description) : description;
770 this.langDescription = language;
771 }
772 }
773
774 /**
775 * Returns a tool tip text for display.
776 * @return The text
777 * @since 8065
778 */
779 public String getToolTipText() {
780 String desc = getDescription();
781 if (desc != null && !desc.isEmpty()) {
782 return "<html>" + getName() + "<br>" + desc + "</html>";
783 }
784 return getName();
785 }
786
787 /**
788 * Returns the EULA acceptance URL, if any.
789 * @return The URL to an EULA text that has to be accepted before use, or {@code null}
790 */
791 public String getEulaAcceptanceRequired() {
792 return eulaAcceptanceRequired;
793 }
794
795 /**
796 * Sets the EULA acceptance URL.
797 * @param eulaAcceptanceRequired The URL to an EULA text that has to be accepted before use
798 */
799 public void setEulaAcceptanceRequired(String eulaAcceptanceRequired) {
800 this.eulaAcceptanceRequired = eulaAcceptanceRequired;
801 }
802
803 /**
804 * Returns the ISO 3166-1-alpha-2 country code.
805 * @return The country code (2 letters)
806 */
807 public String getCountryCode() {
808 return countryCode;
809 }
810
811 /**
812 * Sets the ISO 3166-1-alpha-2 country code.
813 * @param countryCode The country code (2 letters)
814 */
815 public void setCountryCode(String countryCode) {
816 this.countryCode = countryCode;
817 }
818
819 /**
820 * Returns the entry icon.
821 * @return The entry icon
822 */
823 public String getIcon() {
824 return icon;
825 }
826
827 /**
828 * Sets the entry icon.
829 * @param icon The entry icon
830 */
831 public void setIcon(String icon) {
832 this.icon = icon;
833 }
834
835 /**
836 * Get the projections supported by the server. Only relevant for
837 * WMS-type ImageryInfo at the moment.
838 * @return null, if no projections have been specified; the list
839 * of supported projections otherwise.
840 */
841 public List<String> getServerProjections() {
842 if (serverProjections == null)
843 return Collections.emptyList();
844 return Collections.unmodifiableList(serverProjections);
845 }
846
847 public void setServerProjections(Collection<String> serverProjections) {
848 this.serverProjections = new ArrayList<>(serverProjections);
849 }
850
851 /**
852 * Returns the extended URL, containing in addition of service URL, its type and min/max zoom info.
853 * @return The extended URL
854 */
855 public String getExtendedUrl() {
856 return imageryType.getTypeString() + (defaultMaxZoom != 0
857 ? "["+(defaultMinZoom != 0 ? Integer.toString(defaultMinZoom) + ',' : "")+defaultMaxZoom+"]" : "") + ':' + url;
858 }
859
860 public String getToolbarName() {
861 String res = name;
862 if (pixelPerDegree != 0) {
863 res += "#PPD="+pixelPerDegree;
864 }
865 return res;
866 }
867
868 public String getMenuName() {
869 String res = name;
870 if (pixelPerDegree != 0) {
871 res += " ("+pixelPerDegree+')';
872 }
873 return res;
874 }
875
876 /**
877 * Determines if this entry requires attribution.
878 * @return {@code true} if some attribution text has to be displayed, {@code false} otherwise
879 */
880 public boolean hasAttribution() {
881 return attributionText != null;
882 }
883
884 /**
885 * Copies attribution from another {@code ImageryInfo}.
886 * @param i The other imagery info to get attribution from
887 */
888 public void copyAttribution(ImageryInfo i) {
889 this.attributionImage = i.attributionImage;
890 this.attributionImageURL = i.attributionImageURL;
891 this.attributionText = i.attributionText;
892 this.attributionLinkURL = i.attributionLinkURL;
893 this.termsOfUseText = i.termsOfUseText;
894 this.termsOfUseURL = i.termsOfUseURL;
895 }
896
897 /**
898 * Applies the attribution from this object to a tile source.
899 * @param s The tile source
900 */
901 public void setAttribution(AbstractTileSource s) {
902 if (attributionText != null) {
903 if ("osm".equals(attributionText)) {
904 s.setAttributionText(new Mapnik().getAttributionText(0, null, null));
905 } else {
906 s.setAttributionText(attributionText);
907 }
908 }
909 if (attributionLinkURL != null) {
910 if ("osm".equals(attributionLinkURL)) {
911 s.setAttributionLinkURL(new Mapnik().getAttributionLinkURL());
912 } else {
913 s.setAttributionLinkURL(attributionLinkURL);
914 }
915 }
916 if (attributionImage != null) {
917 ImageIcon i = ImageProvider.getIfAvailable(null, attributionImage);
918 if (i != null) {
919 s.setAttributionImage(i.getImage());
920 }
921 }
922 if (attributionImageURL != null) {
923 s.setAttributionImageURL(attributionImageURL);
924 }
925 if (termsOfUseText != null) {
926 s.setTermsOfUseText(termsOfUseText);
927 }
928 if (termsOfUseURL != null) {
929 if ("osm".equals(termsOfUseURL)) {
930 s.setTermsOfUseURL(new Mapnik().getTermsOfUseURL());
931 } else {
932 s.setTermsOfUseURL(termsOfUseURL);
933 }
934 }
935 }
936
937 /**
938 * Returns the imagery type.
939 * @return The imagery type
940 */
941 public ImageryType getImageryType() {
942 return imageryType;
943 }
944
945 /**
946 * Sets the imagery type.
947 * @param imageryType The imagery type
948 */
949 public void setImageryType(ImageryType imageryType) {
950 this.imageryType = imageryType;
951 }
952
953 /**
954 * Returns true if this layer's URL is matched by one of the regular
955 * expressions kept by the current OsmApi instance.
956 * @return {@code true} is this entry is blacklisted, {@code false} otherwise
957 */
958 public boolean isBlacklisted() {
959 Capabilities capabilities = OsmApi.getOsmApi().getCapabilities();
960 return capabilities != null && capabilities.isOnImageryBlacklist(this.url);
961 }
962
963 /**
964 * Sets the map of &lt;header name, header value&gt; that if any of this header
965 * will be returned, then this tile will be treated as "no tile at this zoom level"
966 *
967 * @param noTileHeaders Map of &lt;header name, header value&gt; which will be treated as "no tile at this zoom level"
968 * @since 8344
969 */
970 public void setNoTileHeaders(Map<String, String> noTileHeaders) {
971 this.noTileHeaders = noTileHeaders;
972 }
973
974 @Override
975 public Map<String, String> getNoTileHeaders() {
976 return noTileHeaders;
977 }
978
979 /**
980 * Returns the map of &lt;header name, metadata key&gt; indicating, which HTTP headers should
981 * be moved to metadata
982 *
983 * @param metadataHeaders map of &lt;header name, metadata key&gt; indicating, which HTTP headers should be moved to metadata
984 * @since 8418
985 */
986 public void setMetadataHeaders(Map<String, String> metadataHeaders) {
987 this.metadataHeaders = metadataHeaders;
988 }
989
990 public boolean isEpsg4326To3857Supported() {
991 return isEpsg4326To3857Supported;
992 }
993
994 public void setEpsg4326To3857Supported(boolean isEpsg4326To3857Supported) {
995 this.isEpsg4326To3857Supported = isEpsg4326To3857Supported;
996 }
997
998 public boolean isGeoreferenceValid() {
999 return isGeoreferenceValid;
1000 }
1001
1002 public void setGeoreferenceValid(boolean isGeoreferenceValid) {
1003 this.isGeoreferenceValid = isGeoreferenceValid;
1004 }
1005
1006}
Note: See TracBrowser for help on using the repository browser.