Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: c86477a7 by Tony Chemit at 2023-11-22T15:37:45+01:00 add validCount and notValidCount in ObserveMapPaneLegendItem (to be able to compute real label at runtime via the getLabel method) - See #2805 - - - - - d72c14b2 by Tony Chemit at 2023-11-22T17:45:06+01:00 Pouvoir sélectionner/déselectionner les lignes et les points dans la carte - Closes #2806 - - - - - 8 changed files: - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/TripUIHelper.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/ObserveMapPane.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/ObserveMapPaneLegendItem.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/TripMapContentBuilderSupport.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/TripMapUIHandler.java - client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/common/TripMapContentBuilder.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/common/TripMapContentBuilder.java - core/api/dto/src/main/java/fr/ird/observe/dto/data/TripMapContentBuilder.java Changes: ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/TripUIHelper.java ===================================== @@ -25,6 +25,7 @@ package fr.ird.observe.client.datasource.editor.api.content.data; import fr.ird.observe.client.WithClientUIContextApi; import fr.ird.observe.client.configuration.ClientConfig; import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUIHandler; +import fr.ird.observe.client.datasource.editor.api.content.data.map.ObserveMapPane; import fr.ird.observe.client.datasource.editor.api.content.data.map.TripMapUI; import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRootOpenableUI; import fr.ird.observe.dto.data.RootOpenableDto; @@ -88,7 +89,7 @@ public abstract class TripUIHelper<D extends RootOpenableDto, U extends ContentR updateMapModel(); } }); - + tripMap.getObserveMapPane().addPropertyChangeListener(ObserveMapPane.PROPERTY_REBUILD_MODEL, e -> rebuildTripMap()); ui.getMainTabbedPane().addChangeListener(this::onTabChanged); // Disable map tab because can't manage it :( ui.getMainTabbedPane().setEnabledAt(ui.getMainTabbedPane().getTabCount() - 1, false); @@ -121,8 +122,34 @@ public abstract class TripUIHelper<D extends RootOpenableDto, U extends ContentR TripMapUI tripMap = ui.getTripMap(); TripMapConfigDto tripMapConfig = tripMap.getTripMapConfig(); log.info(prefix + String.format("Ask to build map: show observation? %s, show logbook? %s", tripMapConfig.isAddObservations(), tripMapConfig.isAddLogbook())); - TripMapDto tripLonglineMap = getMap(tripMapConfig); - tripMap.getHandler().doOpenMap(tripMapConfig, tripLonglineMap); + TripMapDto tripMapDto = getMap(tripMapConfig); + Set<String> excludedFeatureNames = tripMap.getObserveMapPane().getExcludedFeatureNames(); + tripMap.getHandler().doOpenMap(tripMapConfig, tripMapDto, excludedFeatureNames); + } finally { + getBusyModel().popTask(); + } + }); + } + + private void rebuildTripMap() { + if (ui.getModel().getStates().isCreatingMode()) { + return; + } + if (opening) { + return; + } + if (!ui.getModel().getStates().isOpened()) { + return; + } + + SwingUtilities.invokeLater(() -> { + getBusyModel().addTask("Rebuild map"); + try { + TripMapUI tripMap = ui.getTripMap(); + TripMapConfigDto tripMapConfig = tripMap.getTripMapConfig(); + TripMapDto tripMapDto = tripMap.getObserveMapPane().getTripMapDto(); + Set<String> excludedFeatureNames = tripMap.getObserveMapPane().getExcludedFeatureNames(); + tripMap.getHandler().doOpenMap(tripMapConfig, tripMapDto, excludedFeatureNames); } finally { getBusyModel().popTask(); } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/ObserveMapPane.java ===================================== @@ -22,6 +22,8 @@ package fr.ird.observe.client.datasource.editor.api.content.data.map; * #L% */ +import fr.ird.observe.client.util.UIHelper; +import fr.ird.observe.dto.data.TripMapDto; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.geotools.geometry.jts.ReferencedEnvelope; @@ -33,18 +35,25 @@ import org.geotools.swing.JMapPane; import org.geotools.swing.event.MapPaneAdapter; import org.geotools.swing.event.MapPaneEvent; +import javax.swing.Icon; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Point; import java.awt.Polygon; +import java.awt.Rectangle; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import static io.ultreia.java4all.i18n.I18n.n; import static io.ultreia.java4all.i18n.I18n.t; @@ -54,6 +63,7 @@ import static io.ultreia.java4all.i18n.I18n.t; */ public class ObserveMapPane extends JMapPane { public static final String PROPERTY_ADD_POINT_COUNT = "addPointCount"; + public static final String PROPERTY_REBUILD_MODEL = "rebuildModel"; protected static final int MARGIN = 10; protected static final int SCALE_HEIGHT = 15; protected static final int SCALE_WIDTH_MAX = 200; @@ -74,6 +84,18 @@ public class ObserveMapPane extends JMapPane { private boolean showLegend = true; private LegendPosition legendPosition = LegendPosition.BOTTOM; private boolean addPointCount = true; + private final Icon notSelectedIcon = UIHelper.getUIManagerIcon("checkbox.empty"); + private final Icon selectedIcon = UIHelper.getUIManagerIcon("checkbox.full"); + private TripMapDto tripMapDto; + private final Map<ObserveMapPaneLegendItem, Rectangle> legendItemPositions = new LinkedHashMap<>(); + + public void setTripMapDto(TripMapDto tripMapDto) { + this.tripMapDto = tripMapDto; + } + + public TripMapDto getTripMapDto() { + return tripMapDto; + } public enum LegendPosition { TOP, BOTTOM @@ -93,6 +115,23 @@ public class ObserveMapPane extends JMapPane { } + public Set<String> getExcludedFeatureNames() { + return legendItems.stream().filter(i -> !i.isSelected()).map(ObserveMapPaneLegendItem::getName).collect(Collectors.toSet()); + } + + public void fireRebuildModel() { + firePropertyChange(PROPERTY_REBUILD_MODEL, null, true); + } + + public Optional<ObserveMapPaneLegendItem> getLegendItem(Point point) { + for (Map.Entry<ObserveMapPaneLegendItem, Rectangle> entry : legendItemPositions.entrySet()) { + if (entry.getValue().contains(point)) { + return Optional.of(entry.getKey()); + } + } + return Optional.empty(); + } + public long getScaleInMiles() { return scaleInMiles; } @@ -128,13 +167,13 @@ public class ObserveMapPane extends JMapPane { } public boolean isLegendPositionTop() { - return getLegendPosition()==LegendPosition.TOP; + return getLegendPosition() == LegendPosition.TOP; } + public boolean isLegendPositionBottom() { - return getLegendPosition()==LegendPosition.BOTTOM; + return getLegendPosition() == LegendPosition.BOTTOM; } - public boolean isAddPointCount() { return addPointCount; } @@ -222,18 +261,18 @@ public class ObserveMapPane extends JMapPane { Point2D direction = cardinalPoint.getDirection(rotation, AXIS_LENGTH, center); - Point2D sommet1 = cardinalPoint.getDirection(rotation - Math.PI / 4, SUB_AXIS_LENGTH, center); + Point2D top1 = cardinalPoint.getDirection(rotation - Math.PI / 4, SUB_AXIS_LENGTH, center); - Point2D sommet2 = cardinalPoint.getDirection(rotation + Math.PI / 4, SUB_AXIS_LENGTH, center); + Point2D top2 = cardinalPoint.getDirection(rotation + Math.PI / 4, SUB_AXIS_LENGTH, center); Polygon polygon = new Polygon(); polygon.addPoint((int) center.getX(), (int) center.getY()); polygon.addPoint((int) direction.getX(), (int) direction.getY()); - polygon.addPoint((int) sommet2.getX(), (int) sommet2.getY()); + polygon.addPoint((int) top2.getX(), (int) top2.getY()); graphics.fillPolygon(polygon); - graphics.drawLine((int) sommet1.getX(), (int) sommet1.getY(), (int) direction.getX(), (int) direction.getY()); + graphics.drawLine((int) top1.getX(), (int) top1.getY(), (int) direction.getX(), (int) direction.getY()); Rectangle2D textArea = fm.getStringBounds(cardinalPoint.getLabel(), graphics); @@ -258,8 +297,10 @@ public class ObserveMapPane extends JMapPane { this.legendItems = legendItems; } + protected void paintLegend(Graphics graphics) { + legendItemPositions.clear(); if (getLegendItems() != null && isShowLegend()) { int x; @@ -291,25 +332,34 @@ public class ObserveMapPane extends JMapPane { int legendWidth = ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH + maxLabelWidth + ObserveMapPaneLegendItem.LEGEND_MARGIN * 2; - graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); - graphics.fillRect( - x, - y, - legendWidth, - LEGEND_MARGIN); +// graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); +// graphics.fillRect( +// x, +// y, +// legendWidth, +// LEGEND_MARGIN); y += LEGEND_MARGIN; for (ObserveMapPaneLegendItem item : legendItems) { + Rectangle itemPosition = new Rectangle(x, y, legendWidth, ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT); + legendItemPositions.put(item, itemPosition); + + + int x2 = x + 22; graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); graphics.fillRect( x, y, - legendWidth, + legendWidth + 22, ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT); - - BufferedImage symbole = new BufferedImage( + if (item.isSelected()) { + selectedIcon.paintIcon(this, graphics, x, y); + } else { + notSelectedIcon.paintIcon(this, graphics, x, y); + } + BufferedImage symbol = new BufferedImage( ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH, ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT, BufferedImage.TYPE_INT_ARGB); @@ -322,32 +372,33 @@ public class ObserveMapPane extends JMapPane { if (rule.getFilter().evaluate(item.getSimpleFeature())) { - drawer.drawDirect(symbole, item.getSimpleFeature(), rule); + drawer.drawDirect(symbol, item.getSimpleFeature(), rule); } } } - graphics.drawImage(symbole, x + LEGEND_MARGIN, y, null); + graphics.drawImage(symbol, x2 + LEGEND_MARGIN, y, null); - graphics.setColor(Color.BLACK); + Color textColor = item.isSelected() ? Color.BLACK : ObserveMapPaneLegendItem.LEGEND_TEXT_NOT_SELECTED; + graphics.setColor(textColor); int labelMarginBottom = ((ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT - fm.getHeight()) / 2) + fm.getDescent(); graphics.drawString(item.getLabel(addPointCount), - x + LEGEND_MARGIN + ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH, + x2 + LEGEND_MARGIN + ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH, y + ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT - labelMarginBottom); y += ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT; } - graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); - graphics.fillRect( - x, - y, - legendWidth, - LEGEND_MARGIN); +// graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); +// graphics.fillRect( +// x, +// y, +// legendWidth+22, +// LEGEND_MARGIN); } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/ObserveMapPaneLegendItem.java ===================================== @@ -38,18 +38,23 @@ public class ObserveMapPaneLegendItem { protected static final int LEGEND_SYMBOL_WIDTH = 50; protected static final int LEGEND_MARGIN = 5; protected static final Color LEGEND_BACKGROUND = new Color(1f, 1f, 1f, 0.8f); + protected static final Color LEGEND_TEXT_NOT_SELECTED = Color.RED; protected final SimpleFeature simpleFeature; protected final Style style; protected final String label; protected final int notValidCount; protected final int validCount; + protected final String name; + protected boolean selected; - public ObserveMapPaneLegendItem(SimpleFeature simpleFeature, Style style, String label, int notValidCount, int validCount) { + public ObserveMapPaneLegendItem(String name, SimpleFeature simpleFeature, Style style, String label, int notValidCount, int validCount, boolean selected) { + this.name = name; this.simpleFeature = simpleFeature; this.style = style; this.label = label; this.notValidCount = notValidCount; this.validCount = validCount; + this.selected = selected; } public static Coordinate[] lineCoordinates() { @@ -63,6 +68,10 @@ public class ObserveMapPaneLegendItem { return new Coordinate(LEGEND_SYMBOL_WIDTH / 2., LEGEND_ITEM_HEIGHT / 2.); } + public String getName() { + return name; + } + public SimpleFeature getSimpleFeature() { return simpleFeature; } @@ -90,4 +99,12 @@ public class ObserveMapPaneLegendItem { } return label; } + + public boolean isSelected() { + return selected; + } + + public void setSelected(boolean selected) { + this.selected = selected; + } } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/TripMapContentBuilderSupport.java ===================================== @@ -108,7 +108,7 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil protected StyledLayerDescriptor styledLayerDescriptor; private GeometryFactory geometryFactory; - public static TripMapContentBuilderSupport of(TripMapConfig config, TripMapConfigDto tripMapConfig, TripMapDto tripMapDto, List<TripMapPoint> tripMapPoints) throws Exception { + public static TripMapContentBuilderSupport of(TripMapConfig config, TripMapConfigDto tripMapConfig, TripMapDto tripMapDto, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) throws Exception { TripMapContentBuilderSupport builder = (TripMapContentBuilderSupport) config.getTripMapContentBuilders().stream().filter(t -> t.accept(tripMapDto)).findFirst().orElseThrow(IllegalStateException::new); builder.reset(); String mapDateFormat = config.getMapDateFormat(); @@ -134,8 +134,8 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil for (File layerFile : config.getMapLayerFiles()) { builder.addLayer(layerFile); } - builder.addLines(tripMapConfig, tripMapPoints); - builder.addPoints(tripMapConfig, tripMapPoints); + builder.addLines(tripMapConfig, tripMapPoints, excludedFeatureNames); + builder.addPoints(tripMapConfig, tripMapPoints, excludedFeatureNames); return builder; } @@ -242,22 +242,13 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil mapContent.addLayer(layer); } - protected void addPoint(DefaultFeatureCollection pointsFeatures, TripMapPoint tripMapPoint) { - Point point = getGeometryFactory().createPoint(create(tripMapPoint)); - pointBuilder.add(point); - pointBuilder.add(formatDate(tripMapPoint.getTime())); - pointBuilder.add(tripMapPoint.getType().name()); - pointsFeatures.add(pointBuilder.buildFeature(null)); - validPoints.computeIfAbsent(tripMapPoint.getType(), e -> new LinkedList<>()).add(tripMapPoint); - } - - public void addPoints(List<TripMapPoint> tripMapPoints, String layerName, String notValidPointsLabel) { + public void addPoints(List<TripMapPoint> tripMapPoints, String layerName, String notValidPointsLabel, Set<String> excludedFeatureNames) { DefaultFeatureCollection pointsFeatures = new DefaultFeatureCollection(); Style stylePoints = findStyle(styledLayerDescriptor, layerName); for (TripMapPoint tripMapPoint : tripMapPoints) { if (tripMapPoint.isValid()) { - addPoint(pointsFeatures, tripMapPoint); + addPoint(pointsFeatures, tripMapPoint, excludedFeatureNames); } else { notValidPoints.computeIfAbsent(tripMapPoint.getType(), e -> new LinkedList<>()).add(tripMapPoint); } @@ -281,15 +272,29 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil if (notValidCount > 0) { notValidTypes.remove(type); } - addPointLegend(stylePoints, type.name(), label, notValidCount, validCount); + addPointLegend(stylePoints, type.name(), label, notValidCount, validCount, excludedFeatureNames); } if (!notValidTypes.isEmpty()) { for (TripMapPointType type : notValidTypes) { List<TripMapPoint> notValidPointsForType = notValidPoints.get(type); String label = I18n.t(notValidPointsLabel, notValidPointsForType.size()) + " - " + type.getLabel(); - addPointLegend(stylePoints, "notValidPoint", label, 0, 0); + addPointLegend(stylePoints, "notValidPoint", label, 0, 0, excludedFeatureNames); } } + validPoints.clear(); + notValidPoints.clear(); + } + + protected void addPoint(DefaultFeatureCollection pointsFeatures, TripMapPoint tripMapPoint, Set<String> excludedFeatureNames) { + if (!excludedFeatureNames.contains(tripMapPoint.getType().name())) { + // display this point + Point point = getGeometryFactory().createPoint(create(tripMapPoint)); + pointBuilder.add(point); + pointBuilder.add(formatDate(tripMapPoint.getTime())); + pointBuilder.add(tripMapPoint.getType().name()); + pointsFeatures.add(pointBuilder.buildFeature(null)); + } + validPoints.computeIfAbsent(tripMapPoint.getType(), e -> new LinkedList<>()).add(tripMapPoint); } protected GeometryFactory getGeometryFactory() { @@ -337,14 +342,20 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil return DATE_FORMAT.format(date); } - protected void addLine(DefaultFeatureCollection linesFeatures, String lineName, Coordinate[] coordinates) { + protected void addLine(DefaultFeatureCollection linesFeatures, String lineName, Coordinate[] coordinates, Set<String> excludedFeatureNames) { + if (excludedFeatureNames.contains(lineName)) { + return; + } LineString line = getGeometryFactory().createLineString(coordinates); lineBuilder.add(line); lineBuilder.add(lineName); linesFeatures.add(lineBuilder.buildFeature(null)); } - protected void addLine(DefaultFeatureCollection linesFeatures, String lineName, Coordinate[] coordinates, Date date) { + protected void addLine(DefaultFeatureCollection linesFeatures, String lineName, Coordinate[] coordinates, Date date, Set<String> excludedFeatureNames) { + if (excludedFeatureNames.contains(lineName)) { + return; + } LineString line = getGeometryFactory().createLineString(coordinates); lineBuilder.add(line); lineBuilder.add(date == null ? null : formatDate(date)); @@ -352,7 +363,7 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil linesFeatures.add(lineBuilder.buildFeature(null)); } - protected void addLineLegend(Style styleLines, String legendName, String legendLabel) { + protected void addLineLegend(Style styleLines, String legendName, String legendLabel, Set<String> excludedFeatureNames) { LineString line = getGeometryFactory().createLineString(ObserveMapPaneLegendItem.lineCoordinates()); lineBuilder.add(line); if (withLabelLine) { @@ -360,17 +371,17 @@ public abstract class TripMapContentBuilderSupport implements TripMapContentBuil } lineBuilder.add(legendName); SimpleFeature simpleFeature = lineBuilder.buildFeature(null); - ObserveMapPaneLegendItem legendTripDay = new ObserveMapPaneLegendItem(simpleFeature, styleLines, legendLabel, 0, 0); + ObserveMapPaneLegendItem legendTripDay = new ObserveMapPaneLegendItem(legendName, simpleFeature, styleLines, legendLabel, 0, 0, !excludedFeatureNames.contains(legendName)); legendItems.add(legendTripDay); } - protected void addPointLegend(Style stylePoints, String legendName, String legendLabel, int notValidCount, int validCount) { + protected void addPointLegend(Style stylePoints, String legendName, String legendLabel, int notValidCount, int validCount, Set<String> excludedFeatureNames) { Point point = getGeometryFactory().createPoint(ObserveMapPaneLegendItem.pointCoordinates()); pointBuilder.add(point); pointBuilder.add(""); pointBuilder.add(legendName); SimpleFeature simpleFeature = pointBuilder.buildFeature(null); - ObserveMapPaneLegendItem legendPoint = new ObserveMapPaneLegendItem(simpleFeature, stylePoints, legendLabel, notValidCount, validCount); + ObserveMapPaneLegendItem legendPoint = new ObserveMapPaneLegendItem(legendName, simpleFeature, stylePoints, legendLabel, notValidCount, validCount, !excludedFeatureNames.contains(legendName)); legendItems.add(legendPoint); } } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/map/TripMapUIHandler.java ===================================== @@ -47,6 +47,8 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.Set; /** * @author Tony Chemit - dev@tchemit.fr @@ -76,7 +78,7 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { return ui.getObserveMapPane(); } - public void doOpenMap(TripMapConfigDto tripMapConfig, TripMapDto tripMapDto) { + public void doOpenMap(TripMapConfigDto tripMapConfig, TripMapDto tripMapDto, Set<String> excludedFeatureNames) { try { flipContent(); @@ -89,10 +91,12 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { List<TripMapPoint> tripMapPoints = new ArrayList<>(tripMapDto.getPoints()); log.info(String.format("Found %d point(s).", tripMapPoints.size())); + mapPane.setTripMapDto(tripMapDto); TripMapContentBuilderSupport mapContentBuilder = TripMapContentBuilderSupport.of(config, tripMapConfig, tripMapDto, - tripMapPoints); + tripMapPoints, + excludedFeatureNames); // set zoom tripArea = new ReferencedEnvelope(); @@ -224,7 +228,16 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { @Override public void mouseClicked(MouseEvent e) { - + if (e.getClickCount() < 2) { + return; + } + Point point = e.getPoint(); + Optional<ObserveMapPaneLegendItem> legendItem = getObserveMapPane().getLegendItem(point); + legendItem.ifPresent(i -> { + i.setSelected(!i.isSelected()); + log.info("Change selected value for legend item: {} to value: {}", i.getName(), i.isSelected()); + SwingUtilities.invokeLater(ui.getObserveMapPane()::fireRebuildModel); + }); } @Override ===================================== client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/common/TripMapContentBuilder.java ===================================== @@ -95,26 +95,26 @@ public class TripMapContentBuilder extends TripMapContentBuilderSupport { } @Override - public void addLines(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints) { + public void addLines(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) { if (tripMapConfig.isAddObservations()) { List<TripMapPoint> obsPoints = getObsPoints(tripMapPoints); addFishingZone(OBSERVATIONS_ZONES_BUILDER, obsPoints); - addLines(OBSERVATIONS_LINES_BUILDER, obsPoints, tripMapConfig.isAddObservationsTripSegment()); + addLines(OBSERVATIONS_LINES_BUILDER, obsPoints, tripMapConfig.isAddObservationsTripSegment(), excludedFeatureNames); } if (tripMapConfig.isAddLogbook()) { List<TripMapPoint> logbookPoints = getLogbookPoints(tripMapPoints); addFishingZone(LOGBOOK_ZONES_BUILDER, logbookPoints); - addLines(LOGBOOK_LINES_BUILDER, logbookPoints, tripMapConfig.isAddLogbookTripSegment()); + addLines(LOGBOOK_LINES_BUILDER, logbookPoints, tripMapConfig.isAddLogbookTripSegment(), excludedFeatureNames); } } @Override - public void addPoints(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints) { + public void addPoints(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) { if (tripMapConfig.isAddObservations()) { - addPoints(getObsPoints(tripMapPoints), OBSERVATION_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.observation.points.not.valid")); + addPoints(getObsPoints(tripMapPoints), OBSERVATION_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.observation.points.not.valid"), excludedFeatureNames); } if (tripMapConfig.isAddLogbook()) { - addPoints(getLogbookPoints(tripMapPoints), LOGBOOK_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.logbook.points.not.valid")); + addPoints(getLogbookPoints(tripMapPoints), LOGBOOK_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.logbook.points.not.valid"), excludedFeatureNames); } } @@ -132,36 +132,36 @@ public class TripMapContentBuilder extends TripMapContentBuilderSupport { } } - private void addLines(LinesBuilder builder, List<TripMapPoint> tripMapPoints, boolean addTripSegment) { + private void addLines(LinesBuilder builder, List<TripMapPoint> tripMapPoints, boolean addTripSegment, Set<String> excludedFeatureNames) { DefaultFeatureCollection linesFeatures = new DefaultFeatureCollection(); Set<String> lineTypes = new TreeSet<>(); builder.build(tripMapPoints); if (addTripSegment) { - addLines(TRIP_LINE_TYPE, linesFeatures, lineTypes, builder.getTripLines()); + addLines(TRIP_LINE_TYPE, linesFeatures, lineTypes, builder.getTripLines(), excludedFeatureNames); } - addLines(SETTING_LINE_TYPE, linesFeatures, lineTypes, builder.getSettingLines()); - addLines(HAULING_LINE_TYPE, linesFeatures, lineTypes, builder.getHaulingLines()); + addLines(SETTING_LINE_TYPE, linesFeatures, lineTypes, builder.getSettingLines(), excludedFeatureNames); + addLines(HAULING_LINE_TYPE, linesFeatures, lineTypes, builder.getHaulingLines(), excludedFeatureNames); if (!linesFeatures.isEmpty()) { Style styleLines = findStyle(styledLayerDescriptor, builder.layerName()); Layer layerLines = new FeatureLayer(linesFeatures, styleLines, builder.layerName()); mapContent.addLayer(layerLines); if (lineTypes.contains(TRIP_LINE_TYPE)) { - addLineLegend(styleLines, TRIP_LINE_TYPE, builder.tripLineTitle()); + addLineLegend(styleLines, TRIP_LINE_TYPE, builder.tripLineTitle(), excludedFeatureNames); } if (lineTypes.contains(SETTING_LINE_TYPE)) { - addLineLegend(styleLines, SETTING_LINE_TYPE, builder.settingLineTitle()); + addLineLegend(styleLines, SETTING_LINE_TYPE, builder.settingLineTitle(), excludedFeatureNames); } if (lineTypes.contains(HAULING_LINE_TYPE)) { - addLineLegend(styleLines, HAULING_LINE_TYPE, builder.haulingLineTitle()); + addLineLegend(styleLines, HAULING_LINE_TYPE, builder.haulingLineTitle(), excludedFeatureNames); } } } - private void addLines(String lineType, DefaultFeatureCollection linesFeatures, Set<String> lineTypes, List<Coordinate[]> lines) { + private void addLines(String lineType, DefaultFeatureCollection linesFeatures, Set<String> lineTypes, List<Coordinate[]> lines, Set<String> excludedFeatureNames) { if (!lines.isEmpty()) { lineTypes.add(lineType); for (Coordinate[] tripLine : lines) { - addLine(linesFeatures, lineType, tripLine); + addLine(linesFeatures, lineType, tripLine, excludedFeatureNames); } } } ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/common/TripMapContentBuilder.java ===================================== @@ -100,24 +100,24 @@ public class TripMapContentBuilder extends fr.ird.observe.client.datasource.edit } @Override - public void addPoints(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints) { + public void addPoints(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) { if (tripMapConfig.isAddObservations()) { - addPoints(tripMapPoints.stream().filter(f -> f.getType().isTrip() || f.getType().isObs()).collect(Collectors.toList()), OBSERVATION_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.observation.points.not.valid")); + addPoints(tripMapPoints.stream().filter(f -> f.getType().isTrip() || f.getType().isObs()).collect(Collectors.toList()), OBSERVATION_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.observation.points.not.valid"), excludedFeatureNames); } if (tripMapConfig.isAddLogbook()) { - addPoints(tripMapPoints.stream().filter(f -> f.getType().isTrip() || f.getType().isLogbook()).collect(Collectors.toList()), LOGBOOK_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.logbook.points.not.valid")); + addPoints(tripMapPoints.stream().filter(f -> f.getType().isTrip() || f.getType().isLogbook()).collect(Collectors.toList()), LOGBOOK_POINTS_LAYER_NAME, n("observe.ui.datasource.editor.content.map.logbook.points.not.valid"), excludedFeatureNames); } } @Override - public void addLines(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints) { + public void addLines(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) { if (tripMapConfig.isAddObservations() && tripMapConfig.isAddObservationsTripSegment()) { addLines0(tripMapPoints.stream().filter(f -> f.getType().isTrip() || f.getType().isObs()).collect(Collectors.toList()), "observationDay", "observationNight", true, t("observe.ui.datasource.editor.content.map.legend.obs.tripDay"), - t("observe.ui.datasource.editor.content.map.legend.obs.tripBetweenTwoDays")); + t("observe.ui.datasource.editor.content.map.legend.obs.tripBetweenTwoDays"), excludedFeatureNames); } if (tripMapConfig.isAddLogbook() && tripMapConfig.isAddLogbookTripSegment()) { addLines0(tripMapPoints.stream().filter(f -> f.getType().isTrip() || f.getType().isLogbook()).collect(Collectors.toList()), @@ -125,23 +125,23 @@ public class TripMapContentBuilder extends fr.ird.observe.client.datasource.edit "logbookSegment", false, t("observe.ui.datasource.editor.content.map.legend.logbook.tripSegment"), - null); + null, excludedFeatureNames); } } - protected void addTripDay(DefaultFeatureCollection linesFeatures, String label, List<Coordinate> coordinatesByDay, TripMapPoint previousPoint) { + protected void addTripDay(DefaultFeatureCollection linesFeatures, String label, List<Coordinate> coordinatesByDay, TripMapPoint previousPoint, Set<String> excludedFeatureNames) { if (coordinatesByDay.size() > 1) { Coordinate[] coordinates = coordinatesByDay.toArray(new Coordinate[0]); - addLine(linesFeatures, label, coordinates, previousPoint.getTime()); + addLine(linesFeatures, label, coordinates, previousPoint.getTime(), excludedFeatureNames); } } - protected void addTripBetweenTwoDay(DefaultFeatureCollection linesFeatures, String label, TripMapPoint previousPoint, TripMapPoint point, boolean addTime) { + protected void addTripBetweenTwoDay(DefaultFeatureCollection linesFeatures, String label, TripMapPoint previousPoint, TripMapPoint point, boolean addTime, Set<String> excludedFeatureNames) { Coordinate[] coordinates = create(previousPoint, point); - addLine(linesFeatures, label, coordinates, addTime ? previousPoint.getTime() : null); + addLine(linesFeatures, label, coordinates, addTime ? previousPoint.getTime() : null, excludedFeatureNames); } - protected void addLines0(List<TripMapPoint> tripMapPoints, String pointDay, String pointNight, boolean addDate, String pointDayLabel, String pointNightLabel) { + protected void addLines0(List<TripMapPoint> tripMapPoints, String pointDay, String pointNight, boolean addDate, String pointDayLabel, String pointNightLabel, Set<String> excludedFeatureNames) { if (tripMapPoints.size() == 2 && tripMapPoints.stream().allMatch(t -> t.getType().isTrip())) { // Got only trip points, nothing to display then return; @@ -157,24 +157,24 @@ public class TripMapContentBuilder extends fr.ird.observe.client.datasource.edit Coordinate coordinate = create(point); if (previousPoint != null && !DateUtils.isSameDay(previousPoint.getTime(), point.getTime())) { // changing day - addTripDay(linesFeatures, pointDay, coordinatesByDay, previousPoint); - addTripBetweenTwoDay(linesFeatures, pointNight, previousPoint, point, addDate); + addTripDay(linesFeatures, pointDay, coordinatesByDay, previousPoint, excludedFeatureNames); + addTripBetweenTwoDay(linesFeatures, pointNight, previousPoint, point, addDate, excludedFeatureNames); coordinatesByDay.clear(); } coordinatesByDay.add(coordinate); previousPoint = point; } if (previousPoint != null) { - addTripDay(linesFeatures, pointDay, coordinatesByDay, previousPoint); + addTripDay(linesFeatures, pointDay, coordinatesByDay, previousPoint, excludedFeatureNames); } Style styleLines = findStyle(styledLayerDescriptor, LINES_LAYER_NAME); if (!linesFeatures.isEmpty()) { Layer layerLines = new FeatureLayer(linesFeatures, styleLines, LINES_LAYER_NAME); mapContent.addLayer(layerLines); } - addLineLegend(styleLines, pointDay, pointDayLabel); + addLineLegend(styleLines, pointDay, pointDayLabel, excludedFeatureNames); if (pointNightLabel != null) { - addLineLegend(styleLines, pointNight, pointNightLabel); + addLineLegend(styleLines, pointNight, pointNightLabel, excludedFeatureNames); } } ===================================== core/api/dto/src/main/java/fr/ird/observe/dto/data/TripMapContentBuilder.java ===================================== @@ -43,9 +43,9 @@ public interface TripMapContentBuilder { boolean accept(TripMapDto tripMapDto); - void addLines(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints) throws Exception; + void addLines(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) throws Exception; - void addPoints(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints) throws Exception; + void addPoints(TripMapConfigDto tripMapConfig, List<TripMapPoint> tripMapPoints, Set<String> excludedFeatureNames) throws Exception; File getStyleFile(Path mapDirectory); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/70eb8a1c52404a5bc6d4c5b4e... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/70eb8a1c52404a5bc6d4c5b4e... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)