Changeset 13792 in josm


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

fix #16103 - add map type definitions

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/maps.xsd

    r13757 r13792  
    679679                            <!-- A link that is opened, when the user clicks on the terms-of-use text -->
    680680                            <xs:element name="terms-of-use-url" minOccurs="0" maxOccurs="1" type="xs:string" />
     681                            <!-- The image category, don't use enumeration, so future extension is possible -->
     682                            <!-- Currently defined values are: "photo", "map", "historicmap", "osmbasedmap", "historicphoto" and "other" -->
     683                            <xs:element name="category" minOccurs="0" maxOccurs="1" type="xs:string" />
    681684                            <!-- The ISO 3166 country code -->
    682685                            <xs:element name="country-code" minOccurs="0" maxOccurs="1" type="tns:iso3166" />
  • trunk/scripts/SyncEditorLayerIndex.groovy

    r13780 r13792  
    3535class SyncEditorLayerIndex {
    3636
    37     List<ImageryInfo> josmEntries;
    38     JsonArray eliEntries;
     37    List<ImageryInfo> josmEntries
     38    JsonArray eliEntries
    3939
    4040    def eliUrls = new HashMap<String, JsonObject>()
     
    5757     */
    5858    static main(def args) {
    59         Locale.setDefault(Locale.ROOT);
     59        Locale.setDefault(Locale.ROOT)
    6060        parse_command_line_arguments(args)
    6161        Main.determinePlatformHook()
     
    7272            def stream = new OutputStreamWriter(file, "UTF-8")
    7373            script.printentries(script.josmEntries, stream)
    74             stream.close();
    75             file.close();
     74            stream.close()
     75            file.close()
    7676        }
    7777        script.loadELIEntries()
     
    8080            def stream = new OutputStreamWriter(file, "UTF-8")
    8181            script.printentries(script.eliEntries, stream)
    82             stream.close();
    83             file.close();
     82            stream.close()
     83            file.close()
    8484        }
    8585        script.checkInOneButNotTheOther()
     
    8787        script.end()
    8888        if(outputStream != null) {
    89             outputStream.close();
     89            outputStream.close()
    9090        }
    9191        if(outputFile != null) {
    92             outputFile.close();
     92            outputFile.close()
    9393        }
    9494    }
     
    425425                            eliUrls.remove(e)
    426426                            eliUrls.put(urlj,e)
    427                             break;
     427                            break
    428428                        }
    429429                    }
     
    901901                }
    902902            }
     903            def cat = getCategory(j)
     904            if(cat != null && cat != "photo" && cat != "map" && cat != "historicmap" && cat != "osmbasedmap" && cat != "historicphoto" && cat != "other") {
     905                myprintln "* Strange category ${cat}: ${getDescription(j)}"
     906            }
    903907        }
    904908    }
     
    10111015        if (e instanceof ImageryInfo) {
    10121016            if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
    1013                 return null;
     1017                return null
    10141018            int mz = e.getMinZoom()
    10151019            return mz == 0 ? null : mz
     
    10231027        if (e instanceof ImageryInfo) {
    10241028            if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
    1025                 return null;
     1029                return null
    10261030            int mz = e.getMaxZoom()
    10271031            return mz == 0 ? null : mz
     
    10641068    static String getTermsOfUseUrl(Object e) {
    10651069        if (e instanceof ImageryInfo) return e.getTermsOfUseURL()
     1070        return null
     1071    }
     1072    static String getCategory(Object e) {
     1073        if (e instanceof ImageryInfo) {
     1074            return e.getImageryCategoryOriginalString()
     1075        }
    10661076        return null
    10671077    }
  • 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.