Ignore:
Timestamp:
2017-02-02T18:52:17+01:00 (7 years ago)
Author:
stoecker
Message:

drop imagery entries which have an id, but are no longer in default list

File:
1 edited

Legend:

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

    r11385 r11527  
    170170            updateEntriesFromDefaults();
    171171            buildIdMap(layers, layerIds);
     172            dropOldEntries();
    172173        }
    173174    }
     
    232233        Main.pref.putCollection("imagery.layers.default", newKnownDefaults);
    233234
    234         // Add ids to user entries without id.
    235         // Only do this the first time for each id, so the user can have
    236         // custom entries that don't get updated automatically
    237         Collection<String> addedIds = Main.pref.getCollection("imagery.layers.addedIds");
    238         Collection<String> newAddedIds = new TreeSet<>(addedIds);
    239         for (ImageryInfo info : layers) {
    240             for (ImageryInfo def : defaultLayers) {
    241                 if (isSimilar(def, info) && def.getId() != null && !addedIds.contains(def.getId())) {
    242                     if (!defaultLayerIds.containsKey(def.getId())) {
    243                         // ignore ids used more than once (have been purged from the map)
    244                         continue;
    245                     }
    246                     newAddedIds.add(def.getId());
    247                     if (info.getId() == null) {
    248                         info.setId(def.getId());
    249                         changed = true;
    250                     }
    251                 }
    252             }
    253         }
    254         Main.pref.putCollection("imagery.layers.addedIds", newAddedIds);
    255 
    256235        // automatically update user entries with same id as a default entry
    257236        for (int i = 0; i < layers.size(); i++) {
     
    263242            if (matchingDefault != null && !matchingDefault.equalsPref(info)) {
    264243                layers.set(i, matchingDefault);
     244                Main.info(tr("Update imagery ''{0}''", info.getName()));
    265245                changed = true;
    266246            }
     
    268248
    269249        if (changed) {
     250            save();
     251        }
     252    }
     253
     254    /**
     255     * Drop entries with Id which do no longer exist (removed from defaults).
     256     */
     257    public void dropOldEntries() {
     258        List<String> drop = new ArrayList<>();
     259
     260        for (Map.Entry<String, ImageryInfo> info : layerIds.entrySet()) {
     261            if (!defaultLayerIds.containsKey(info.getKey())) {
     262                remove(info.getValue());
     263                drop.add(info.getKey());
     264                Main.info(tr("Drop old imagery ''{0}''", info.getValue().getName()));
     265            }
     266        }
     267
     268        if (!drop.isEmpty()) {
     269            for (String id : drop) {
     270                layerIds.remove(id);
     271            }
    270272            save();
    271273        }
Note: See TracChangeset for help on using the changeset viewer.