use of org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter in project dhis2-core by dhis2.
the class GeoToolsMapGenerationService method getSingleInternalMapLayer.
private InternalMapLayer getSingleInternalMapLayer(MapView mapView, User user, Date date) {
if (mapView == null) {
return null;
}
List<OrganisationUnit> atLevels = new ArrayList<>();
List<OrganisationUnit> inGroups = new ArrayList<>();
if (mapView.hasOrganisationUnitLevels()) {
atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(mapView.getOrganisationUnitLevels(), mapView.getOrganisationUnits()));
}
if (mapView.hasItemOrganisationUnitGroups()) {
inGroups.addAll(organisationUnitService.getOrganisationUnits(mapView.getItemOrganisationUnitGroups(), mapView.getOrganisationUnits()));
}
mapView.init(user, date, null, atLevels, inGroups, null);
List<OrganisationUnit> organisationUnits = mapView.getAllOrganisationUnits();
FilterUtils.filter(organisationUnits, new OrganisationUnitWithCoordinatesFilter());
java.util.Map<String, OrganisationUnit> uidOuMap = new HashMap<>();
for (OrganisationUnit ou : organisationUnits) {
uidOuMap.put(ou.getUid(), ou);
}
String name = mapView.getName();
Period period = null;
if (// TODO integrate with
!mapView.getPeriods().isEmpty()) // BaseAnalyticalObject
{
period = mapView.getPeriods().get(0);
} else if (mapView.getRelatives() != null) {
AnalyticsFinancialYearStartKey financialYearStart = systemSettingManager.getSystemSetting(SettingKey.ANALYTICS_FINANCIAL_YEAR_START, AnalyticsFinancialYearStartKey.class);
period = mapView.getRelatives().getRelativePeriods(date, null, false, financialYearStart).get(0);
}
Integer radiusLow = mapView.getRadiusLow() != null ? mapView.getRadiusLow() : DEFAULT_RADIUS_LOW;
Integer radiusHigh = mapView.getRadiusHigh() != null ? mapView.getRadiusHigh() : DEFAULT_RADIUS_HIGH;
// Get the low and high colors, typically in hexadecimal form, e.g.
// #ff3200
Color colorLow = MapUtils.createColorFromString(StringUtils.trimToNull(mapView.getColorLow()) != null ? mapView.getColorLow() : DEFAULT_COLOR_LOW);
Color colorHigh = MapUtils.createColorFromString(StringUtils.trimToNull(mapView.getColorHigh()) != null ? mapView.getColorHigh() : DEFAULT_COLOR_HIGH);
float opacity = mapView.getOpacity() != null ? mapView.getOpacity().floatValue() : DEFAULT_OPACITY;
boolean hasLegendSet = mapView.hasLegendSet();
// Create and setup an internal layer
InternalMapLayer mapLayer = new InternalMapLayer();
mapLayer.setName(name);
mapLayer.setPeriod(period);
mapLayer.setMethod(mapView.getMethod());
mapLayer.setLayer(mapView.getLayer());
mapLayer.setRadiusLow(radiusLow);
mapLayer.setRadiusHigh(radiusHigh);
mapLayer.setColorLow(colorLow);
mapLayer.setColorHigh(colorHigh);
mapLayer.setOpacity(opacity);
mapLayer.setClasses(mapView.getClasses());
if (// Boundary (and facility) layer
!mapView.isDataLayer()) {
for (OrganisationUnit unit : organisationUnits) {
mapLayer.addBoundaryMapObject(unit);
}
} else // Thematic layer
{
Collection<MapValue> mapValues = getAggregatedMapValues(mapView);
if (mapValues.isEmpty()) {
return null;
}
for (MapValue mapValue : mapValues) {
OrganisationUnit orgUnit = uidOuMap.get(mapValue.getOu());
if (orgUnit != null) {
mapLayer.addDataMapObject(mapValue.getValue(), orgUnit);
}
}
if (!mapLayer.hasMapObjects()) {
return null;
}
if (hasLegendSet) {
mapLayer.setIntervalSetFromLegendSet(mapView.getLegendSet());
mapLayer.distributeAndUpdateMapObjectsInIntervalSet();
} else {
mapLayer.setAutomaticIntervalSet(mapLayer.getClasses());
mapLayer.distributeAndUpdateMapObjectsInIntervalSet();
}
// Update the radius of each map object in this map layer according
// to
// its map object's highest and lowest values
mapLayer.applyInterpolatedRadii();
}
return mapLayer;
}
Aggregations