Search in sources :

Example 6 with JSNodeMarker

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker 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)

Example 7 with JSNodeMarker

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker in project opennms by OpenNMS.

the class MarkerCluster method getAllChildMarkers.

public final List<JSNodeMarker> getAllChildMarkers() {
    final List<JSNodeMarker> markers = new ArrayList<>();
    final JsArray<JSObject> markerObjects = getMarkerObjects();
    if (markerObjects == null)
        return markers;
    for (int i = 0; i < markerObjects.length(); i++) {
        final JSObject markerObject = markerObjects.get(i);
        final JSNodeMarker marker = new JSNodeMarker(markerObject);
        markers.add(marker);
    }
    return markers;
}
Also used : ArrayList(java.util.ArrayList) JSObject(org.discotools.gwt.leaflet.client.jsobject.JSObject) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Example 8 with JSNodeMarker

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker in project opennms by OpenNMS.

the class MarkerContainer method getDisabledMarkers.

public List<JSNodeMarker> getDisabledMarkers() {
    final ArrayList<JSNodeMarker> markers = new ArrayList<>();
    final List<JSNodeMarker> existingMarkers = getMarkers();
    if (existingMarkers != null) {
        for (final NodeMarker marker : existingMarkers) {
            if (marker instanceof JSNodeMarker) {
                final JSNodeMarker m = (JSNodeMarker) marker;
                if (!m_filteredMarkers.contains(m)) {
                    markers.add(m);
                }
            }
        }
    }
    return Collections.unmodifiableList(markers);
}
Also used : JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) ArrayList(java.util.ArrayList) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Example 9 with JSNodeMarker

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker in project opennms by OpenNMS.

the class MarkerContainer method refresh.

public void refresh() {
    logger.info("MarkerContainer.refresh()");
    final List<JSNodeMarker> markers = new ArrayList<>();
    final List<JSNodeMarker> existingMarkers = getAllMarkers();
    if (existingMarkers != null) {
        for (final JSNodeMarker marker : existingMarkers) {
            if (m_filter.matches(marker)) {
                markers.add(marker);
            }
        }
    }
    m_filteredMarkers = markers;
    logger.info("MarkerContainer.refresh(): out of " + getMarkers().size() + " markers, " + markers.size() + " matched the search filter.");
    m_eventManager.fireEvent(new FilteredMarkersUpdatedEvent());
}
Also used : FilteredMarkersUpdatedEvent(org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.FilteredMarkersUpdatedEvent) ArrayList(java.util.ArrayList) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Example 10 with JSNodeMarker

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker in project opennms by OpenNMS.

the class NodeMapConnector method updateNodes.

private void updateNodes() {
    final List<MapNode> nodes = getState().nodes;
    LOG.info("NodeMapConnector.onStateChanged(): nodes list is now: " + nodes);
    final List<JSNodeMarker> featureCollection = new ArrayList<>();
    if (nodes.isEmpty()) {
        getWidget().setMarkers(featureCollection);
        return;
    }
    for (final MapNode node : nodes) {
        final JSNodeMarker marker = new JSNodeMarker(new LatLng(node.getLatitude(), node.getLongitude()));
        marker.putProperty(JSNodeMarker.Property.NODE_ID, node.getNodeId());
        marker.putProperty(JSNodeMarker.Property.NODE_LABEL, node.getNodeLabel());
        marker.putProperty(JSNodeMarker.Property.FOREIGN_SOURCE, node.getForeignSource());
        marker.putProperty(JSNodeMarker.Property.FOREIGN_ID, node.getForeignId());
        marker.putProperty(JSNodeMarker.Property.DESCRIPTION, node.getDescription());
        marker.putProperty(JSNodeMarker.Property.MAINTCONTRACT, node.getMaintcontract());
        marker.putProperty(JSNodeMarker.Property.IP_ADDRESS, node.getIpAddress());
        marker.putProperty(JSNodeMarker.Property.SEVERITY, node.getSeverity());
        marker.putProperty(JSNodeMarker.Property.SEVERITY_LABEL, node.getSeverityLabel());
        final List<String> categories = node.getCategories();
        if (categories != null) {
            marker.setCategories(categories.toArray(new String[] {}));
        }
        // TODO: Icon handling should be moved to the Widget
        if (m_icons.containsKey(marker.getSeverityLabel())) {
            marker.setIcon(m_icons.get(marker.getSeverityLabel()));
        } else {
            marker.setIcon(m_icons.get("Normal"));
        }
        // TODO: This should be moved to the Widget
        marker.bindPopup(NodeMarkerClusterCallback.getPopupTextForMarker(marker));
        featureCollection.add(marker);
    }
    getWidget().setMarkers(featureCollection);
    getConnection().getLoadingIndicator().hide();
}
Also used : ArrayList(java.util.ArrayList) MapNode(org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode) LatLng(org.discotools.gwt.leaflet.client.types.LatLng) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Aggregations

JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)10 ArrayList (java.util.ArrayList)5 List (java.util.List)3 Coordinates (org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates)3 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)2 LatLng (org.discotools.gwt.leaflet.client.types.LatLng)2 NodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 JSObject (org.discotools.gwt.leaflet.client.jsobject.JSObject)1 Popup (org.discotools.gwt.leaflet.client.popup.Popup)1 PopupOptions (org.discotools.gwt.leaflet.client.popup.PopupOptions)1 DivIcon (org.discotools.gwt.leaflet.client.types.DivIcon)1 DivIconOptions (org.discotools.gwt.leaflet.client.types.DivIconOptions)1 LatLngBounds (org.discotools.gwt.leaflet.client.types.LatLngBounds)1 Point (org.discotools.gwt.leaflet.client.types.Point)1 Map (org.opennms.features.vaadin.nodemaps.internal.gwt.client.Map)1 MapNode (org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode)1 SearchResults (org.opennms.features.vaadin.nodemaps.internal.gwt.client.SearchResults)1 FilteredMarkersUpdatedEvent (org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.FilteredMarkersUpdatedEvent)1 MarkerCluster (org.opennms.features.vaadin.nodemaps.internal.gwt.client.ui.MarkerCluster)1