Search in sources :

Example 1 with Coordinates

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

the class NodeMapWidget method removeDisabledMarkers.

private void removeDisabledMarkers() {
    // remove disabled markers
    final List<JSNodeMarker> disabledMarkers = m_markerContainer.getDisabledMarkers();
    LOG.info("NodeMapWidget.removeDisabledMarkers(): removing " + disabledMarkers.size() + " disabled markers from the map.");
    Scheduler.get().scheduleIncremental(new RepeatingCommand() {

        final ListIterator<JSNodeMarker> m_markerIterator = disabledMarkers.listIterator();

        @Override
        public boolean execute() {
            if (m_markerIterator.hasNext()) {
                final JSNodeMarker marker = m_markerIterator.next();
                marker.closePopup();
                final Coordinates coordinates = marker.getCoordinates();
                if (coordinates == null) {
                    LOG.log(Level.WARNING, "NodeMapWidget.removeDisabledMarkers(): no coordinates found for marker! " + marker);
                    return true;
                }
                if (m_groupByState && StatesData.inUs(marker.getLatLng().lat(), marker.getLatLng().lng(), StatesData.getUsShape())) {
                    final int stateId = StatesData.getStateId(marker.getLatLng().lat(), marker.getLatLng().lng(), StatesData.getInstance());
                    m_stateClusterGroups[stateId].removeLayer(marker);
                } else {
                    m_markerClusterGroup.removeLayer(marker);
                }
                return true;
            }
            LOG.info("NodeMapWidget.removeDisabledMarkers(): finished removing filtered markers (" + disabledMarkers.size() + " entries)");
            return false;
        }
    });
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Coordinates(org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Example 2 with Coordinates

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

the class NodeMapWidget method addNewMarkers.

private void addNewMarkers() {
    // add new markers
    LOG.info("NodeMapWidget.addNewMarkers(): adding " + m_markerContainer.size() + " markers to the map.");
    Scheduler.get().scheduleIncremental(new RepeatingCommand() {

        final ListIterator<JSNodeMarker> m_markerIterator = m_markerContainer.listIterator();

        @Override
        public boolean execute() {
            if (m_markerIterator.hasNext()) {
                final JSNodeMarker marker = m_markerIterator.next();
                final Coordinates coordinates = marker.getCoordinates();
                if (coordinates == null) {
                    LOG.log(Level.WARNING, "NodeMapWidget.addNewMarkers(): no coordinates found for marker! " + marker);
                    return true;
                }
                if (m_groupByState && StatesData.inUs(coordinates.latitude, coordinates.longitude, StatesData.getUsShape())) {
                    final int stateId = StatesData.getStateId(marker.getLatLng().lat(), marker.getLatLng().lng(), StatesData.getInstance());
                    if (!m_stateClusterGroups[stateId].hasLayer(marker)) {
                        m_stateClusterGroups[stateId].addLayer(marker);
                    }
                } else {
                    if (!m_markerClusterGroup.hasLayer(marker)) {
                        m_markerClusterGroup.addLayer(marker);
                    }
                }
                return true;
            }
            LOG.info("NodeMapWidget.addNewMarkers(): finished adding visible markers (" + m_markerContainer.size() + " entries)");
            return false;
        }
    });
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Coordinates(org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Example 3 with Coordinates

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

the class NodeMapWidget method zoomToFit.

private void zoomToFit() {
    // zoom on first run
    if (m_firstUpdate) {
        LOG.info("NodeMapWidget.zoomToFit(): first update, zooming to bounds.");
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                if (m_firstUpdate) {
                    final List<JSNodeMarker> allMarkers = m_markerContainer.getAllMarkers();
                    if (allMarkers.size() == 0) {
                        LOG.info("NodeMapWidget.zoomToFit(): no bounds yet, skipping.");
                    } else {
                        final LatLngBounds bounds = new LatLngBounds();
                        for (final NodeMarker marker : allMarkers) {
                            LOG.info("NodeMapWidget.zoomToFit(): processing marker: " + marker);
                            final Coordinates coordinates = marker.getCoordinates();
                            if (coordinates == null) {
                                LOG.log(Level.WARNING, "NodeMapWidget.zoomToFit(): no coordinates found for marker! " + marker);
                            } else {
                                bounds.extend(JSNodeMarker.coordinatesToLatLng(coordinates));
                            }
                        }
                        LOG.info("NodeMapWidget.zoomToFit(): setting boundary to " + bounds.toBBoxString() + ".");
                        m_map.fitBounds(bounds);
                        m_firstUpdate = false;
                    }
                }
            }
        });
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) Coordinates(org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates) LatLngBounds(org.discotools.gwt.leaflet.client.types.LatLngBounds) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Coordinates (org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates)3 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)3 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LatLngBounds (org.discotools.gwt.leaflet.client.types.LatLngBounds)1 NodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker)1