Search in sources :

Example 1 with PieMapMarker

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);
}
Also used : IconOptions(org.discotools.gwt.leaflet.client.types.IconOptions) Options(org.discotools.gwt.leaflet.client.Options) MarkerOptions(org.discotools.gwt.leaflet.client.marker.MarkerOptions) MarkerOptions(org.discotools.gwt.leaflet.client.marker.MarkerOptions) SliceValue(org.activityinfo.legacy.shared.reports.content.PieMapMarker.SliceValue) Point(org.discotools.gwt.leaflet.client.types.Point) Icon(org.discotools.gwt.leaflet.client.types.Icon) MapIcon(org.activityinfo.legacy.shared.reports.model.MapIcon) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) CircleMarker(org.discotools.gwt.leaflet.client.marker.CircleMarker) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) MapMarker(org.activityinfo.legacy.shared.reports.content.MapMarker) Marker(org.discotools.gwt.leaflet.client.marker.Marker) Point(org.discotools.gwt.leaflet.client.types.Point) IconOptions(org.discotools.gwt.leaflet.client.types.IconOptions)

Example 2 with PieMapMarker

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));
}
Also used : MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) NoClustering(org.activityinfo.legacy.shared.reports.model.clustering.NoClustering) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Example 3 with PieMapMarker

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);
}
Also used : PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer)

Example 4 with PieMapMarker

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;
}
Also used : IconOptions(org.discotools.gwt.leaflet.client.types.IconOptions) Options(org.discotools.gwt.leaflet.client.Options) MarkerOptions(org.discotools.gwt.leaflet.client.marker.MarkerOptions) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) EventHandler(org.discotools.gwt.leaflet.client.events.handler.EventHandler) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) CircleMarker(org.discotools.gwt.leaflet.client.marker.CircleMarker) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) MapMarker(org.activityinfo.legacy.shared.reports.content.MapMarker) Marker(org.discotools.gwt.leaflet.client.marker.Marker)

Example 5 with PieMapMarker

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());
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) Color(com.google.code.appengine.awt.Color) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) SliceValue(org.activityinfo.legacy.shared.reports.content.PieMapMarker.SliceValue) BufferedImage(com.google.code.appengine.awt.image.BufferedImage) Graphics2D(com.google.code.appengine.awt.Graphics2D)

Aggregations

PieMapMarker (org.activityinfo.legacy.shared.reports.content.PieMapMarker)7 SliceValue (org.activityinfo.legacy.shared.reports.content.PieMapMarker.SliceValue)3 PiechartMapLayer (org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer)3 Color (com.google.code.appengine.awt.Color)2 Graphics2D (com.google.code.appengine.awt.Graphics2D)2 BufferedImage (com.google.code.appengine.awt.image.BufferedImage)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 BubbleMapMarker (org.activityinfo.legacy.shared.reports.content.BubbleMapMarker)2 IconMapMarker (org.activityinfo.legacy.shared.reports.content.IconMapMarker)2 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)2 MapMarker (org.activityinfo.legacy.shared.reports.content.MapMarker)2 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)2 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)2 Options (org.discotools.gwt.leaflet.client.Options)2 CircleMarker (org.discotools.gwt.leaflet.client.marker.CircleMarker)2 Marker (org.discotools.gwt.leaflet.client.marker.Marker)2 MarkerOptions (org.discotools.gwt.leaflet.client.marker.MarkerOptions)2 IconOptions (org.discotools.gwt.leaflet.client.types.IconOptions)2 Test (org.junit.Test)2 File (java.io.File)1