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

Last change on this file since 8067 was 8067, checked in by stoecker, 9 years ago

version off by one

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