Changeset 13792 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-05-20T17:28:55+02:00 (6 years ago)
Author:
stoecker
Message:

fix #16103 - add map type definitions

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r13753 r13792  
    7373        private final String typeString;
    7474
    75         ImageryType(String urlString) {
    76             this.typeString = urlString;
     75        ImageryType(String typeString) {
     76            this.typeString = typeString;
    7777        }
    7878
     
    9595                if (type.getTypeString().equals(s)) {
    9696                    return type;
     97                }
     98            }
     99            return null;
     100        }
     101    }
     102
     103    /**
     104     * Category of imagery entry.
     105     * @since 13792
     106     */
     107    public enum ImageryCategory {
     108        /** A aerial or satellite photo. **/
     109        PHOTO("photo", tr("Aerial or satellite photo")),
     110        /** A map. **/
     111        MAP("map", tr("Map")),
     112        /** A historic or otherwise outdated map. */
     113        HISTORICMAP("historicmap", tr("Historic or otherwise outdated map")),
     114        /** A map based on OSM data. **/
     115        OSMBASEDMAP("osmbasedmap", tr("Map based on OSM data")),
     116        /** A historic or otherwise outdated aerial or satellite photo. **/
     117        HISTORICPHOTO("historicphoto", tr("Historic or otherwise outdated aerial or satellite photo")),
     118        /** Any other type of imagery **/
     119        OTHER("other", tr("Imagery not matching any other category"));
     120
     121        private final String category;
     122        private final String description;
     123
     124        ImageryCategory(String category, String description) {
     125            this.category = category;
     126            this.description = description;
     127        }
     128
     129        /**
     130         * Returns the unique string identifying this category.
     131         * @return the unique string identifying this category
     132         */
     133        public final String getCategoryString() {
     134            return category;
     135        }
     136
     137        /**
     138         * Returns the description of this category.
     139         * @return the description of this category
     140         */
     141        public final String getDescription() {
     142            return description;
     143        }
     144
     145        /**
     146         * Returns the imagery category from the given category string.
     147         * @param s The category string
     148         * @return the imagery category matching the given category string
     149         */
     150        public static ImageryCategory fromString(String s) {
     151            for (ImageryCategory category : ImageryCategory.values()) {
     152                if (category.getCategoryString().equals(s)) {
     153                    return category;
    97154                }
    98155            }
     
    230287    private boolean transparent = true;
    231288    private int minimumTileExpire = (int) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get());
     289    /** category of the imagery */
     290    private ImageryCategory category;
     291    /** category of the imagery (input string, not saved, copied or used otherwise except for error checks) */
     292    private String categoryOriginalString;
    232293    /** when adding a field, also adapt the:
    233294     * {@link #ImageryPreferenceEntry ImageryPreferenceEntry object}
     
    278339        @StructEntry boolean transparent;
    279340        @StructEntry int minimumTileExpire;
     341        @StructEntry String category;
    280342
    281343        /**
     
    313375            icon = i.icon;
    314376            description = i.description;
     377            category = i.category != null ? i.category.getCategoryString() : null;
    315378            if (i.bounds != null) {
    316379                bounds = i.bounds.encodeAsString(",");
     
    502565        transparent = e.transparent;
    503566        minimumTileExpire = e.minimumTileExpire;
     567        category = ImageryCategory.fromString(e.category);
    504568    }
    505569
     
    549613        this.transparent = i.transparent;
    550614        this.minimumTileExpire = i.minimumTileExpire;
     615        this.category = i.category;
    551616    }
    552617
     
    603668                Objects.equals(this.customHttpHeaders, other.customHttpHeaders) &&
    604669                Objects.equals(this.transparent, other.transparent) &&
    605                 Objects.equals(this.minimumTileExpire, other.minimumTileExpire);
     670                Objects.equals(this.minimumTileExpire, other.minimumTileExpire) &&
     671                Objects.equals(this.category, other.category);
    606672        // CHECKSTYLE.ON: BooleanExpressionComplexity
    607673    }
     
    9901056            html = true;
    9911057        }
     1058        if (category != null && category.getDescription() != null) {
     1059            res.append("<br>").append(tr("Imagery category: {0}", category.getDescription()));
     1060            html = true;
     1061        }
    9921062        if (bestMarked) {
    9931063            res.append("<br>").append(tr("This imagery is marked as best in this region in other editors."));
     
    12031273    public void setImageryType(ImageryType imageryType) {
    12041274        this.imageryType = imageryType;
     1275    }
     1276
     1277    /**
     1278     * Returns the imagery category.
     1279     * @return The imagery category
     1280     * @since 13792
     1281     */
     1282    public ImageryCategory getImageryCategory() {
     1283        return category;
     1284    }
     1285
     1286    /**
     1287     * Sets the imagery category.
     1288     * @param category The imagery category
     1289     * @since 13792
     1290     */
     1291    public void setImageryCategory(ImageryCategory category) {
     1292        this.category = category;
     1293    }
     1294
     1295    /**
     1296     * Returns the imagery category original string (don't use except for error checks).
     1297     * @return The imagery category original string
     1298     * @since 13792
     1299     */
     1300    public String getImageryCategoryOriginalString() {
     1301        return categoryOriginalString;
     1302    }
     1303
     1304    /**
     1305     * Sets the imagery category original string (don't use except for error checks).
     1306     * @param categoryOriginalString The imagery category original string
     1307     * @since 13792
     1308     */
     1309    public void setImageryCategoryOriginalString(String categoryOriginalString) {
     1310        this.categoryOriginalString = categoryOriginalString;
    12051311    }
    12061312
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r13757 r13792  
    1818import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1919import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
     20import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryCategory;
    2021import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    2122import org.openstreetmap.josm.data.imagery.Shape;
     
    220221                        "permission-ref",
    221222                        "country-code",
     223                        "category",
    222224                        "icon",
    223225                        "date",
     
    425427                    break;
    426428                case "type":
    427                     boolean found = false;
    428                     for (ImageryType type : ImageryType.values()) {
    429                         if (Objects.equals(accumulator.toString(), type.getTypeString())) {
    430                             entry.setImageryType(type);
    431                             found = true;
    432                             break;
    433                         }
    434                     }
    435                     if (!found) {
     429                    ImageryType type = ImageryType.fromString(accumulator.toString());
     430                    if(type != null)
     431                        entry.setImageryType(type);
     432                    else
    436433                        skipEntry = true;
    437                     }
    438434                    break;
    439435                case "default":
     
    524520                case "minimum-tile-expire":
    525521                    entry.setMinimumTileExpire(Integer.parseInt(accumulator.toString()));
     522                    break;
     523                case "category":
     524                    String cat = accumulator.toString();
     525                    ImageryCategory category = ImageryCategory.fromString(cat);
     526                    if(category != null)
     527                        entry.setImageryCategory(category);
     528                    entry.setImageryCategoryOriginalString(cat);
    526529                    break;
    527530                default: // Do nothing
Note: See TracChangeset for help on using the changeset viewer.