Example usage for com.google.gwt.maps.client MapWidget getBounds

List of usage examples for com.google.gwt.maps.client MapWidget getBounds

Introduction

In this page you can find the example usage for com.google.gwt.maps.client MapWidget getBounds.

Prototype

public LatLngBounds getBounds() 

Source Link

Document

Returns the lat/lng bounds of the current viewport.

Usage

From source file:org.onebusaway.webapp.gwt.oba_application.view.ResultsTablePresenter.java

License:Apache License

private void refresh() {

    clear();//from  ww w  .  j  a va 2 s.c o  m

    if (_minimized) {

        DivPanel panel = new DivPanel();
        panel.addStyleName(_css.ResultsTableWidgetMinimized());
        _tablePanel.add(panel);

        Anchor showAllEntries = new Anchor("Show all results...");
        showAllEntries.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent arg0) {
                _control.clearActiveSearchResult();
            }
        });
        panel.add(showAllEntries);

        constructAttributionPanel();

    } else {

        _tablePanel.add(_filterWidget);

        List<TimedLocalSearchResult> entries = _model.getActiveEntries();

        Grid grid = new Grid(entries.size() + 1, 4);
        grid.addStyleName(_css.ResultsTableWidgetResultsTable());
        grid.setText(0, 0, "");
        grid.setWidget(0, 1, getTableHeaderWidget("Name", EResultsSort.NAME));
        grid.setWidget(0, 2, getTableHeaderWidget("Rating", EResultsSort.RATING));
        grid.setWidget(0, 3, getTableHeaderWidget("Distance", EResultsSort.DISTANCE));

        grid.getRowFormatter().addStyleName(0, "ResultsTableWidget-ResultsTable-HeaderRow");

        grid.getCellFormatter().addStyleName(0, 1, "ResultsTableWidget-ResultsTable-HeaderRow-Name");
        grid.getCellFormatter().addStyleName(0, 2, "ResultsTableWidget-ResultsTable-HeaderRow-Rating");
        grid.getCellFormatter().addStyleName(0, 3, "ResultsTableWidget-ResultsTable-HeaderRow-Distance");

        int index = 0;

        LatLngBounds bounds = LatLngBounds.newInstance();

        for (TimedLocalSearchResult tlsr : entries) {

            LocalSearchResult entry = tlsr.getLocalSearchResult();

            int tableRow = index + 1;
            EntryClickHandler handler = new EntryClickHandler(tlsr);

            String labelPre = index < ROW_LABELS.length() ? (ROW_LABELS.charAt(index) + "") : "";
            grid.setWidget(tableRow, 0, new SpanWidget(labelPre));
            grid.getCellFormatter().addStyleName(tableRow, 0, "ResultsTableWidget-ResultsTable-LabelColumn");

            Anchor name = new Anchor(entry.getName());
            name.addClickHandler(handler);
            grid.setWidget(tableRow, 1, name);
            grid.getCellFormatter().addStyleName(tableRow, 1, "ResultsTableWidget-ResultsTable-NameColumn");

            if (entry.getRatingUrlSmall() != null) {
                Image image = new Image(entry.getRatingUrlSmall());
                grid.setWidget(tableRow, 2, image);
            } else {
                String rating = entry.getRating() + "/" + entry.getMaxRating();
                grid.setText(tableRow, 2, rating);
            }
            grid.getCellFormatter().addStyleName(tableRow, 2, "ResultsTableWidget-ResultsTable-RatingColumn");

            int minutes = tlsr.getTime() / 60;
            String minLabel = minutes + " " + (minutes == 1 ? " min" : " mins");
            grid.setText(tableRow, 3, minLabel);
            grid.getCellFormatter().addStyleName(tableRow, 3, "ResultsTableWidget-ResultsTable-TimeColumn");

            grid.getRowFormatter().addStyleName(tableRow, "ResultsTableWidget-ResultsTable-ResultRow");

            Marker marker = getMarker(index, entry);
            marker.addMarkerClickHandler(handler);
            _mapOverlayManager.addOverlay(marker, 10, 20);
            _overlays.add(marker);

            index++;

            bounds.extend(marker.getLatLng());
        }

        if (!bounds.isEmpty()) {
            MapWidget map = _mapOverlayManager.getMapWidget();
            LatLngBounds currentView = map.getBounds();
            if (!currentView.containsBounds(bounds)) {
                _mapOverlayManager.setCenterAndZoom(bounds);
            }
        }

        _tablePanel.add(grid);

        constructItemNavigationPanel(entries);
        constructAttributionPanel();
    }
}

From source file:org.onebusaway.webapp.gwt.where_library.view.StopFinderPresenter.java

License:Apache License

/*****************************************************************************
 * Private Methods//from w  w w  .ja  va2  s .  co m
 * 
 * @param includeView
 ****************************************************************************/

private Context buildContext(Map<String, String> params, boolean includeView) {

    Map<String, String> m = new LinkedHashMap<String, String>();
    m.putAll(params);

    if (includeView) {
        MapWidget map = _widget.getMapWidget();

        LatLng center = map.getCenter();

        LatLngBounds bounds = map.getBounds();
        LatLng ne = bounds.getNorthEast();
        LatLng sw = bounds.getSouthWest();
        double latSpan = Math.abs(ne.getLatitude() - sw.getLatitude());
        double lonSpan = Math.abs(ne.getLongitude() - sw.getLongitude());

        addBoundsToParams(m, center.getLatitude(), center.getLongitude(), latSpan, lonSpan);
    }

    return new ContextImpl(m);
}