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


Ignore:
Timestamp:
2016-01-27T22:27:54+01:00 (8 years ago)
Author:
stoecker
Message:

see #12313 - support mirror URLs in editor compare and JOSM imagery loader

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

Legend:

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

    r9619 r9658  
    145145        }
    146146    }
    147 
    148147
    149148    /** original name of the imagery entry in case of translation call, for multiple languages English when possible */
     
    186185    /** country code of the imagery (for country specific imagery) */
    187186    private String countryCode = "";
     187    /** mirrors of different type for this entry */
     188    private List<ImageryInfo> mirrors = null;
    188189    /** icon used in menu */
    189190    private String icon;
     
    10291030    }
    10301031
     1032    /**
     1033     * Adds a mirror entry. Mirror entries are completed with the data from the master entry
     1034     * and only describe another method to access identical data.
     1035     *
     1036     * @param entry the mirror to be added
     1037     * @since 9658
     1038     */
     1039    public void addMirror(ImageryInfo entry) {
     1040       if (mirrors == null) {
     1041           mirrors = new ArrayList<>();
     1042       }
     1043       mirrors.add(entry);
     1044    }
     1045
     1046    /**
     1047     * Returns the mirror entries. Entries are completed with master entry data.
     1048     *
     1049     * @return the list of mirrors
     1050     * @since 9658
     1051     */
     1052    public List<ImageryInfo> getMirrors() {
     1053       List<ImageryInfo> l = new ArrayList<>();
     1054       if (mirrors != null) {
     1055           for (ImageryInfo i : mirrors) {
     1056               ImageryInfo n = new ImageryInfo(this);
     1057               if (i.defaultMaxZoom != 0) {
     1058                   n.defaultMaxZoom = i.defaultMaxZoom;
     1059               }
     1060               if (i.defaultMinZoom != 0) {
     1061                   n.defaultMinZoom = i.defaultMinZoom;
     1062               }
     1063               if (i.serverProjections != null) {
     1064                   n.serverProjections = i.serverProjections;
     1065               }
     1066               n.url = i.url;
     1067               n.imageryType = i.imageryType;
     1068               if (i.getTileSize() != 0) {
     1069                   n.setTileSize(i.getTileSize());
     1070               }
     1071               l.add(n);
     1072           }
     1073       }
     1074       return l;
     1075    }
    10311076}
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r9619 r9658  
    4040        ENTRY,              // inside an entry
    4141        ENTRY_ATTRIBUTE,    // note we are inside an entry attribute to collect the character data
    42         PROJECTIONS,
     42        PROJECTIONS,        // inside projections block of an entry
     43        MIRROR,             // inside an mirror entry
     44        MIRROR_ATTRIBUTE,   // note we are inside an mirror attribute to collect the character data
     45        MIRROR_PROJECTIONS, // inside projections block of an mirror entry
    4346        CODE,
    4447        BOUNDS,
     
    8992
    9093        private ImageryInfo entry;
     94        /** In case of mirror parsing this contains the mirror entry */
     95        private ImageryInfo mirrorEntry;
    9196        private ImageryBounds bounds;
    9297        private Shape shape;
     
    130135                    noTileChecksums = new HashMap<>();
    131136                    metadataHeaders = new HashMap<>();
     137                }
     138                break;
     139            case MIRROR:
     140                if (Arrays.asList(new String[] {
     141                        "type",
     142                        "url",
     143                        "min-zoom",
     144                        "max-zoom",
     145                        "tile-size",
     146                }).contains(qName)) {
     147                    newState = State.MIRROR_ATTRIBUTE;
     148                    lang = atts.getValue("lang");
     149                } else if ("projections".equals(qName)) {
     150                    projections = new ArrayList<>();
     151                    newState = State.MIRROR_PROJECTIONS;
    132152                }
    133153                break;
     
    171191                    projections = new ArrayList<>();
    172192                    newState = State.PROJECTIONS;
     193                } else if ("mirror".equals(qName)) {
     194                    projections = new ArrayList<>();
     195                    newState = State.MIRROR;
     196                    mirrorEntry = new ImageryInfo();
    173197                } else if ("no-tile-header".equals(qName)) {
    174198                    String name = atts.getValue("name");
     
    214238                break;
    215239            case PROJECTIONS:
     240            case MIRROR_PROJECTIONS:
    216241                if ("code".equals(qName)) {
    217242                    newState = State.CODE;
     
    259284                }
    260285                break;
     286            case MIRROR:
     287                if ("mirror".equals(qName)) {
     288                    if (mirrorEntry != null) {
     289                        entry.addMirror(mirrorEntry);
     290                        mirrorEntry = null;
     291                    }
     292                }
     293                break;
     294            case MIRROR_ATTRIBUTE:
     295                if (mirrorEntry != null) {
     296                    switch(qName) {
     297                    case "type":
     298                        boolean found = false;
     299                        for (ImageryType type : ImageryType.values()) {
     300                            if (Objects.equals(accumulator.toString(), type.getTypeString())) {
     301                                mirrorEntry.setImageryType(type);
     302                                found = true;
     303                                break;
     304                            }
     305                        }
     306                        if (!found) {
     307                            mirrorEntry = null;
     308                        }
     309                        break;
     310                    case "url":
     311                        mirrorEntry.setUrl(accumulator.toString());
     312                        break;
     313                    case "min-zoom":
     314                    case "max-zoom":
     315                        Integer val = null;
     316                        try {
     317                            val = Integer.valueOf(accumulator.toString());
     318                        } catch (NumberFormatException e) {
     319                            val = null;
     320                        }
     321                        if (val == null) {
     322                            mirrorEntry = null;
     323                        } else {
     324                            if ("min-zoom".equals(qName)) {
     325                                mirrorEntry.setDefaultMinZoom(val);
     326                            } else {
     327                                mirrorEntry.setDefaultMaxZoom(val);
     328                            }
     329                        }
     330                        break;
     331                    case "tile-size":
     332                        Integer tileSize = null;
     333                        try {
     334                            tileSize = Integer.valueOf(accumulator.toString());
     335                        } catch (NumberFormatException e) {
     336                            tileSize = null;
     337                        }
     338                        if (tileSize == null) {
     339                            mirrorEntry = null;
     340                        } else {
     341                            entry.setTileSize(tileSize.intValue());
     342                        }
     343                        break;
     344                    }
     345                }
     346                break;
    261347            case ENTRY_ATTRIBUTE:
    262348                switch(qName) {
     
    379465                projections = null;
    380466                break;
     467            case MIRROR_PROJECTIONS:
     468                mirrorEntry.setServerProjections(projections);
     469                projections = null;
     470                break;
     471            /* nothing to do for these or the unknown type:
    381472            case NO_TILE:
    382                 break;
    383 
     473            case NO_TILESUM:
     474            case METADATA:
     475            case UNKNOWN:
     476                break;
     477            */
    384478            }
    385479        }
Note: See TracChangeset for help on using the changeset viewer.