use of org.activityinfo.legacy.shared.reports.content.PieMapMarker in project activityinfo by bedatadriven.
the class LeafletMarkerFactory method createPieMapMarker.
public static Marker createPieMapMarker(PieMapMarker marker) {
StringBuilder sb = new StringBuilder();
sb.append("/icon?t=piechart&r=").append(marker.getRadius());
for (SliceValue slice : marker.getSlices()) {
sb.append("&value=").append(slice.getValue());
sb.append("&color=").append(slice.getColor());
}
String iconUrl = sb.toString();
int size = marker.getRadius() * 2;
IconOptions iconOptions = new IconOptions();
iconOptions.setIconUrl(iconUrl);
iconOptions.setIconAnchor(new Point(marker.getRadius(), marker.getRadius()));
iconOptions.setIconSize(new Point(size, size));
Options markerOptions = new MarkerOptions();
markerOptions.setProperty("icon", new Icon(iconOptions));
setModel(markerOptions.getJSObject(), marker);
return new Marker(toLatLng(marker), markerOptions);
}
use of org.activityinfo.legacy.shared.reports.content.PieMapMarker in project activityinfo by bedatadriven.
the class PiechartMapLayerGeneratorTest method testSomething.
@Test
public void testSomething() {
SiteDTO siteData = new SiteDTO();
siteData.setId(42);
siteData.setX(15.0);
siteData.setY(0.0);
siteData.setIndicatorValue(1, 50.0);
siteData.setIndicatorValue(2, 10.0);
siteData.setIndicatorValue(3, 20.0);
siteData.setIndicatorValue(4, 40.0);
PiechartMapLayer pcml = new PiechartMapLayer();
pcml.setMinRadius(10);
pcml.setMaxRadius(50);
pcml.addIndicatorId(1);
pcml.addIndicatorId(2);
pcml.addIndicatorId(3);
pcml.addIndicatorId(4);
pcml.setClustering(new NoClustering());
TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
Map<Integer, Indicator> indicators = Maps.newHashMap();
indicators.put(1, new Indicator());
indicators.put(2, new Indicator());
indicators.put(3, new Indicator());
indicators.put(4, new Indicator());
PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
gen.setSites(Arrays.asList(siteData));
MapContent mc = new MapContent();
gen.generate(map, mc);
assertThat(mc.getMarkers().size(), equalTo(1));
assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
use of org.activityinfo.legacy.shared.reports.content.PieMapMarker in project activityinfo by bedatadriven.
the class PieChartLegendRenderer method drawSymbol.
private void drawSymbol(Graphics2D g2d) {
PieMapMarker marker = new PieMapMarker();
marker.setRadius(layer.getMaxRadius());
marker.setX(PADDING + layer.getMaxRadius());
marker.setY(PADDING + layer.getMaxRadius());
double[] values = calculateNiceLookingValues(layer.getSlices().size());
int nextValue = 0;
for (PiechartMapLayer.Slice slice : layer.getSlices()) {
PieMapMarker.SliceValue sliceValue = new PieMapMarker.SliceValue();
sliceValue.setColor(slice.getColor());
sliceValue.setValue(values[nextValue++]);
marker.getSlices().add(sliceValue);
}
ImageMapRenderer.drawPieMarker(g2d, marker);
}
use of org.activityinfo.legacy.shared.reports.content.PieMapMarker in project activityinfo by bedatadriven.
the class LeafletMarkerFactory method create.
public static Marker create(MapMarker mapMarker, final EventHandler... markerEventHandlers) {
final Marker marker;
if (mapMarker instanceof IconMapMarker) {
marker = createIconMapMarker((IconMapMarker) mapMarker);
} else if (mapMarker instanceof PieMapMarker) {
marker = createPieMapMarker((PieMapMarker) mapMarker);
} else if (mapMarker instanceof BubbleMapMarker) {
marker = createBubbleMapMarker((BubbleMapMarker) mapMarker);
} else {
final Options options = new Options();
setModel(options.getJSObject(), mapMarker);
marker = new Marker(toLatLng(mapMarker), options);
}
if (markerEventHandlers != null) {
for (EventHandler handler : markerEventHandlers) {
EventHandlerManager.addEventHandler(marker, EventHandler.Events.click, handler);
}
}
return marker;
}
use of org.activityinfo.legacy.shared.reports.content.PieMapMarker in project activityinfo by bedatadriven.
the class MapIconServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Cache forever
resp.setHeader("Cache-Control", "max-age=31556926, public");
if (req.getParameter("t").equals("bubble")) {
int radius = Integer.parseInt(req.getParameter("r"));
Color color = ColorUtil.colorFromString(req.getParameter("c"));
BufferedImage icon = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = icon.createGraphics();
g2d.setPaint(new Color(255, 255, 255, 0));
g2d.fillRect(0, 0, radius * 2, radius * 2);
renderer.drawBubble(g2d, color, radius, radius, radius);
resp.setContentType("image/png");
ImageIO.write(icon, "PNG", resp.getOutputStream());
} else {
if (req.getParameter("t").equals("piechart")) {
int radius = Integer.parseInt(req.getParameter("r"));
BufferedImage icon = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = icon.createGraphics();
PieMapMarker pmm = new PieMapMarker();
pmm.setRadius(radius);
pmm.setX(radius);
pmm.setY(radius);
String[] values = req.getParameterValues("value");
String[] colors = req.getParameterValues("color");
if (colors.length != values.length) {
String error = "Expected same amount of colors & values. Amount of Colors: [{0}]. Amount of " + "values: [{1}].";
error = String.format(error, colors.length, values.length);
throw new ServletException(error);
}
for (int i = 0; i < colors.length; i++) {
String color;
double value = 0.0;
color = colors[i];
try {
value = Double.parseDouble(values[i]);
} catch (NumberFormatException e) {
// color = Color.decode(colors[i]).getRGB();
}
SliceValue slice = new SliceValue();
slice.setColor(color);
slice.setValue(value);
pmm.getSlices().add(slice);
}
g2d.setPaint(new Color(255, 255, 255, 0));
g2d.fillRect(0, 0, radius * 2, radius * 2);
renderer.drawPieMarker(g2d, pmm);
resp.setContentType("image/png");
ImageIO.write(icon, "PNG", resp.getOutputStream());
}
}
}
Aggregations