diff --git a/www-client/src/main/java/fr/agrometinfo/www/client/view/MapView.java b/www-client/src/main/java/fr/agrometinfo/www/client/view/MapView.java index 9bb1d36561af407ef2fbd809e1d49e3b6ac6f267..99ad507751d8a32b3393a3739ff179faa9e81709 100644 --- a/www-client/src/main/java/fr/agrometinfo/www/client/view/MapView.java +++ b/www-client/src/main/java/fr/agrometinfo/www/client/view/MapView.java @@ -22,6 +22,7 @@ import fr.agrometinfo.www.client.App; import fr.agrometinfo.www.client.event.FeatureSelectEvent; import fr.agrometinfo.www.client.event.FeatureSelectHandler; import fr.agrometinfo.www.client.event.MapClickEvent; +import fr.agrometinfo.www.client.i18n.AppConstants; import fr.agrometinfo.www.client.i18n.MapConstants; import fr.agrometinfo.www.client.i18n.MapMessages; import fr.agrometinfo.www.client.presenter.MapPresenter; @@ -121,6 +122,11 @@ public final class MapView extends HtmlContentBuilder<HTMLElement> implements Fe */ private static final String TITLE = "title"; + /** + * I18N constants. + */ + private static final AppConstants APP_CSTS = GWT.create(AppConstants.class); + /** * Add base layers (OSM, IGN, None). * @@ -295,6 +301,11 @@ public final class MapView extends HtmlContentBuilder<HTMLElement> implements Fe */ private List<ColorInterval> colorIntervals; + /** + * If indicator values are comparison to normal. + */ + private boolean isComparisonToNormal; + /** * Name of selected indicator. */ @@ -387,12 +398,17 @@ public final class MapView extends HtmlContentBuilder<HTMLElement> implements Fe && !featureSelect.getFeatures().isEmpty() // && featureSelect.getFeatures().item(0) != null) { + final String title; + if (isComparisonToNormal) { + title = APP_CSTS.normalComparison() + "<br/>" + indicatorName; + } else { + title = indicatorName; + } final Feature feature = featureSelect.getFeatures().item(0); final Date date = getPropertyAsDate(feature, FeatureProperty.DATE); final Double value = getPropertyAsDouble(feature, FeatureProperty.VALUE); final String praName = praNames.getOrDefault(feature.getId(), feature.getId() + "/" + praNames.size()); - final String content = MSGS.popupContent(indicatorName, value, indicatorUnit, praName, periodStartDate, - date); + final String content = MSGS.popupContent(title, value, indicatorUnit, praName, periodStartDate, date); final Extent extent = feature.getGeometry().getExtent(); tooltip.setPosition(extent); @@ -537,6 +553,8 @@ public final class MapView extends HtmlContentBuilder<HTMLElement> implements Fe if (propertiesFeature.getId() == null) { indicatorName = getProperty(propertiesFeature, FeatureProperty.INDICATOR_NAME); indicatorUnit = getProperty(propertiesFeature, FeatureProperty.INDICATOR_UNIT); + isComparisonToNormal = "true" + .equalsIgnoreCase(getProperty(propertiesFeature, FeatureProperty.COMPARISON_TO_NORMAL)); periodStartDate = getPropertyAsDate(propertiesFeature, FeatureProperty.PERIOD_FIRST_DAY); final Feature[] filtered = new Feature[allFeatures.length - 1]; @@ -563,6 +581,7 @@ public final class MapView extends HtmlContentBuilder<HTMLElement> implements Fe final org.geojson.Feature fakeFeature = list.remove(0); indicatorName = getProperty(fakeFeature, FeatureProperty.INDICATOR_NAME); indicatorUnit = getProperty(fakeFeature, FeatureProperty.INDICATOR_UNIT); + isComparisonToNormal = "true".equalsIgnoreCase(getProperty(fakeFeature, FeatureProperty.COMPARISON_TO_NORMAL)); periodStartDate = getPropertyAsDate(fakeFeature, FeatureProperty.PERIOD_FIRST_DAY); final Feature[] features = list.toArray(new Feature[list.size()]); setFeatures(features); diff --git a/www-server/src/main/java/fr/agrometinfo/www/server/rs/IndicatorResource.java b/www-server/src/main/java/fr/agrometinfo/www/server/rs/IndicatorResource.java index b4a21373ff70abed70a6fdf89063b60b74fe6564..14a3f8c42f0f657d2387f3d7b036cfdb27faffdb 100644 --- a/www-server/src/main/java/fr/agrometinfo/www/server/rs/IndicatorResource.java +++ b/www-server/src/main/java/fr/agrometinfo/www/server/rs/IndicatorResource.java @@ -187,13 +187,15 @@ public class IndicatorResource implements IndicatorService { * @param indicator indicator with metadata to add * @param year to get the first day of indicator period * @param locale locale of descriptions + * @param comparison if returned values are comparison to normal */ private void addMetadata(final FeatureCollection collection, final Indicator indicator, - final Integer year, final Locale locale) { + final Integer year, final Locale locale, final boolean comparison) { final var periodFirstDay = getDate(year, indicator.getPeriod().getFirstDay()); final Feature feature = new Feature(); final MultiPolygon multiPolygon = new MultiPolygon(); feature.setGeometry(multiPolygon); + feature.setProperty(FeatureProperty.COMPARISON_TO_NORMAL.toCamelCase(), String.valueOf(comparison)); feature.setProperty(FeatureProperty.INDICATOR_NAME.toCamelCase(), getTranslation(indicator.getDescriptions(), locale)); feature.setProperty(FeatureProperty.INDICATOR_UNIT.toCamelCase(), indicator.getUnit()); @@ -442,7 +444,7 @@ public class IndicatorResource implements IndicatorService { if (indicator == null) { throwWebApplicationException(Response.Status.BAD_REQUEST, indicatorUid + " is unknown for " + periodCode); } - addMetadata(collection, indicator, year, locale); + addMetadata(collection, indicator, year, locale, Boolean.TRUE.equals(comparison)); final LocalDate date = praDailyValueDao.findLastDate(indicator, year); if (date == null) { throwWebApplicationException(Response.Status.NOT_FOUND, diff --git a/www-shared/src/main/java/fr/agrometinfo/www/shared/dto/FeatureProperty.java b/www-shared/src/main/java/fr/agrometinfo/www/shared/dto/FeatureProperty.java index 04ea6ca294365df5db95bdff597d3f53a5e5e599..9a7ab74045e546a47da915162cfc7bd046aa58e7 100644 --- a/www-shared/src/main/java/fr/agrometinfo/www/shared/dto/FeatureProperty.java +++ b/www-shared/src/main/java/fr/agrometinfo/www/shared/dto/FeatureProperty.java @@ -8,13 +8,13 @@ package fr.agrometinfo.www.shared.dto; */ public enum FeatureProperty { /** - * Feature property. + * If indicator values are comparison to normal. */ - DATE, + COMPARISON_TO_NORMAL, /** * Feature property. */ - VALUE, + DATE, /** * Collection property. */ @@ -26,7 +26,11 @@ public enum FeatureProperty { /** * Collection property. */ - PERIOD_FIRST_DAY; + PERIOD_FIRST_DAY, + /** + * Feature property. + */ + VALUE; /** * @return enum name as camel case format