예제 #1
0
 @Override
 public void postHandle(
     HttpServletRequest request,
     HttpServletResponse response,
     Object handler,
     ModelAndView modelAndView)
     throws Exception {
   if (modelAndView != null) {
     I18n i18n = i18nManager.getI18n("org.hisp.dhis.web.mobile");
     modelAndView.addObject("i18n", i18n);
   }
 }
  public BufferedImage generateMapImage(
      Map map, Date date, OrganisationUnit unit, Integer width, Integer height) {
    Assert.isTrue(map != null);

    if (width == null && height == null) {
      width = MapUtils.DEFAULT_MAP_WIDTH;
    }

    InternalMap internalMap = new InternalMap();

    List<MapView> mapViews = new ArrayList<MapView>(map.getMapViews());
    Collections.reverse(mapViews);

    User user = currentUserService.getCurrentUser();

    for (MapView mapView : mapViews) {
      InternalMapLayer mapLayer = getSingleInternalMapLayer(mapView, user, date);

      if (mapLayer != null) {
        internalMap.getLayers().add(mapLayer);
      }
    }

    if (internalMap.getLayers().isEmpty()) {
      return null;
    }

    boolean dataLayer = map.getMapViews().get(0).isDataLayer();

    // Build representation of a map using GeoTools, then render as image
    BufferedImage mapImage = MapUtils.render(internalMap, width, height);

    if (!dataLayer) {
      return mapImage;
    } else {
      // Build the legend set, then render it to an image
      InternalMapLayer mapLayer = internalMap.getLayers().get(0); // TODO improve

      LegendSet legendSet = new LegendSet(mapLayer); // TODO

      BufferedImage titleImage = MapUtils.renderTitle(map.getName(), width);

      BufferedImage legendImage = legendSet.render(i18nManager.getI18nFormat());

      // Combine the legend image and the map image into one image
      return combineLegendAndMapImages(titleImage, legendImage, mapImage);
    }
  }