Search in sources :

Example 1 with DivIcon

use of org.discotools.gwt.leaflet.client.types.DivIcon in project opennms by OpenNMS.

the class IconCreateCallback method createIcon.

//    public JSObject createIcon(final MarkerCluster cluster) {
//        final DivIconOptions options = new DivIconOptions();
//        options.setHtml("<div><span>" + cluster.getChildCount() + "</span></div>");
//        options.setIconSize(new Point(40, 40));
//
//        int severity = 0;
//        String severityLabel = "Normal";
//        for (final JSNodeMarker marker : (List<JSNodeMarker>)cluster.getAllChildMarkers()) {
//            final int nodeSeverity = marker.getSeverity();
//            if (nodeSeverity > severity) {
//                severity = nodeSeverity;
//                severityLabel = marker.getSeverityLabel();
//            }
//            if (severity == 7) break;
//        }
//
//        options.setClassName("marker-cluster marker-cluster-" + severityLabel);
//
//        return new DivIcon(options).getJSObject();
//    }
public JSObject createIcon(final MarkerCluster cluster) {
    final DivIconOptions options = new DivIconOptions();
    options.setIconSize(new Point(40, 40));
    int severity = 0;
    int total = 0;
    double[] dataArray = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
    //class array corresponds to data array
    String[] classArray = { "Indeterminate", "Cleared", "Normal", "Warning", "Minor", "Major", "Critical" };
    String severityLabel = "Normal";
    for (final JSNodeMarker marker : (List<JSNodeMarker>) cluster.getAllChildMarkers()) {
        final int nodeSeverity = marker.getSeverity();
        total++;
        dataArray[nodeSeverity - 1] += 1.0;
        if (nodeSeverity > severity) {
            severity = nodeSeverity;
            severityLabel = marker.getSeverityLabel();
        }
    }
    String svg = getChartSvg(20.0, 20.0, 18.0, 12.0, dataArray, classArray, (double) total);
    options.setHtml(svg + "<div><span>" + cluster.getChildCount() + "</span></div>");
    options.setClassName("marker-cluster marker-cluster-" + severityLabel);
    return new DivIcon(options).getJSObject();
}
Also used : DivIconOptions(org.discotools.gwt.leaflet.client.types.DivIconOptions) List(java.util.List) Point(org.discotools.gwt.leaflet.client.types.Point) DivIcon(org.discotools.gwt.leaflet.client.types.DivIcon) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) Point(org.discotools.gwt.leaflet.client.types.Point)

Aggregations

List (java.util.List)1 DivIcon (org.discotools.gwt.leaflet.client.types.DivIcon)1 DivIconOptions (org.discotools.gwt.leaflet.client.types.DivIconOptions)1 Point (org.discotools.gwt.leaflet.client.types.Point)1 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)1