Changeset 18007 in josm for trunk/src/org


Ignore:
Timestamp:
2021-07-12T16:25:33+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21044 - keep all tags when merging geojson nodes at the same location

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java

    r17333 r18007  
    1010import java.util.Map;
    1111import java.util.Set;
     12import java.util.function.BiConsumer;
    1213
    1314import javax.swing.table.DefaultTableModel;
     
    299300        return new HashSet<>(keysWithConflicts);
    300301    }
     302
     303    /**
     304     * Perform an action on all decisions, useful to perform a global decision (keep all, keep none, etc.)
     305     * @param action action to perform on decision
     306     * @since 18007
     307     */
     308    public final void actOnDecisions(BiConsumer<String, MultiValueResolutionDecision> action) {
     309        decisions.forEach(action::accept);
     310    }
    301311}
  • trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java

    r17646 r18007  
    1212import java.nio.charset.StandardCharsets;
    1313import java.util.ArrayList;
     14import java.util.Arrays;
    1415import java.util.List;
    1516import java.util.Map;
    1617import java.util.Objects;
    1718import java.util.Optional;
    18 import java.util.TreeMap;
    1919import java.util.stream.Collectors;
    2020
     
    3737import org.openstreetmap.josm.data.osm.Relation;
    3838import org.openstreetmap.josm.data.osm.RelationMember;
     39import org.openstreetmap.josm.data.osm.Tag;
     40import org.openstreetmap.josm.data.osm.TagCollection;
     41import org.openstreetmap.josm.data.osm.TagMap;
    3942import org.openstreetmap.josm.data.osm.UploadPolicy;
    4043import org.openstreetmap.josm.data.osm.Way;
     
    4346import org.openstreetmap.josm.data.validation.TestError;
    4447import org.openstreetmap.josm.data.validation.tests.DuplicateWay;
     48import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil;
     49import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolverModel;
    4550import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    4651import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    329334
    330335    /**
    331      * Replace all existing tags in primitive by the values given in the GeoJSON feature.
     336     * Merge existing tags in primitive (if any) with the values given in the GeoJSON feature.
    332337     * @param feature the GeoJSON feature
    333338     * @param primitive the OSM primitive
     
    335340    private static void fillTagsFromFeature(final JsonObject feature, final OsmPrimitive primitive) {
    336341        if (feature != null) {
    337             primitive.setKeys(getTags(feature));
    338         }
     342            TagCollection featureTags = getTags(feature);
     343            primitive.setKeys(new TagMap(primitive.isTagged() ? mergeAllTagValues(primitive, featureTags) : featureTags));
     344        }
     345    }
     346
     347    private static TagCollection mergeAllTagValues(final OsmPrimitive primitive, TagCollection featureTags) {
     348        TagCollection tags = TagCollection.from(primitive).union(featureTags);
     349        TagConflictResolutionUtil.applyAutomaticTagConflictResolution(tags);
     350        TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(tags, Arrays.asList(primitive));
     351        TagConflictResolverModel tagModel = new TagConflictResolverModel();
     352        tagModel.populate(new TagCollection(tags), tags.getKeysWithMultipleValues());
     353        tagModel.actOnDecisions((k, d) -> d.keepAll());
     354        return tagModel.getAllResolutions();
    339355    }
    340356
     
    347363    }
    348364
    349     private static Map<String, String> getTags(final JsonObject feature) {
    350         final Map<String, String> tags = new TreeMap<>();
     365    private static TagCollection getTags(final JsonObject feature) {
     366        final TagCollection tags = new TagCollection();
    351367
    352368        if (feature.containsKey(PROPERTIES) && !feature.isNull(PROPERTIES)) {
     
    357373
    358374                    if (value instanceof JsonString) {
    359                         tags.put(stringJsonValueEntry.getKey(), ((JsonString) value).getString());
     375                        tags.add(new Tag(stringJsonValueEntry.getKey(), ((JsonString) value).getString()));
    360376                    } else if (value instanceof JsonObject) {
    361377                        Logging.warn(
     
    365381                        );
    366382                    } else if (value.getValueType() != JsonValue.ValueType.NULL) {
    367                         tags.put(stringJsonValueEntry.getKey(), value.toString());
     383                        tags.add(new Tag(stringJsonValueEntry.getKey(), value.toString()));
    368384                    }
    369385                }
Note: See TracChangeset for help on using the changeset viewer.