Ignore:
Timestamp:
2021-07-18T15:40:42+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #21131 - allow to edit direction/position of sequence of geo-images without GPX track

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r18035 r18065  
    22package org.openstreetmap.josm.gui.layer.geoimage;
    33
     4import static java.util.stream.Collectors.toList;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    2122import java.io.File;
    2223import java.util.ArrayList;
     24import java.util.Arrays;
    2325import java.util.Collection;
     26import java.util.Collections;
     27import java.util.Comparator;
    2428import java.util.LinkedList;
    2529import java.util.List;
     30import java.util.Objects;
    2631import java.util.concurrent.ExecutorService;
    2732import java.util.concurrent.Executors;
     
    3136
    3237import org.openstreetmap.josm.actions.AutoScaleAction;
     38import org.openstreetmap.josm.actions.ExpertToggleAction;
    3339import org.openstreetmap.josm.actions.RenameLayerAction;
    3440import org.openstreetmap.josm.actions.mapmode.MapMode;
     
    4046import org.openstreetmap.josm.data.ImageData.ImageDataUpdateListener;
    4147import org.openstreetmap.josm.data.gpx.GpxData;
    42 import org.openstreetmap.josm.data.gpx.WayPoint;
     48import org.openstreetmap.josm.data.gpx.GpxImageEntry;
     49import org.openstreetmap.josm.data.gpx.GpxTrack;
    4350import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4451import org.openstreetmap.josm.gui.MainApplication;
     
    7279    GpxLayer gpxLayer;
    7380    GpxLayer gpxFauxLayer;
     81    GpxData gpxFauxData;
    7482
    7583    private CorrelateGpxWithImages gpxCorrelateAction;
     
    247255        entries.add(SeparatorLayerAction.INSTANCE);
    248256        entries.add(getGpxCorrelateAction());
     257        if (ExpertToggleAction.isExpert()) {
     258            entries.add(new EditImagesSequenceAction(this));
     259        }
    249260        entries.add(new ShowThumbnailAction(this));
    250261        if (!menuAdditions.isEmpty()) {
     
    807818        if (gpxLayer != null) return getGpxLayer();
    808819        if (gpxFauxLayer == null) {
    809             GpxData gpxData = new GpxData();
    810             for (ImageEntry image : data.getImages()) {
    811                 gpxData.addWaypoint(new WayPoint(image.getPos()));
    812             }
    813             gpxFauxLayer = new GpxLayer(gpxData);
     820            gpxFauxLayer = new GpxLayer(getFauxGpxData());
    814821        }
    815822        return gpxFauxLayer;
     823    }
     824
     825    /**
     826     * Returns a faux GPX data built from the images or the associated GPX layer data.
     827     * @return A faux GPX data or the associated GPX layer data
     828     * @since 18065
     829     */
     830    public synchronized GpxData getFauxGpxData() {
     831        if (gpxLayer != null) return getGpxLayer().data;
     832        if (gpxFauxData == null) {
     833            gpxFauxData = new GpxData();
     834            gpxFauxData.addTrack(new GpxTrack(Arrays.asList(
     835                    data.getImages().stream().map(ImageEntry::asWayPoint).filter(Objects::nonNull).collect(toList())),
     836                    Collections.emptyMap()));
     837        }
     838        return gpxFauxData;
    816839    }
    817840
     
    870893        return data;
    871894    }
     895
     896    void applyTmp() {
     897        data.getImages().forEach(ImageEntry::applyTmp);
     898    }
     899
     900    void discardTmp() {
     901        data.getImages().forEach(ImageEntry::discardTmp);
     902    }
     903
     904    /**
     905     * Returns a list of images that fulfill the given criteria.
     906     * Default setting is to return untagged images, but may be overwritten.
     907     * @param exif also returns images with exif-gps info
     908     * @param tagged also returns tagged images
     909     * @return matching images
     910     */
     911    List<ImageEntry> getSortedImgList(boolean exif, boolean tagged) {
     912        return data.getImages().stream()
     913                .filter(GpxImageEntry::hasExifTime)
     914                .filter(e -> e.getExifCoor() == null || exif)
     915                .filter(e -> tagged || !e.isTagged() || e.getExifCoor() != null)
     916                .sorted(Comparator.comparing(ImageEntry::getExifInstant))
     917                .collect(toList());
     918    }
    872919}
Note: See TracChangeset for help on using the changeset viewer.