dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23610
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11501: PNG maps, added option for custom image widths
------------------------------------------------------------
revno: 11501
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-07-24 14:38:12 +0200
message:
PNG maps, added option for custom image widths
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java 2013-07-18 17:16:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java 2013-07-24 12:38:12 +0000
@@ -51,16 +51,25 @@
/**
* Generate an image that represents this map.
*
- * @param mapView the map view that will be rendered
+ * @param mapView the map view that will be rendered,
* @return the rendered map image or null if there is no data for the map view.
*/
- public BufferedImage generateMapImage( MapView mapView );
+ BufferedImage generateMapImage( MapView mapView );
/**
* Generate an image that represents this map.
*
- * @param mapView the map view that will be rendered
- * @return the rendered map image or null if there is no data for the map view.
- */
- public BufferedImage generateMapImage( Map map );
+ * @param map the map that will be rendered,
+ * @return the rendered map image or null if there is no data for the map view.
+ */
+ BufferedImage generateMapImage( Map map );
+
+ /**
+ * Generate an image that represents this map.
+ *
+ * @param map the map that will be rendered,
+ * @param width the width of the map image.
+ * @return the rendered map image or null if there is no data for the map view.
+ */
+ BufferedImage generateMapImage( Map map, int width );
}
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2013-07-22 17:13:22 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2013-07-24 12:38:12 +0000
@@ -91,12 +91,16 @@
return generateMapImage( map );
}
-
+
public BufferedImage generateMapImage( Map map )
{
+ return generateMapImage( map, 512 );
+ }
+
+ public BufferedImage generateMapImage( Map map, int width )
+ {
Assert.isTrue( map != null );
-
- int height = 512;
+ Assert.isTrue( width > LegendSet.LEGEND_TOTAL_WIDTH );
InternalMap internalMap = new InternalMap();
@@ -116,11 +120,11 @@
}
// Build representation of a map using GeoTools, then render as image
- BufferedImage mapImage = MapUtils.render( internalMap, height );
+ BufferedImage mapImage = MapUtils.render( internalMap, ( width - LegendSet.LEGEND_TOTAL_WIDTH ) );
// Build the legend set, then render it to an image
LegendSet legendSet = new LegendSet( internalMap.getLayers().get( 0 ) ); //TODO
- BufferedImage legendImage = legendSet.render( height );
+ BufferedImage legendImage = legendSet.render( width );
// Combine the legend image and the map image into one image
BufferedImage finalImage = combineLegendAndMapImages( legendImage, mapImage );
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java 2013-07-24 12:38:12 +0000
@@ -45,7 +45,7 @@
public class Legend
{
public static final Font TITLE_FONT = new Font( "title", Font.BOLD, 15 );
- public static final Font PLAIN_FONT = new Font( "plain", Font.PLAIN, 13 );
+ public static final Font PLAIN_FONT = new Font( "plain", Font.PLAIN, 11 );
private InternalMapLayer mapLayer;
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java 2011-12-13 09:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java 2013-07-24 12:38:12 +0000
@@ -44,7 +44,7 @@
{
private Interval interval;
- private static final int WIDTH = 25;
+ private static final int WIDTH = 22;
private static final int HEIGHT = 20;
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java 2011-12-13 09:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java 2013-07-24 12:38:12 +0000
@@ -49,11 +49,11 @@
private Color backgroundColor = null;
- private static final int LEGEND_WIDTH = 250;
-
- private static final int LEGEND_MARGIN_LEFT = 5;
-
+ private static final int LEGEND_WIDTH = 145;
+ private static final int LEGEND_MARGIN_LEFT = 4;
private static final int LEGEND_MARGIN_BOTTOM = 20;
+
+ public static final int LEGEND_TOTAL_WIDTH = LEGEND_WIDTH + LEGEND_MARGIN_LEFT;
public LegendSet()
{
@@ -91,18 +91,19 @@
Graphics2D g = (Graphics2D) image.getGraphics();
// Overwrite if one of the legends is bigger than imageMaxHeight
- if ( imageDimensions.getHeight() > imageMaxHeight )
+ if ( imageHeight > imageMaxHeight )
{
- imageMaxHeight = (int) imageDimensions.getHeight();
+ imageMaxHeight = imageHeight;
}
// Draw a background if the background color is specified
// NOTE It will be transparent otherwise, which is desired
+ /*
if ( backgroundColor != null )
{
g.setColor( backgroundColor );
g.fill( new Rectangle( 0, 0, imageWidth, imageHeight ) );
- }
+ }*/
// Turn anti-aliasing on
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java 2013-07-18 17:16:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java 2013-07-24 12:38:12 +0000
@@ -60,6 +60,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
@@ -223,11 +224,14 @@
}
@RequestMapping(value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET)
- public void getMapData( @PathVariable String uid, HttpServletResponse response ) throws Exception
+ public void getMapData(
+ @PathVariable String uid,
+ @RequestParam( required = false, defaultValue = "512" ) Integer width,
+ HttpServletResponse response ) throws Exception
{
Map map = mappingService.getMap( uid );
- renderMapViewPng( map, response );
+ renderMapViewPng( map, width, response );
}
//--------------------------------------------------------------------------
@@ -295,10 +299,10 @@
}
}
- private void renderMapViewPng( Map map, HttpServletResponse response )
+ private void renderMapViewPng( Map map, int width, HttpServletResponse response )
throws Exception
{
- BufferedImage image = mapGenerationService.generateMapImage( map );
+ BufferedImage image = mapGenerationService.generateMapImage( map, width );
if ( image != null )
{