Search in sources :

Example 6 with MapView

use of org.hisp.dhis.mapping.MapView in project dhis2-core by dhis2.

the class BaseAnalyticalObjectTest method testAddDataDimensionItem.

@Test
public void testAddDataDimensionItem() {
    DataElement deA = new DataElement();
    deA.setAutoFields();
    MapView mv = new MapView(MapView.LAYER_THEMATIC1);
    mv.addDataDimensionItem(deA);
    assertEquals(1, mv.getDataDimensionItems().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) MapView(org.hisp.dhis.mapping.MapView) Test(org.junit.Test)

Example 7 with MapView

use of org.hisp.dhis.mapping.MapView in project dhis2-core by dhis2.

the class GeoToolsMapGenerationService method generateMapImageForUser.

@Override
public BufferedImage generateMapImageForUser(Map map, Date date, OrganisationUnit unit, Integer width, Integer height, User user) {
    Assert.isTrue(map != null, "Map cannot be null");
    if (width == null && height == null) {
        width = MapUtils.DEFAULT_MAP_WIDTH;
    }
    InternalMap internalMap = new InternalMap();
    List<MapView> mapViews = new ArrayList<>(map.getMapViews());
    Collections.reverse(mapViews);
    for (MapView mapView : mapViews) {
        InternalMapLayer mapLayer = getSingleInternalMapLayer(mapView, user, date);
        if (mapLayer != null) {
            internalMap.getLayers().add(mapLayer);
        }
    }
    if (internalMap.getLayers().isEmpty()) {
        return null;
    }
    InternalMapLayer dataLayer = internalMap.getFirstDataLayer();
    BufferedImage mapImage = MapUtils.render(internalMap, width, height);
    if (dataLayer == null) {
        mapViews.forEach(BaseAnalyticalObject::clearTransientState);
        return mapImage;
    } else {
        LegendSet legendSet = new LegendSet(dataLayer);
        BufferedImage legendImage = legendSet.render(i18nManager.getI18nFormat());
        BufferedImage titleImage = MapUtils.renderTitle(map.getName(), getImageWidth(legendImage, mapImage));
        mapViews.forEach(BaseAnalyticalObject::clearTransientState);
        return combineLegendAndMapImages(titleImage, legendImage, mapImage);
    }
}
Also used : BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) MapView(org.hisp.dhis.mapping.MapView) BufferedImage(java.awt.image.BufferedImage)

Aggregations

MapView (org.hisp.dhis.mapping.MapView)7 DataElement (org.hisp.dhis.dataelement.DataElement)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BufferedImage (java.awt.image.BufferedImage)1 BaseAnalyticalObject (org.hisp.dhis.common.BaseAnalyticalObject)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 I18nFormat (org.hisp.dhis.i18n.I18nFormat)1 Period (org.hisp.dhis.period.Period)1