001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.imagery; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.Image; 007import java.io.StringReader; 008import java.util.ArrayList; 009import java.util.Arrays; 010import java.util.Collection; 011import java.util.Collections; 012import java.util.EnumMap; 013import java.util.HashMap; 014import java.util.List; 015import java.util.Locale; 016import java.util.Map; 017import java.util.Objects; 018import java.util.Optional; 019import java.util.Set; 020import java.util.TreeSet; 021import java.util.concurrent.ConcurrentHashMap; 022import java.util.concurrent.TimeUnit; 023import java.util.regex.Matcher; 024import java.util.regex.Pattern; 025import java.util.stream.Collectors; 026 027import javax.json.Json; 028import javax.json.JsonObject; 029import javax.json.JsonReader; 030import javax.json.stream.JsonCollectors; 031import javax.swing.ImageIcon; 032 033import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; 034import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 035import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource; 036import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik; 037import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; 038import org.openstreetmap.josm.data.Bounds; 039import org.openstreetmap.josm.data.StructUtils; 040import org.openstreetmap.josm.data.StructUtils.StructEntry; 041import org.openstreetmap.josm.io.Capabilities; 042import org.openstreetmap.josm.io.OsmApi; 043import org.openstreetmap.josm.spi.preferences.Config; 044import org.openstreetmap.josm.spi.preferences.IPreferences; 045import org.openstreetmap.josm.tools.CheckParameterUtil; 046import org.openstreetmap.josm.tools.ImageProvider; 047import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 048import org.openstreetmap.josm.tools.LanguageInfo; 049import org.openstreetmap.josm.tools.Logging; 050import org.openstreetmap.josm.tools.MultiMap; 051import org.openstreetmap.josm.tools.Utils; 052 053/** 054 * Class that stores info about an image background layer. 055 * 056 * @author Frederik Ramm 057 */ 058public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInfo>, Attributed { 059 060 /** 061 * Type of imagery entry. 062 */ 063 public enum ImageryType { 064 /** A WMS (Web Map Service) entry. **/ 065 WMS("wms"), 066 /** A TMS (Tile Map Service) entry. **/ 067 TMS("tms"), 068 /** TMS entry for Microsoft Bing. */ 069 BING("bing"), 070 /** TMS entry for Russian company <a href="https://wiki.openstreetmap.org/wiki/WikiProject_Russia/kosmosnimki">ScanEx</a>. **/ 071 SCANEX("scanex"), 072 /** A WMS endpoint entry only stores the WMS server info, without layer, which are chosen later by the user. **/ 073 WMS_ENDPOINT("wms_endpoint"), 074 /** WMTS stores GetCapabilities URL. Does not store any information about the layer **/ 075 WMTS("wmts"); 076 077 private final String typeString; 078 079 ImageryType(String typeString) { 080 this.typeString = typeString; 081 } 082 083 /** 084 * Returns the unique string identifying this type. 085 * @return the unique string identifying this type 086 * @since 6690 087 */ 088 public final String getTypeString() { 089 return typeString; 090 } 091 092 /** 093 * Returns the imagery type from the given type string. 094 * @param s The type string 095 * @return the imagery type matching the given type string 096 */ 097 public static ImageryType fromString(String s) { 098 for (ImageryType type : ImageryType.values()) { 099 if (type.getTypeString().equals(s)) { 100 return type; 101 } 102 } 103 return null; 104 } 105 } 106 107 /** 108 * Category of imagery entry. 109 * @since 13792 110 */ 111 public enum ImageryCategory { 112 /** A aerial or satellite photo. **/ 113 PHOTO(/* ICON(data/imagery/) */ "photo", tr("Aerial or satellite photo")), 114 /** A map. **/ 115 MAP(/* ICON(data/imagery/) */ "map", tr("Map")), 116 /** A historic or otherwise outdated map. */ 117 HISTORICMAP(/* ICON(data/imagery/) */ "historicmap", tr("Historic or otherwise outdated map")), 118 /** A map based on OSM data. **/ 119 OSMBASEDMAP(/* ICON(data/imagery/) */ "osmbasedmap", tr("Map based on OSM data")), 120 /** A historic or otherwise outdated aerial or satellite photo. **/ 121 HISTORICPHOTO(/* ICON(data/imagery/) */ "historicphoto", tr("Historic or otherwise outdated aerial or satellite photo")), 122 /** Any other type of imagery **/ 123 OTHER(/* ICON(data/imagery/) */ "other", tr("Imagery not matching any other category")); 124 125 private final String category; 126 private final String description; 127 private static final Map<ImageSizes, Map<ImageryCategory, ImageIcon>> iconCache = 128 Collections.synchronizedMap(new EnumMap<>(ImageSizes.class)); 129 130 ImageryCategory(String category, String description) { 131 this.category = category; 132 this.description = description; 133 } 134 135 /** 136 * Returns the unique string identifying this category. 137 * @return the unique string identifying this category 138 */ 139 public final String getCategoryString() { 140 return category; 141 } 142 143 /** 144 * Returns the description of this category. 145 * @return the description of this category 146 */ 147 public final String getDescription() { 148 return description; 149 } 150 151 /** 152 * Returns the category icon at the given size. 153 * @param size icon wanted size 154 * @return the category icon at the given size 155 * @since 15049 156 */ 157 public final ImageIcon getIcon(ImageSizes size) { 158 return iconCache 159 .computeIfAbsent(size, x -> Collections.synchronizedMap(new EnumMap<>(ImageryCategory.class))) 160 .computeIfAbsent(this, x -> ImageProvider.get("data/imagery", x.category, size)); 161 } 162 163 /** 164 * Returns the imagery category from the given category string. 165 * @param s The category string 166 * @return the imagery category matching the given category string 167 */ 168 public static ImageryCategory fromString(String s) { 169 for (ImageryCategory category : ImageryCategory.values()) { 170 if (category.getCategoryString().equals(s)) { 171 return category; 172 } 173 } 174 return null; 175 } 176 } 177 178 /** 179 * Multi-polygon bounds for imagery backgrounds. 180 * Used to display imagery coverage in preferences and to determine relevant imagery entries based on edit location. 181 */ 182 public static class ImageryBounds extends Bounds { 183 184 /** 185 * Constructs a new {@code ImageryBounds} from string. 186 * @param asString The string containing the list of shapes defining this bounds 187 * @param separator The shape separator in the given string, usually a comma 188 */ 189 public ImageryBounds(String asString, String separator) { 190 super(asString, separator); 191 } 192 193 private List<Shape> shapes = new ArrayList<>(); 194 195 /** 196 * Adds a new shape to this bounds. 197 * @param shape The shape to add 198 */ 199 public final void addShape(Shape shape) { 200 this.shapes.add(shape); 201 } 202 203 /** 204 * Sets the list of shapes defining this bounds. 205 * @param shapes The list of shapes defining this bounds. 206 */ 207 public final void setShapes(List<Shape> shapes) { 208 this.shapes = shapes; 209 } 210 211 /** 212 * Returns the list of shapes defining this bounds. 213 * @return The list of shapes defining this bounds 214 */ 215 public final List<Shape> getShapes() { 216 return shapes; 217 } 218 219 @Override 220 public int hashCode() { 221 return Objects.hash(super.hashCode(), shapes); 222 } 223 224 @Override 225 public boolean equals(Object o) { 226 if (this == o) return true; 227 if (o == null || getClass() != o.getClass()) return false; 228 if (!super.equals(o)) return false; 229 ImageryBounds that = (ImageryBounds) o; 230 return Objects.equals(shapes, that.shapes); 231 } 232 } 233 234 /** original name of the imagery entry in case of translation call, for multiple languages English when possible */ 235 private String origName; 236 /** (original) language of the translated name entry */ 237 private String langName; 238 /** whether this is a entry activated by default or not */ 239 private boolean defaultEntry; 240 /** Whether this service requires a explicit EULA acceptance before it can be activated */ 241 private String eulaAcceptanceRequired; 242 /** type of the imagery servics - WMS, TMS, ... */ 243 private ImageryType imageryType = ImageryType.WMS; 244 private double pixelPerDegree; 245 /** maximum zoom level for TMS imagery */ 246 private int defaultMaxZoom; 247 /** minimum zoom level for TMS imagery */ 248 private int defaultMinZoom; 249 /** display bounds of imagery, displayed in prefs and used for automatic imagery selection */ 250 private ImageryBounds bounds; 251 /** projections supported by WMS servers */ 252 private List<String> serverProjections = Collections.emptyList(); 253 /** description of the imagery entry, should contain notes what type of data it is */ 254 private String description; 255 /** language of the description entry */ 256 private String langDescription; 257 /** Text of a text attribution displayed when using the imagery */ 258 private String attributionText; 259 /** Link to a reference stating the permission for OSM usage */ 260 private String permissionReferenceURL; 261 /** Link behind the text attribution displayed when using the imagery */ 262 private String attributionLinkURL; 263 /** Image of a graphical attribution displayed when using the imagery */ 264 private String attributionImage; 265 /** Link behind the graphical attribution displayed when using the imagery */ 266 private String attributionImageURL; 267 /** Text with usage terms displayed when using the imagery */ 268 private String termsOfUseText; 269 /** Link behind the text with usage terms displayed when using the imagery */ 270 private String termsOfUseURL; 271 /** country code of the imagery (for country specific imagery) */ 272 private String countryCode = ""; 273 /** 274 * creation date of the imagery (in the form YYYY-MM-DD;YYYY-MM-DD, where 275 * DD and MM as well as a second date are optional) 276 * @since 11570 277 */ 278 private String date; 279 /** 280 * marked as best in other editors 281 * @since 11575 282 */ 283 private boolean bestMarked; 284 /** 285 * marked as overlay 286 * @since 13536 287 */ 288 private boolean overlay; 289 /** 290 * list of old IDs, only for loading, not handled anywhere else 291 * @since 13536 292 */ 293 private Collection<String> oldIds; 294 /** mirrors of different type for this entry */ 295 private List<ImageryInfo> mirrors; 296 /** icon used in menu */ 297 private String icon; 298 /** is the geo reference correct - don't offer offset handling */ 299 private boolean isGeoreferenceValid; 300 /** which layers should be activated by default on layer addition. **/ 301 private List<DefaultLayer> defaultLayers = new ArrayList<>(); 302 /** HTTP headers **/ 303 private Map<String, String> customHttpHeaders = new ConcurrentHashMap<>(); 304 /** Should this map be transparent **/ 305 private boolean transparent = true; 306 private int minimumTileExpire = (int) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get()); 307 /** category of the imagery */ 308 private ImageryCategory category; 309 /** category of the imagery (input string, not saved, copied or used otherwise except for error checks) */ 310 private String categoryOriginalString; 311 /** when adding a field, also adapt the: 312 * {@link #ImageryPreferenceEntry ImageryPreferenceEntry object} 313 * {@link #ImageryPreferenceEntry#ImageryPreferenceEntry(ImageryInfo) ImageryPreferenceEntry constructor} 314 * {@link #ImageryInfo(ImageryPreferenceEntry) ImageryInfo constructor} 315 * {@link #ImageryInfo(ImageryInfo) ImageryInfo constructor} 316 * {@link #equalsPref(ImageryPreferenceEntry) equalsPref method} 317 **/ 318 319 /** 320 * Auxiliary class to save an {@link ImageryInfo} object in the preferences. 321 */ 322 public static class ImageryPreferenceEntry { 323 @StructEntry String name; 324 @StructEntry String d; 325 @StructEntry String id; 326 @StructEntry String type; 327 @StructEntry String url; 328 @StructEntry double pixel_per_eastnorth; 329 @StructEntry String eula; 330 @StructEntry String attribution_text; 331 @StructEntry String attribution_url; 332 @StructEntry String permission_reference_url; 333 @StructEntry String logo_image; 334 @StructEntry String logo_url; 335 @StructEntry String terms_of_use_text; 336 @StructEntry String terms_of_use_url; 337 @StructEntry String country_code = ""; 338 @StructEntry String date; 339 @StructEntry int max_zoom; 340 @StructEntry int min_zoom; 341 @StructEntry String cookies; 342 @StructEntry String bounds; 343 @StructEntry String shapes; 344 @StructEntry String projections; 345 @StructEntry String icon; 346 @StructEntry String description; 347 @StructEntry MultiMap<String, String> noTileHeaders; 348 @StructEntry MultiMap<String, String> noTileChecksums; 349 @StructEntry int tileSize = -1; 350 @StructEntry Map<String, String> metadataHeaders; 351 @StructEntry boolean valid_georeference; 352 @StructEntry boolean bestMarked; 353 @StructEntry boolean modTileFeatures; 354 @StructEntry boolean overlay; 355 @StructEntry String default_layers; 356 @StructEntry Map<String, String> customHttpHeaders; 357 @StructEntry boolean transparent; 358 @StructEntry int minimumTileExpire; 359 @StructEntry String category; 360 361 /** 362 * Constructs a new empty WMS {@code ImageryPreferenceEntry}. 363 */ 364 public ImageryPreferenceEntry() { 365 // Do nothing 366 } 367 368 /** 369 * Constructs a new {@code ImageryPreferenceEntry} from a given {@code ImageryInfo}. 370 * @param i The corresponding imagery info 371 */ 372 public ImageryPreferenceEntry(ImageryInfo i) { 373 name = i.name; 374 id = i.id; 375 type = i.imageryType.getTypeString(); 376 url = i.url; 377 pixel_per_eastnorth = i.pixelPerDegree; 378 eula = i.eulaAcceptanceRequired; 379 attribution_text = i.attributionText; 380 attribution_url = i.attributionLinkURL; 381 permission_reference_url = i.permissionReferenceURL; 382 date = i.date; 383 bestMarked = i.bestMarked; 384 overlay = i.overlay; 385 logo_image = i.attributionImage; 386 logo_url = i.attributionImageURL; 387 terms_of_use_text = i.termsOfUseText; 388 terms_of_use_url = i.termsOfUseURL; 389 country_code = i.countryCode; 390 max_zoom = i.defaultMaxZoom; 391 min_zoom = i.defaultMinZoom; 392 cookies = i.cookies; 393 icon = i.icon; 394 description = i.description; 395 category = i.category != null ? i.category.getCategoryString() : null; 396 if (i.bounds != null) { 397 bounds = i.bounds.encodeAsString(","); 398 StringBuilder shapesString = new StringBuilder(); 399 for (Shape s : i.bounds.getShapes()) { 400 if (shapesString.length() > 0) { 401 shapesString.append(';'); 402 } 403 shapesString.append(s.encodeAsString(",")); 404 } 405 if (shapesString.length() > 0) { 406 shapes = shapesString.toString(); 407 } 408 } 409 if (!i.serverProjections.isEmpty()) { 410 projections = i.serverProjections.stream().collect(Collectors.joining(",")); 411 } 412 if (i.noTileHeaders != null && !i.noTileHeaders.isEmpty()) { 413 noTileHeaders = new MultiMap<>(i.noTileHeaders); 414 } 415 416 if (i.noTileChecksums != null && !i.noTileChecksums.isEmpty()) { 417 noTileChecksums = new MultiMap<>(i.noTileChecksums); 418 } 419 420 if (i.metadataHeaders != null && !i.metadataHeaders.isEmpty()) { 421 metadataHeaders = i.metadataHeaders; 422 } 423 424 tileSize = i.getTileSize(); 425 426 valid_georeference = i.isGeoreferenceValid(); 427 modTileFeatures = i.isModTileFeatures(); 428 if (!i.defaultLayers.isEmpty()) { 429 default_layers = i.defaultLayers.stream().map(DefaultLayer::toJson).collect(JsonCollectors.toJsonArray()).toString(); 430 } 431 customHttpHeaders = i.customHttpHeaders; 432 transparent = i.isTransparent(); 433 minimumTileExpire = i.minimumTileExpire; 434 } 435 436 @Override 437 public String toString() { 438 StringBuilder s = new StringBuilder("ImageryPreferenceEntry [name=").append(name); 439 if (id != null) { 440 s.append(" id=").append(id); 441 } 442 s.append(']'); 443 return s.toString(); 444 } 445 } 446 447 /** 448 * Constructs a new WMS {@code ImageryInfo}. 449 */ 450 public ImageryInfo() { 451 super(); 452 } 453 454 /** 455 * Constructs a new WMS {@code ImageryInfo} with a given name. 456 * @param name The entry name 457 */ 458 public ImageryInfo(String name) { 459 super(name); 460 } 461 462 /** 463 * Constructs a new WMS {@code ImageryInfo} with given name and extended URL. 464 * @param name The entry name 465 * @param url The entry extended URL 466 */ 467 public ImageryInfo(String name, String url) { 468 this(name); 469 setExtendedUrl(url); 470 } 471 472 /** 473 * Constructs a new WMS {@code ImageryInfo} with given name, extended and EULA URLs. 474 * @param name The entry name 475 * @param url The entry URL 476 * @param eulaAcceptanceRequired The EULA URL 477 */ 478 public ImageryInfo(String name, String url, String eulaAcceptanceRequired) { 479 this(name); 480 setExtendedUrl(url); 481 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 482 } 483 484 /** 485 * Constructs a new {@code ImageryInfo} with given name, url, extended and EULA URLs. 486 * @param name The entry name 487 * @param url The entry URL 488 * @param type The entry imagery type. If null, WMS will be used as default 489 * @param eulaAcceptanceRequired The EULA URL 490 * @param cookies The data part of HTTP cookies header in case the service requires cookies to work 491 * @throws IllegalArgumentException if type refers to an unknown imagery type 492 */ 493 public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies) { 494 this(name); 495 setExtendedUrl(url); 496 ImageryType t = ImageryType.fromString(type); 497 this.cookies = cookies; 498 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 499 if (t != null) { 500 this.imageryType = t; 501 } else if (type != null && !type.isEmpty()) { 502 throw new IllegalArgumentException("unknown type: "+type); 503 } 504 } 505 506 /** 507 * Constructs a new {@code ImageryInfo} with given name, url, id, extended and EULA URLs. 508 * @param name The entry name 509 * @param url The entry URL 510 * @param type The entry imagery type. If null, WMS will be used as default 511 * @param eulaAcceptanceRequired The EULA URL 512 * @param cookies The data part of HTTP cookies header in case the service requires cookies to work 513 * @param id tile id 514 * @throws IllegalArgumentException if type refers to an unknown imagery type 515 */ 516 public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies, String id) { 517 this(name, url, type, eulaAcceptanceRequired, cookies); 518 setId(id); 519 } 520 521 /** 522 * Constructs a new {@code ImageryInfo} from an imagery preference entry. 523 * @param e The imagery preference entry 524 */ 525 public ImageryInfo(ImageryPreferenceEntry e) { 526 super(e.name, e.url, e.id); 527 CheckParameterUtil.ensureParameterNotNull(e.name, "name"); 528 CheckParameterUtil.ensureParameterNotNull(e.url, "url"); 529 description = e.description; 530 cookies = e.cookies; 531 eulaAcceptanceRequired = e.eula; 532 imageryType = ImageryType.fromString(e.type); 533 if (imageryType == null) throw new IllegalArgumentException("unknown type"); 534 pixelPerDegree = e.pixel_per_eastnorth; 535 defaultMaxZoom = e.max_zoom; 536 defaultMinZoom = e.min_zoom; 537 if (e.bounds != null) { 538 bounds = new ImageryBounds(e.bounds, ","); 539 if (e.shapes != null) { 540 try { 541 for (String s : e.shapes.split(";")) { 542 bounds.addShape(new Shape(s, ",")); 543 } 544 } catch (IllegalArgumentException ex) { 545 Logging.warn(ex); 546 } 547 } 548 } 549 if (e.projections != null && !e.projections.isEmpty()) { 550 // split generates null element on empty string which gives one element Array[null] 551 serverProjections = Arrays.asList(e.projections.split(",")); 552 } 553 attributionText = e.attribution_text; 554 attributionLinkURL = e.attribution_url; 555 permissionReferenceURL = e.permission_reference_url; 556 attributionImage = e.logo_image; 557 attributionImageURL = e.logo_url; 558 date = e.date; 559 bestMarked = e.bestMarked; 560 overlay = e.overlay; 561 termsOfUseText = e.terms_of_use_text; 562 termsOfUseURL = e.terms_of_use_url; 563 countryCode = e.country_code; 564 icon = e.icon; 565 if (e.noTileHeaders != null) { 566 noTileHeaders = e.noTileHeaders.toMap(); 567 } 568 if (e.noTileChecksums != null) { 569 noTileChecksums = e.noTileChecksums.toMap(); 570 } 571 setTileSize(e.tileSize); 572 metadataHeaders = e.metadataHeaders; 573 isGeoreferenceValid = e.valid_georeference; 574 modTileFeatures = e.modTileFeatures; 575 if (e.default_layers != null) { 576 try (JsonReader jsonReader = Json.createReader(new StringReader(e.default_layers))) { 577 defaultLayers = jsonReader. 578 readArray(). 579 stream(). 580 map(x -> DefaultLayer.fromJson((JsonObject) x, imageryType)). 581 collect(Collectors.toList()); 582 } 583 } 584 customHttpHeaders = e.customHttpHeaders; 585 transparent = e.transparent; 586 minimumTileExpire = e.minimumTileExpire; 587 category = ImageryCategory.fromString(e.category); 588 } 589 590 /** 591 * Constructs a new {@code ImageryInfo} from an existing one. 592 * @param i The other imagery info 593 */ 594 public ImageryInfo(ImageryInfo i) { 595 super(i.name, i.url, i.id); 596 this.noTileHeaders = i.noTileHeaders; 597 this.noTileChecksums = i.noTileChecksums; 598 this.minZoom = i.minZoom; 599 this.maxZoom = i.maxZoom; 600 this.cookies = i.cookies; 601 this.tileSize = i.tileSize; 602 this.metadataHeaders = i.metadataHeaders; 603 this.modTileFeatures = i.modTileFeatures; 604 605 this.origName = i.origName; 606 this.langName = i.langName; 607 this.defaultEntry = i.defaultEntry; 608 this.eulaAcceptanceRequired = null; 609 this.imageryType = i.imageryType; 610 this.pixelPerDegree = i.pixelPerDegree; 611 this.defaultMaxZoom = i.defaultMaxZoom; 612 this.defaultMinZoom = i.defaultMinZoom; 613 this.bounds = i.bounds; 614 this.serverProjections = i.serverProjections; 615 this.description = i.description; 616 this.langDescription = i.langDescription; 617 this.attributionText = i.attributionText; 618 this.permissionReferenceURL = i.permissionReferenceURL; 619 this.attributionLinkURL = i.attributionLinkURL; 620 this.attributionImage = i.attributionImage; 621 this.attributionImageURL = i.attributionImageURL; 622 this.termsOfUseText = i.termsOfUseText; 623 this.termsOfUseURL = i.termsOfUseURL; 624 this.countryCode = i.countryCode; 625 this.date = i.date; 626 this.bestMarked = i.bestMarked; 627 this.overlay = i.overlay; 628 // do not copy field {@code mirrors} 629 this.icon = i.icon; 630 this.isGeoreferenceValid = i.isGeoreferenceValid; 631 this.defaultLayers = i.defaultLayers; 632 this.customHttpHeaders = i.customHttpHeaders; 633 this.transparent = i.transparent; 634 this.minimumTileExpire = i.minimumTileExpire; 635 this.category = i.category; 636 } 637 638 @Override 639 public int hashCode() { 640 return Objects.hash(url, imageryType); 641 } 642 643 /** 644 * Check if this object equals another ImageryInfo with respect to the properties 645 * that get written to the preference file. 646 * 647 * The field {@link #pixelPerDegree} is ignored. 648 * 649 * @param other the ImageryInfo object to compare to 650 * @return true if they are equal 651 */ 652 public boolean equalsPref(ImageryInfo other) { 653 if (other == null) { 654 return false; 655 } 656 657 // CHECKSTYLE.OFF: BooleanExpressionComplexity 658 return 659 Objects.equals(this.name, other.name) && 660 Objects.equals(this.id, other.id) && 661 Objects.equals(this.url, other.url) && 662 Objects.equals(this.modTileFeatures, other.modTileFeatures) && 663 Objects.equals(this.bestMarked, other.bestMarked) && 664 Objects.equals(this.overlay, other.overlay) && 665 Objects.equals(this.isGeoreferenceValid, other.isGeoreferenceValid) && 666 Objects.equals(this.cookies, other.cookies) && 667 Objects.equals(this.eulaAcceptanceRequired, other.eulaAcceptanceRequired) && 668 Objects.equals(this.imageryType, other.imageryType) && 669 Objects.equals(this.defaultMaxZoom, other.defaultMaxZoom) && 670 Objects.equals(this.defaultMinZoom, other.defaultMinZoom) && 671 Objects.equals(this.bounds, other.bounds) && 672 Objects.equals(this.serverProjections, other.serverProjections) && 673 Objects.equals(this.attributionText, other.attributionText) && 674 Objects.equals(this.attributionLinkURL, other.attributionLinkURL) && 675 Objects.equals(this.permissionReferenceURL, other.permissionReferenceURL) && 676 Objects.equals(this.attributionImageURL, other.attributionImageURL) && 677 Objects.equals(this.attributionImage, other.attributionImage) && 678 Objects.equals(this.termsOfUseText, other.termsOfUseText) && 679 Objects.equals(this.termsOfUseURL, other.termsOfUseURL) && 680 Objects.equals(this.countryCode, other.countryCode) && 681 Objects.equals(this.date, other.date) && 682 Objects.equals(this.icon, other.icon) && 683 Objects.equals(this.description, other.description) && 684 Objects.equals(this.noTileHeaders, other.noTileHeaders) && 685 Objects.equals(this.noTileChecksums, other.noTileChecksums) && 686 Objects.equals(this.metadataHeaders, other.metadataHeaders) && 687 Objects.equals(this.defaultLayers, other.defaultLayers) && 688 Objects.equals(this.customHttpHeaders, other.customHttpHeaders) && 689 Objects.equals(this.transparent, other.transparent) && 690 Objects.equals(this.minimumTileExpire, other.minimumTileExpire) && 691 Objects.equals(this.category, other.category); 692 // CHECKSTYLE.ON: BooleanExpressionComplexity 693 } 694 695 @Override 696 public boolean equals(Object o) { 697 if (this == o) return true; 698 if (o == null || getClass() != o.getClass()) return false; 699 ImageryInfo that = (ImageryInfo) o; 700 return imageryType == that.imageryType && Objects.equals(url, that.url); 701 } 702 703 private static final Map<String, String> localizedCountriesCache = new HashMap<>(); 704 static { 705 localizedCountriesCache.put("", tr("Worldwide")); 706 } 707 708 /** 709 * Returns a localized name for the given country code, or "Worldwide" if empty. 710 * This function falls back on the English name, and uses the ISO code as a last-resortvalue. 711 * 712 * @param countryCode An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code 713 * @return The name of the country appropriate to the current locale. 714 * @see Locale#getDisplayCountry 715 * @since 15158 716 */ 717 public static String getLocalizedCountry(String countryCode) { 718 return localizedCountriesCache.computeIfAbsent(countryCode, code -> new Locale("en", code).getDisplayCountry()); 719 } 720 721 @Override 722 public String toString() { 723 // Used in imagery preferences filtering, so must be efficient 724 return new StringBuilder(name) 725 .append('[').append(countryCode) 726 // appending the localized country in toString() allows us to filter imagery preferences table with it! 727 .append("] ('").append(getLocalizedCountry(countryCode)).append(')') 728 .append(" - ").append(url) 729 .append(" - ").append(imageryType) 730 .toString(); 731 } 732 733 @Override 734 public int compareTo(ImageryInfo in) { 735 int i = countryCode.compareTo(in.countryCode); 736 if (i == 0) { 737 i = name.toLowerCase(Locale.ENGLISH).compareTo(in.name.toLowerCase(Locale.ENGLISH)); 738 } 739 if (i == 0) { 740 i = url.compareTo(in.url); 741 } 742 if (i == 0) { 743 i = Double.compare(pixelPerDegree, in.pixelPerDegree); 744 } 745 return i; 746 } 747 748 /** 749 * Determines if URL is equal to given imagery info. 750 * @param in imagery info 751 * @return {@code true} if URL is equal to given imagery info 752 */ 753 public boolean equalsBaseValues(ImageryInfo in) { 754 return url.equals(in.url); 755 } 756 757 /** 758 * Sets the pixel per degree value. 759 * @param ppd The ppd value 760 * @see #getPixelPerDegree() 761 */ 762 public void setPixelPerDegree(double ppd) { 763 this.pixelPerDegree = ppd; 764 } 765 766 /** 767 * Sets the maximum zoom level. 768 * @param defaultMaxZoom The maximum zoom level 769 */ 770 public void setDefaultMaxZoom(int defaultMaxZoom) { 771 this.defaultMaxZoom = defaultMaxZoom; 772 } 773 774 /** 775 * Sets the minimum zoom level. 776 * @param defaultMinZoom The minimum zoom level 777 */ 778 public void setDefaultMinZoom(int defaultMinZoom) { 779 this.defaultMinZoom = defaultMinZoom; 780 } 781 782 /** 783 * Sets the imagery polygonial bounds. 784 * @param b The imagery bounds (non-rectangular) 785 */ 786 public void setBounds(ImageryBounds b) { 787 this.bounds = b; 788 } 789 790 /** 791 * Returns the imagery polygonial bounds. 792 * @return The imagery bounds (non-rectangular) 793 */ 794 public ImageryBounds getBounds() { 795 return bounds; 796 } 797 798 @Override 799 public boolean requiresAttribution() { 800 return attributionText != null || attributionLinkURL != null || attributionImage != null 801 || termsOfUseText != null || termsOfUseURL != null; 802 } 803 804 @Override 805 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) { 806 return attributionText; 807 } 808 809 @Override 810 public String getAttributionLinkURL() { 811 return attributionLinkURL; 812 } 813 814 /** 815 * Return the permission reference URL. 816 * @return The url 817 * @see #setPermissionReferenceURL 818 * @since 11975 819 */ 820 public String getPermissionReferenceURL() { 821 return permissionReferenceURL; 822 } 823 824 @Override 825 public Image getAttributionImage() { 826 ImageIcon i = ImageProvider.getIfAvailable(attributionImage); 827 if (i != null) { 828 return i.getImage(); 829 } 830 return null; 831 } 832 833 /** 834 * Return the raw attribution logo information (an URL to the image). 835 * @return The url text 836 * @since 12257 837 */ 838 public String getAttributionImageRaw() { 839 return attributionImage; 840 } 841 842 @Override 843 public String getAttributionImageURL() { 844 return attributionImageURL; 845 } 846 847 @Override 848 public String getTermsOfUseText() { 849 return termsOfUseText; 850 } 851 852 @Override 853 public String getTermsOfUseURL() { 854 return termsOfUseURL; 855 } 856 857 /** 858 * Set the attribution text 859 * @param text The text 860 * @see #getAttributionText(int, ICoordinate, ICoordinate) 861 */ 862 public void setAttributionText(String text) { 863 attributionText = text; 864 } 865 866 /** 867 * Set the attribution image 868 * @param url The url of the image. 869 * @see #getAttributionImageURL() 870 */ 871 public void setAttributionImageURL(String url) { 872 attributionImageURL = url; 873 } 874 875 /** 876 * Set the image for the attribution 877 * @param res The image resource 878 * @see #getAttributionImage() 879 */ 880 public void setAttributionImage(String res) { 881 attributionImage = res; 882 } 883 884 /** 885 * Sets the URL the attribution should link to. 886 * @param url The url. 887 * @see #getAttributionLinkURL() 888 */ 889 public void setAttributionLinkURL(String url) { 890 attributionLinkURL = url; 891 } 892 893 /** 894 * Sets the permission reference URL. 895 * @param url The url. 896 * @see #getPermissionReferenceURL() 897 * @since 11975 898 */ 899 public void setPermissionReferenceURL(String url) { 900 permissionReferenceURL = url; 901 } 902 903 /** 904 * Sets the text to display to the user as terms of use. 905 * @param text The text 906 * @see #getTermsOfUseText() 907 */ 908 public void setTermsOfUseText(String text) { 909 termsOfUseText = text; 910 } 911 912 /** 913 * Sets a url that links to the terms of use text. 914 * @param text The url. 915 * @see #getTermsOfUseURL() 916 */ 917 public void setTermsOfUseURL(String text) { 918 termsOfUseURL = text; 919 } 920 921 /** 922 * Sets the extended URL of this entry. 923 * @param url Entry extended URL containing in addition of service URL, its type and min/max zoom info 924 */ 925 public void setExtendedUrl(String url) { 926 CheckParameterUtil.ensureParameterNotNull(url); 927 928 // Default imagery type is WMS 929 this.url = url; 930 this.imageryType = ImageryType.WMS; 931 932 defaultMaxZoom = 0; 933 defaultMinZoom = 0; 934 for (ImageryType type : ImageryType.values()) { 935 Matcher m = Pattern.compile(type.getTypeString()+"(?:\\[(?:(\\d+)[,-])?(\\d+)\\])?:(.*)").matcher(url); 936 if (m.matches()) { 937 this.url = m.group(3); 938 this.imageryType = type; 939 if (m.group(2) != null) { 940 defaultMaxZoom = Integer.parseInt(m.group(2)); 941 } 942 if (m.group(1) != null) { 943 defaultMinZoom = Integer.parseInt(m.group(1)); 944 } 945 break; 946 } 947 } 948 949 if (serverProjections.isEmpty()) { 950 serverProjections = new ArrayList<>(); 951 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase(Locale.ENGLISH)); 952 if (m.matches()) { 953 for (String p : m.group(1).split(",")) { 954 serverProjections.add(p); 955 } 956 } 957 } 958 } 959 960 /** 961 * Returns the entry name. 962 * @return The entry name 963 * @since 6968 964 */ 965 public String getOriginalName() { 966 return this.origName != null ? this.origName : this.name; 967 } 968 969 /** 970 * Sets the entry name and handle translation. 971 * @param language The used language 972 * @param name The entry name 973 * @since 8091 974 */ 975 public void setName(String language, String name) { 976 boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language); 977 if (LanguageInfo.isBetterLanguage(langName, language)) { 978 this.name = isdefault ? tr(name) : name; 979 this.langName = language; 980 } 981 if (origName == null || isdefault) { 982 this.origName = name; 983 } 984 } 985 986 /** 987 * Store the id of this info to the preferences and clear it afterwards. 988 */ 989 public void clearId() { 990 if (this.id != null) { 991 Collection<String> newAddedIds = new TreeSet<>(Config.getPref().getList("imagery.layers.addedIds")); 992 newAddedIds.add(this.id); 993 Config.getPref().putList("imagery.layers.addedIds", new ArrayList<>(newAddedIds)); 994 } 995 setId(null); 996 } 997 998 /** 999 * Determines if this entry is enabled by default. 1000 * @return {@code true} if this entry is enabled by default, {@code false} otherwise 1001 */ 1002 public boolean isDefaultEntry() { 1003 return defaultEntry; 1004 } 1005 1006 /** 1007 * Sets the default state of this entry. 1008 * @param defaultEntry {@code true} if this entry has to be enabled by default, {@code false} otherwise 1009 */ 1010 public void setDefaultEntry(boolean defaultEntry) { 1011 this.defaultEntry = defaultEntry; 1012 } 1013 1014 /** 1015 * Gets the pixel per degree value 1016 * @return The ppd value. 1017 */ 1018 public double getPixelPerDegree() { 1019 return this.pixelPerDegree; 1020 } 1021 1022 /** 1023 * Returns the maximum zoom level. 1024 * @return The maximum zoom level 1025 */ 1026 @Override 1027 public int getMaxZoom() { 1028 return this.defaultMaxZoom; 1029 } 1030 1031 /** 1032 * Returns the minimum zoom level. 1033 * @return The minimum zoom level 1034 */ 1035 @Override 1036 public int getMinZoom() { 1037 return this.defaultMinZoom; 1038 } 1039 1040 /** 1041 * Returns the description text when existing. 1042 * @return The description 1043 * @since 8065 1044 */ 1045 public String getDescription() { 1046 return this.description; 1047 } 1048 1049 /** 1050 * Sets the description text when existing. 1051 * @param language The used language 1052 * @param description the imagery description text 1053 * @since 8091 1054 */ 1055 public void setDescription(String language, String description) { 1056 boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language); 1057 if (LanguageInfo.isBetterLanguage(langDescription, language)) { 1058 this.description = isdefault ? tr(description) : description; 1059 this.langDescription = language; 1060 } 1061 } 1062 1063 /** 1064 * Return the sorted list of activated Imagery IDs. 1065 * @return sorted list of activated Imagery IDs 1066 * @since 13536 1067 */ 1068 public static Collection<String> getActiveIds() { 1069 ArrayList<String> ids = new ArrayList<>(); 1070 IPreferences pref = Config.getPref(); 1071 if (pref != null) { 1072 List<ImageryPreferenceEntry> entries = StructUtils.getListOfStructs( 1073 pref, "imagery.entries", null, ImageryPreferenceEntry.class); 1074 if (entries != null) { 1075 for (ImageryPreferenceEntry prefEntry : entries) { 1076 if (prefEntry.id != null && !prefEntry.id.isEmpty()) 1077 ids.add(prefEntry.id); 1078 } 1079 Collections.sort(ids); 1080 } 1081 } 1082 return ids; 1083 } 1084 1085 /** 1086 * Returns a tool tip text for display. 1087 * @return The text 1088 * @since 8065 1089 */ 1090 public String getToolTipText() { 1091 StringBuilder res = new StringBuilder(getName()); 1092 boolean html = false; 1093 String dateStr = getDate(); 1094 if (dateStr != null && !dateStr.isEmpty()) { 1095 res.append("<br>").append(tr("Date of imagery: {0}", dateStr)); 1096 html = true; 1097 } 1098 if (category != null && category.getDescription() != null) { 1099 res.append("<br>").append(tr("Imagery category: {0}", category.getDescription())); 1100 html = true; 1101 } 1102 if (bestMarked) { 1103 res.append("<br>").append(tr("This imagery is marked as best in this region in other editors.")); 1104 html = true; 1105 } 1106 if (overlay) { 1107 res.append("<br>").append(tr("This imagery is an overlay.")); 1108 html = true; 1109 } 1110 String desc = getDescription(); 1111 if (desc != null && !desc.isEmpty()) { 1112 res.append("<br>").append(Utils.escapeReservedCharactersHTML(desc)); 1113 html = true; 1114 } 1115 if (html) { 1116 res.insert(0, "<html>").append("</html>"); 1117 } 1118 return res.toString(); 1119 } 1120 1121 /** 1122 * Returns the EULA acceptance URL, if any. 1123 * @return The URL to an EULA text that has to be accepted before use, or {@code null} 1124 */ 1125 public String getEulaAcceptanceRequired() { 1126 return eulaAcceptanceRequired; 1127 } 1128 1129 /** 1130 * Sets the EULA acceptance URL. 1131 * @param eulaAcceptanceRequired The URL to an EULA text that has to be accepted before use 1132 */ 1133 public void setEulaAcceptanceRequired(String eulaAcceptanceRequired) { 1134 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 1135 } 1136 1137 /** 1138 * Returns the ISO 3166-1-alpha-2 country code. 1139 * @return The country code (2 letters) 1140 */ 1141 public String getCountryCode() { 1142 return countryCode; 1143 } 1144 1145 /** 1146 * Sets the ISO 3166-1-alpha-2 country code. 1147 * @param countryCode The country code (2 letters) 1148 */ 1149 public void setCountryCode(String countryCode) { 1150 this.countryCode = countryCode; 1151 } 1152 1153 /** 1154 * Returns the date information. 1155 * @return The date (in the form YYYY-MM-DD;YYYY-MM-DD, where 1156 * DD and MM as well as a second date are optional) 1157 * @since 11570 1158 */ 1159 public String getDate() { 1160 return date; 1161 } 1162 1163 /** 1164 * Sets the date information. 1165 * @param date The date information 1166 * @since 11570 1167 */ 1168 public void setDate(String date) { 1169 this.date = date; 1170 } 1171 1172 /** 1173 * Returns the entry icon. 1174 * @return The entry icon 1175 */ 1176 public String getIcon() { 1177 return icon; 1178 } 1179 1180 /** 1181 * Sets the entry icon. 1182 * @param icon The entry icon 1183 */ 1184 public void setIcon(String icon) { 1185 this.icon = icon; 1186 } 1187 1188 /** 1189 * Get the projections supported by the server. Only relevant for 1190 * WMS-type ImageryInfo at the moment. 1191 * @return null, if no projections have been specified; the list 1192 * of supported projections otherwise. 1193 */ 1194 public List<String> getServerProjections() { 1195 return Collections.unmodifiableList(serverProjections); 1196 } 1197 1198 /** 1199 * Sets the list of collections the server supports 1200 * @param serverProjections The list of supported projections 1201 */ 1202 public void setServerProjections(Collection<String> serverProjections) { 1203 CheckParameterUtil.ensureParameterNotNull(serverProjections, "serverProjections"); 1204 this.serverProjections = new ArrayList<>(serverProjections); 1205 } 1206 1207 /** 1208 * Returns the extended URL, containing in addition of service URL, its type and min/max zoom info. 1209 * @return The extended URL 1210 */ 1211 public String getExtendedUrl() { 1212 return imageryType.getTypeString() + (defaultMaxZoom != 0 1213 ? ('['+(defaultMinZoom != 0 ? (Integer.toString(defaultMinZoom) + ',') : "")+defaultMaxZoom+']') : "") + ':' + url; 1214 } 1215 1216 /** 1217 * Gets a unique toolbar key to store this layer as toolbar item 1218 * @return The kay. 1219 */ 1220 public String getToolbarName() { 1221 String res = name; 1222 if (pixelPerDegree != 0) { 1223 res += "#PPD="+pixelPerDegree; 1224 } 1225 return res; 1226 } 1227 1228 /** 1229 * Gets the name that should be displayed in the menu to add this imagery layer. 1230 * @return The text. 1231 */ 1232 public String getMenuName() { 1233 String res = name; 1234 if (pixelPerDegree != 0) { 1235 res += " ("+pixelPerDegree+')'; 1236 } 1237 return res; 1238 } 1239 1240 /** 1241 * Determines if this entry requires attribution. 1242 * @return {@code true} if some attribution text has to be displayed, {@code false} otherwise 1243 */ 1244 public boolean hasAttribution() { 1245 return attributionText != null; 1246 } 1247 1248 /** 1249 * Copies attribution from another {@code ImageryInfo}. 1250 * @param i The other imagery info to get attribution from 1251 */ 1252 public void copyAttribution(ImageryInfo i) { 1253 this.attributionImage = i.attributionImage; 1254 this.attributionImageURL = i.attributionImageURL; 1255 this.attributionText = i.attributionText; 1256 this.attributionLinkURL = i.attributionLinkURL; 1257 this.termsOfUseText = i.termsOfUseText; 1258 this.termsOfUseURL = i.termsOfUseURL; 1259 } 1260 1261 /** 1262 * Applies the attribution from this object to a tile source. 1263 * @param s The tile source 1264 */ 1265 public void setAttribution(AbstractTileSource s) { 1266 if (attributionText != null) { 1267 if ("osm".equals(attributionText)) { 1268 s.setAttributionText(new Mapnik().getAttributionText(0, null, null)); 1269 } else { 1270 s.setAttributionText(attributionText); 1271 } 1272 } 1273 if (attributionLinkURL != null) { 1274 if ("osm".equals(attributionLinkURL)) { 1275 s.setAttributionLinkURL(new Mapnik().getAttributionLinkURL()); 1276 } else { 1277 s.setAttributionLinkURL(attributionLinkURL); 1278 } 1279 } 1280 if (attributionImage != null) { 1281 ImageIcon i = ImageProvider.getIfAvailable(null, attributionImage); 1282 if (i != null) { 1283 s.setAttributionImage(i.getImage()); 1284 } 1285 } 1286 if (attributionImageURL != null) { 1287 s.setAttributionImageURL(attributionImageURL); 1288 } 1289 if (termsOfUseText != null) { 1290 s.setTermsOfUseText(termsOfUseText); 1291 } 1292 if (termsOfUseURL != null) { 1293 if ("osm".equals(termsOfUseURL)) { 1294 s.setTermsOfUseURL(new Mapnik().getTermsOfUseURL()); 1295 } else { 1296 s.setTermsOfUseURL(termsOfUseURL); 1297 } 1298 } 1299 } 1300 1301 /** 1302 * Returns the imagery type. 1303 * @return The imagery type 1304 */ 1305 public ImageryType getImageryType() { 1306 return imageryType; 1307 } 1308 1309 /** 1310 * Sets the imagery type. 1311 * @param imageryType The imagery type 1312 */ 1313 public void setImageryType(ImageryType imageryType) { 1314 this.imageryType = imageryType; 1315 } 1316 1317 /** 1318 * Returns the imagery category. 1319 * @return The imagery category 1320 * @since 13792 1321 */ 1322 public ImageryCategory getImageryCategory() { 1323 return category; 1324 } 1325 1326 /** 1327 * Sets the imagery category. 1328 * @param category The imagery category 1329 * @since 13792 1330 */ 1331 public void setImageryCategory(ImageryCategory category) { 1332 this.category = category; 1333 } 1334 1335 /** 1336 * Returns the imagery category original string (don't use except for error checks). 1337 * @return The imagery category original string 1338 * @since 13792 1339 */ 1340 public String getImageryCategoryOriginalString() { 1341 return categoryOriginalString; 1342 } 1343 1344 /** 1345 * Sets the imagery category original string (don't use except for error checks). 1346 * @param categoryOriginalString The imagery category original string 1347 * @since 13792 1348 */ 1349 public void setImageryCategoryOriginalString(String categoryOriginalString) { 1350 this.categoryOriginalString = categoryOriginalString; 1351 } 1352 1353 /** 1354 * Returns true if this layer's URL is matched by one of the regular 1355 * expressions kept by the current OsmApi instance. 1356 * @return {@code true} is this entry is blacklisted, {@code false} otherwise 1357 */ 1358 public boolean isBlacklisted() { 1359 Capabilities capabilities = OsmApi.getOsmApi().getCapabilities(); 1360 return capabilities != null && capabilities.isOnImageryBlacklist(this.url); 1361 } 1362 1363 /** 1364 * Sets the map of <header name, header value> that if any of this header 1365 * will be returned, then this tile will be treated as "no tile at this zoom level" 1366 * 1367 * @param noTileHeaders Map of <header name, header value> which will be treated as "no tile at this zoom level" 1368 * @since 9613 1369 */ 1370 public void setNoTileHeaders(MultiMap<String, String> noTileHeaders) { 1371 if (noTileHeaders == null || noTileHeaders.isEmpty()) { 1372 this.noTileHeaders = null; 1373 } else { 1374 this.noTileHeaders = noTileHeaders.toMap(); 1375 } 1376 } 1377 1378 @Override 1379 public Map<String, Set<String>> getNoTileHeaders() { 1380 return noTileHeaders; 1381 } 1382 1383 /** 1384 * Sets the map of <checksum type, checksum value> that if any tile with that checksum 1385 * will be returned, then this tile will be treated as "no tile at this zoom level" 1386 * 1387 * @param noTileChecksums Map of <checksum type, checksum value> which will be treated as "no tile at this zoom level" 1388 * @since 9613 1389 */ 1390 public void setNoTileChecksums(MultiMap<String, String> noTileChecksums) { 1391 if (noTileChecksums == null || noTileChecksums.isEmpty()) { 1392 this.noTileChecksums = null; 1393 } else { 1394 this.noTileChecksums = noTileChecksums.toMap(); 1395 } 1396 } 1397 1398 @Override 1399 public Map<String, Set<String>> getNoTileChecksums() { 1400 return noTileChecksums; 1401 } 1402 1403 /** 1404 * Returns the map of <header name, metadata key> indicating, which HTTP headers should 1405 * be moved to metadata 1406 * 1407 * @param metadataHeaders map of <header name, metadata key> indicating, which HTTP headers should be moved to metadata 1408 * @since 8418 1409 */ 1410 public void setMetadataHeaders(Map<String, String> metadataHeaders) { 1411 if (metadataHeaders == null || metadataHeaders.isEmpty()) { 1412 this.metadataHeaders = null; 1413 } else { 1414 this.metadataHeaders = metadataHeaders; 1415 } 1416 } 1417 1418 /** 1419 * Gets the flag if the georeference is valid. 1420 * @return <code>true</code> if it is valid. 1421 */ 1422 public boolean isGeoreferenceValid() { 1423 return isGeoreferenceValid; 1424 } 1425 1426 /** 1427 * Sets an indicator that the georeference is valid 1428 * @param isGeoreferenceValid <code>true</code> if it is marked as valid. 1429 */ 1430 public void setGeoreferenceValid(boolean isGeoreferenceValid) { 1431 this.isGeoreferenceValid = isGeoreferenceValid; 1432 } 1433 1434 /** 1435 * Returns the status of "best" marked status in other editors. 1436 * @return <code>true</code> if it is marked as best. 1437 * @since 11575 1438 */ 1439 public boolean isBestMarked() { 1440 return bestMarked; 1441 } 1442 1443 /** 1444 * Returns the overlay indication. 1445 * @return <code>true</code> if it is an overlay. 1446 * @since 13536 1447 */ 1448 public boolean isOverlay() { 1449 return overlay; 1450 } 1451 1452 /** 1453 * Sets an indicator that in other editors it is marked as best imagery 1454 * @param bestMarked <code>true</code> if it is marked as best in other editors. 1455 * @since 11575 1456 */ 1457 public void setBestMarked(boolean bestMarked) { 1458 this.bestMarked = bestMarked; 1459 } 1460 1461 /** 1462 * Sets overlay indication 1463 * @param overlay <code>true</code> if it is an overlay. 1464 * @since 13536 1465 */ 1466 public void setOverlay(boolean overlay) { 1467 this.overlay = overlay; 1468 } 1469 1470 /** 1471 * Adds an old Id. 1472 * 1473 * @param id the Id to be added 1474 * @since 13536 1475 */ 1476 public void addOldId(String id) { 1477 if (oldIds == null) { 1478 oldIds = new ArrayList<>(); 1479 } 1480 oldIds.add(id); 1481 } 1482 1483 /** 1484 * Get old Ids. 1485 * 1486 * @return collection of ids 1487 * @since 13536 1488 */ 1489 public Collection<String> getOldIds() { 1490 return oldIds; 1491 } 1492 1493 /** 1494 * Adds a mirror entry. Mirror entries are completed with the data from the master entry 1495 * and only describe another method to access identical data. 1496 * 1497 * @param entry the mirror to be added 1498 * @since 9658 1499 */ 1500 public void addMirror(ImageryInfo entry) { 1501 if (mirrors == null) { 1502 mirrors = new ArrayList<>(); 1503 } 1504 mirrors.add(entry); 1505 } 1506 1507 /** 1508 * Returns the mirror entries. Entries are completed with master entry data. 1509 * 1510 * @return the list of mirrors 1511 * @since 9658 1512 */ 1513 public List<ImageryInfo> getMirrors() { 1514 List<ImageryInfo> l = new ArrayList<>(); 1515 if (mirrors != null) { 1516 int num = 1; 1517 for (ImageryInfo i : mirrors) { 1518 ImageryInfo n = new ImageryInfo(this); 1519 if (i.defaultMaxZoom != 0) { 1520 n.defaultMaxZoom = i.defaultMaxZoom; 1521 } 1522 if (i.defaultMinZoom != 0) { 1523 n.defaultMinZoom = i.defaultMinZoom; 1524 } 1525 n.setServerProjections(i.getServerProjections()); 1526 n.url = i.url; 1527 n.imageryType = i.imageryType; 1528 if (i.getTileSize() != 0) { 1529 n.setTileSize(i.getTileSize()); 1530 } 1531 if (n.id != null) { 1532 n.id = n.id + "_mirror"+num; 1533 } 1534 if (num > 1) { 1535 n.name = tr("{0} mirror server {1}", n.name, num); 1536 if (n.origName != null) { 1537 n.origName += " mirror server " + num; 1538 } 1539 } else { 1540 n.name = tr("{0} mirror server", n.name); 1541 if (n.origName != null) { 1542 n.origName += " mirror server"; 1543 } 1544 } 1545 l.add(n); 1546 ++num; 1547 } 1548 } 1549 return l; 1550 } 1551 1552 /** 1553 * Returns default layers that should be shown for this Imagery (if at all supported by imagery provider) 1554 * If no layer is set to default and there is more than one imagery available, then user will be asked to choose the layer 1555 * to work on 1556 * @return Collection of the layer names 1557 */ 1558 public List<DefaultLayer> getDefaultLayers() { 1559 return defaultLayers; 1560 } 1561 1562 /** 1563 * Sets the default layers that user will work with 1564 * @param layers set the list of default layers 1565 */ 1566 public void setDefaultLayers(List<DefaultLayer> layers) { 1567 this.defaultLayers = layers; 1568 } 1569 1570 /** 1571 * Returns custom HTTP headers that should be sent with request towards imagery provider 1572 * @return headers 1573 */ 1574 public Map<String, String> getCustomHttpHeaders() { 1575 if (customHttpHeaders == null) { 1576 return Collections.emptyMap(); 1577 } 1578 return customHttpHeaders; 1579 } 1580 1581 /** 1582 * Sets custom HTTP headers that should be sent with request towards imagery provider 1583 * @param customHttpHeaders http headers 1584 */ 1585 public void setCustomHttpHeaders(Map<String, String> customHttpHeaders) { 1586 this.customHttpHeaders = customHttpHeaders; 1587 } 1588 1589 /** 1590 * Determines if this imagery should be transparent. 1591 * @return should this imagery be transparent 1592 */ 1593 public boolean isTransparent() { 1594 return transparent; 1595 } 1596 1597 /** 1598 * Sets whether imagery should be transparent. 1599 * @param transparent set to true if imagery should be transparent 1600 */ 1601 public void setTransparent(boolean transparent) { 1602 this.transparent = transparent; 1603 } 1604 1605 /** 1606 * Returns minimum tile expiration in seconds. 1607 * @return minimum tile expiration in seconds 1608 */ 1609 public int getMinimumTileExpire() { 1610 return minimumTileExpire; 1611 } 1612 1613 /** 1614 * Sets minimum tile expiration in seconds. 1615 * @param minimumTileExpire minimum tile expiration in seconds 1616 */ 1617 public void setMinimumTileExpire(int minimumTileExpire) { 1618 this.minimumTileExpire = minimumTileExpire; 1619 } 1620 1621 /** 1622 * Get a string representation of this imagery info suitable for the {@code source} changeset tag. 1623 * @return English name, if known 1624 * @since 13890 1625 */ 1626 public String getSourceName() { 1627 if (ImageryType.BING == getImageryType()) { 1628 return "Bing"; 1629 } else { 1630 if (id != null) { 1631 // Retrieve english name, unfortunately not saved in preferences 1632 Optional<ImageryInfo> infoEn = ImageryLayerInfo.allDefaultLayers.stream().filter(x -> id.equals(x.getId())).findAny(); 1633 if (infoEn.isPresent()) { 1634 return infoEn.get().getOriginalName(); 1635 } 1636 } 1637 return getOriginalName(); 1638 } 1639 } 1640}