Example usage for com.google.gwt.maps.client.geom LatLngBounds getCenter

List of usage examples for com.google.gwt.maps.client.geom LatLngBounds getCenter

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.geom LatLngBounds getCenter.

Prototype

public final native LatLng getCenter() ;

Source Link

Document

Returns the point at the center of the rectangle.

Usage

From source file:org.onebusaway.webapp.gwt.common.control.PlaceSearch.java

License:Apache License

public void query(String query, PlaceSearchListener listener, LatLngBounds view) {

    final LocationHandler handler = new LocationHandler(listener, view);

    // Google Local Search
    LocalSearch search = new LocalSearch();

    search.setAddressLookupMode(AddressLookupMode.ENABLED);
    if (view != null)
        search.setCenterPoint(view.getCenter());
    search.addSearchCompleteHandler(handler);
    search.execute(query);//from  w ww.j  a  v a 2  s  . co  m

    // Google Maps Geocoder Search
    Geocoder geocoder = new Geocoder();
    if (view != null)
        geocoder.setViewport(view);
    geocoder.getLocations(query, handler);

    handler.scheduleRepeating(1000);
}

From source file:org.onebusaway.webapp.gwt.common.MapOverlayManager.java

License:Apache License

public void setCenterAndZoom(LatLngBounds bounds) {
    _map.setCenter(bounds.getCenter(), _map.getBoundsZoomLevel(bounds));
}

From source file:org.onebusaway.webapp.gwt.mobile_application.view.MapViewController.java

License:Apache License

public void showStopsForRoute(RouteBean route, StopsForRouteBean stopsForRoute) {
    _transitMapManager.showStopsForRoute(route, stopsForRoute, true);
    LatLngBounds b = LatLngBounds.newInstance();
    for (StopBean stop : stopsForRoute.getStops())
        b.extend(LatLng.newInstance(stop.getLat(), stop.getLon()));
    if (!b.isEmpty()) {
        _map.setCenter(b.getCenter(), _map.getBoundsZoomLevel(b));
        _locationManager.setLastSearchLocation(b.getCenter());
    }/*from  w  w w  .ja  v a 2 s. co m*/
}

From source file:org.onebusaway.webapp.gwt.mobile_application.view.MapViewController.java

License:Apache License

public void showPlaces(List<Place> places) {
    _transitMapManager.showPlaces(places, false, new PlaceClickHandlerImpl(true));

    LatLngBounds b = LatLngBounds.newInstance();
    for (Place place : places)
        b.extend(place.getLocation());//from   w  ww  . j a  v a  2  s.co m

    if (!b.isEmpty())
        _locationManager.setLastSearchLocation(b.getCenter());
}

From source file:org.onebusaway.webapp.gwt.tripplanner_library.view.TripBeanMapPresenter.java

License:Apache License

public void displayTrip(ItineraryBean trip, List<Overlay> resultingOverlays) {

    resultingOverlays.clear();// w ww .  j  a  v  a 2s  . c  o  m

    LatLngBounds bounds = LatLngBounds.newInstance();

    for (LegBean segment : trip.getLegs()) {

        String mode = segment.getMode();

        if (mode.equals("transit")) {

            TransitLegBean leg = segment.getTransitLeg();
            String path = leg.getPath();

            if (path != null) {

                List<CoordinatePoint> points = PolylineEncoder.decode(path);
                EncodedPolylineBean bean = PolylineEncoder.createEncodings(points);

                Polyline line = getPathAsPolyline(bean);
                PolyStyleOptions style = PolyStyleOptions.newInstance("#0000FF", 4, 0.5);
                line.setStrokeStyle(style);
                resultingOverlays.add(line);

                addBoundsToBounds(line.getBounds(), bounds);
            }

            StopBean stop = leg.getFromStop();

            if (stop != null) {
                String routeName = leg.getRouteShortName();

                TripPlannerResources resources = TripPlannerResources.INSTANCE;
                SpanPanel w = new SpanPanel();
                w.addStyleName(_css.routeTinyInfoWindow());
                Image image = new Image(resources.getBus14x14().getUrl());
                image.addStyleName(_css.routeModeIcon());
                w.add(image);
                SpanWidget name = new SpanWidget(routeName);
                name.setStyleName(_css.routeName());
                w.add(name);

                LatLng point = LatLng.newInstance(stop.getLat(), stop.getLon());
                TinyInfoWindowMarker marker = new TinyInfoWindowMarker(point, w);
                resultingOverlays.add(marker);

                bounds.extend(point);
            }
        } else if (mode.equals("walk")) {
            List<StreetLegBean> streetLegs = segment.getStreetLegs();
            List<CoordinatePoint> allPoints = new ArrayList<CoordinatePoint>();
            for (StreetLegBean streetLeg : streetLegs) {
                String path = streetLeg.getPath();
                List<CoordinatePoint> points = PolylineEncoder.decode(path);
                allPoints.addAll(points);
            }
            EncodedPolylineBean polyline = PolylineEncoder.createEncodings(allPoints);
            Polyline line = getPathAsPolyline(polyline);
            PolyStyleOptions style = PolyStyleOptions.newInstance("#000000", 4, 0.8);
            line.setStrokeStyle(style);
            resultingOverlays.add(line);

            addBoundsToBounds(line.getBounds(), bounds);
        }
    }

    for (Overlay overlay : resultingOverlays)
        _map.addOverlay(overlay);

    if (_centerOnTrip && !bounds.isEmpty()) {
        _map.setCenter(bounds.getCenter());
        int zoom = _map.getBoundsZoomLevel(bounds);
        _map.setCenter(bounds.getCenter(), zoom);
    }
}

From source file:org.onebusaway.webapp.gwt.where_library.impl.CombinedSearchServiceImpl.java

License:Apache License

@Override
public void search(SearchQueryBean query, int placeTimeoutMillis,
        AsyncCallback<CombinedSearchResult> callback) {

    LatLngBounds originalBounds = getBounds(query.getBounds());
    System.out.println(query.getBounds());
    System.out.println(originalBounds);

    LatLngBounds smallerBounds = null;//from  w ww  . ja v a  2s. com
    if (originalBounds != null) {
        LatLng center = originalBounds.getCenter();
        CoordinateBounds cb2 = SphericalGeometryLibrary.bounds(center.getLatitude(), center.getLongitude(),
                4000);
        smallerBounds = getBounds(cb2);
        System.out.println(cb2);
        System.out.println(smallerBounds);
    }

    CombinedSearchHandlerImpl handler = new CombinedSearchHandlerImpl(originalBounds, placeTimeoutMillis,
            callback);

    // Start the route and stop search
    _service.getRoutesAndStops(query, handler);

    // Google Maps Geocoder Search
    Geocoder geocoder = new Geocoder();
    if (smallerBounds != null)
        geocoder.setViewport(smallerBounds);
    geocoder.getLocations(query.getQuery(), handler);

    // Google Local Search
    LocalSearch search = new LocalSearch();
    search.setAddressLookupMode(AddressLookupMode.ENABLED);
    if (!smallerBounds.isEmpty())
        search.setCenterPoint(smallerBounds.getCenter());
    search.addSearchCompleteHandler(handler);
    search.execute(query.getQuery());
}

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

License:Apache License

public void showStopsForRoute(RouteBean route, StopsForRouteBean stopsForRoute, boolean centerViewOnRoute) {

    reset(false, stopsForRoute.getStops());
    _selectedRoute = route;//from   ww w  . ja  va 2 s  .  c  om

    for (EncodedPolylineBean path : stopsForRoute.getPolylines()) {

        EncodedPolyline epl = EncodedPolyline.newInstance(path.getPoints(), 32, path.getLevels(3), 4);
        epl.setColor("#4F64BA");
        epl.setWeight(3);
        epl.setOpacity(1.0);
        Polyline polyline = Polyline.fromEncoded(epl);
        _manager.addOverlay(polyline);
        _otherOverlays.add(polyline);
    }

    if (centerViewOnRoute) {
        System.out.println("center on route");
        // Center the map on the bounds of the route
        LatLngBounds bounds = LatLngBounds.newInstance();
        for (StopBean stop : stopsForRoute.getStops())
            bounds.extend(LatLng.newInstance(stop.getLat(), stop.getLon()));

        if (!bounds.isEmpty()) {
            int zoomLevel = _map.getBoundsZoomLevel(bounds);
            _map.setCenter(bounds.getCenter(), zoomLevel);
        }
    }
}

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

License:Apache License

public void showPlaces(List<Place> places, boolean showStopsInCurrentView, PlaceClickHandler clickHandler) {

    LatLngBounds bounds = LatLngBounds.newInstance();
    for (Place place : places)
        bounds.extend(place.getLocation());
    if (!bounds.isEmpty())
        _map.setCenter(bounds.getCenter(), _map.getBoundsZoomLevel(bounds));

    reset(showStopsInCurrentView);/*  w  w  w  .ja  va 2s . co  m*/
    for (Place place : places)
        addPlaceToMap(place, clickHandler);
}

From source file:org.opennms.features.poller.remote.gwt.client.GoogleMapsPanel.java

License:Open Source License

/** {@inheritDoc} */
@Override//from ww w.j  a v  a 2s.  c  o  m
public void setBounds(GWTBounds b) {
    LatLngBounds bounds = toLatLngBounds(b);
    getMapWidget().setCenter(bounds.getCenter(), getMapWidget().getBoundsZoomLevel(bounds));
}

From source file:org.sigmah.client.page.entry.editor.MapFieldSet.java

License:Open Source License

public void zoomToBounds(LatLngBounds llbounds) {

    int zoomLevel = map.getBoundsZoomLevel(llbounds);

    if (zoomLevel == 0) {
        pendingZoom = llbounds;/* w ww .ja v a 2s  .  co  m*/
    } else {
        map.setCenter(llbounds.getCenter());
        map.setZoomLevel(zoomLevel);
        pendingZoom = null;
    }
}