Example usage for com.google.gwt.maps.client.base HasLatLngBounds getSouthWest

List of usage examples for com.google.gwt.maps.client.base HasLatLngBounds getSouthWest

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.base HasLatLngBounds getSouthWest.

Prototype

public HasLatLng getSouthWest();

Source Link

Document

Returns the south-west corner of this bounds.

Usage

From source file:com.google.mobile.trippy.web.client.db.DefaultSearchService.java

License:Apache License

/**
 * Lonely planet search related methods//  w w  w.  ja v  a2  s . co  m
 */

private void doLpSearch(final String poiType, final HasLatLngBounds searchBounds,
        final SearchResultsListener listener) {

    final List<SearchItem> searchItemList = new ArrayList<SearchItem>();

    lPSearchService.searchPOIByBoundingBox(searchBounds.getNorthEast().getLatitude(),
            searchBounds.getSouthWest().getLatitude(), searchBounds.getNorthEast().getLongitude(),
            searchBounds.getSouthWest().getLongitude(), poiType, new AsyncCallback<ArrayList<POI>>() {

                @Override
                public void onFailure(Throwable caught) {
                    listener.onFailure(caught);
                }

                @Override
                public void onSuccess(final ArrayList<POI> results) {
                    addLPResultsToList(poiType, searchBounds, searchItemList, results);
                    searchResultsCache.put(getResultsCacheKey(SearchType.LP, poiType, searchBounds),
                            searchItemList);
                    listener.onSuccess(searchItemList);
                }
            });
}

From source file:com.google.mobile.trippy.web.client.db.DefaultSearchService.java

License:Apache License

@Override
public String boundsToString(final HasLatLngBounds bounds) {
    return bounds.getSouthWest().getLatitude() + "," + bounds.getSouthWest().getLongitude() + ","
            + bounds.getNorthEast().getLatitude() + "," + bounds.getNorthEast().getLongitude();
}

From source file:com.google.mobile.trippy.web.client.presenter.CreateNewTripPresenter.java

License:Apache License

/**
 * Create Trip and Add Trip to the Db.//  w  w  w .  jav a 2s.c om
 */
void addTripToDb(final String location, final String address, final HasLatLngBounds latlngBound) {
    final Trip trip = new Trip();
    trip.setLocation(location);
    trip.setDuration(Constants.DEFAULT_TRIP_DURATION);
    trip.setLatitude(latlngBound.getCenter().getLatitude());
    trip.setLongitude(latlngBound.getCenter().getLongitude());

    // LP place details.
    trip.setPlaceId(0L);
    trip.setNorthLatitude(latlngBound.getNorthEast().getLatitude());
    trip.setSouthLatitude(latlngBound.getSouthWest().getLatitude());
    trip.setEastLongitude(latlngBound.getNorthEast().getLongitude());
    trip.setWestLongitude(latlngBound.getSouthWest().getLongitude());

    trip.setStartDate(Constants.UNSCHEDULED_DATE);
    trip.setLastModified(new Date());
    trip.setAddedOn(new Date());
    trip.setName(location);
    trip.setDescription("");
    trip.setThumbsUp(0);
    trip.setThumbsDown(0);

    final Toast toast = singletonComponents.getToast();
    toast.showLoading(singletonComponents.getMessage().toastMsgCreatingTrip());
    singletonComponents.getTripService().addTrip(trip, new AsyncCallback<Trip>() {

        @Override
        public void onSuccess(final Trip result) {
            toast.hideLoading();
            toast.showToast(singletonComponents.getMessage().tripCreated());
            singletonComponents.getEventBus().fireEvent(new ShowTripScheduleEvent(result, true));
        }

        @Override
        public void onFailure(final Throwable caught) {
            toast.hideLoading();
            toast.showToast(singletonComponents.getMessage().tripSaveFailed());
            singletonComponents.getEventBus().fireEvent(new ShowHomePageEvent());
        }
    });
}

From source file:com.mashery.examples.api.client.weatherbug.WeatherBugOverlayView.java

License:Open Source License

@Override
public void draw() {
    HasLatLngBounds bounds = getMap().getBounds();
    HasMapCanvasProjection ovrPrj = getProjection();
    HasPoint ovrNE = ovrPrj.fromLatLngToDivPixel(bounds.getNorthEast());
    HasPoint ovrSW = ovrPrj.fromLatLngToDivPixel(bounds.getSouthWest());

    div.getStyle().setLeft(ovrSW.getX(), Unit.PX);
    div.getStyle().setTop(ovrNE.getY(), Unit.PX);
    div.getStyle().setWidth(ovrNE.getX() - ovrSW.getX(), Unit.PX);
    div.getStyle().setHeight(ovrSW.getY() - ovrNE.getY(), Unit.PX);

    String endpoint = WEATHERBUG_ENDPOINT.replace("${layerType}", layerType.getPath());
    HashSet<TileKey> usedTiles = new HashSet<TileKey>();

    int zoom = getMap().getZoom();
    double scale = Math.pow(2d, zoom);
    HasProjection prj = getMap().getProjection();
    LatLng nwLatLng = new LatLng(bounds.getNorthEast().getLatitude(), bounds.getSouthWest().getLongitude());
    HasPoint nwRaw = prj.fromLatLngToPoint(nwLatLng);
    LatLng seLatLng = new LatLng(bounds.getSouthWest().getLatitude(), bounds.getNorthEast().getLongitude());
    HasPoint seRaw = prj.fromLatLngToPoint(seLatLng);

    Point nw = new Point(Math.floor(nwRaw.getX() * scale), Math.floor(nwRaw.getY() * scale));
    Point se = new Point(Math.floor(seRaw.getX() * scale), Math.floor(seRaw.getY() * scale));

    double offsetX = nw.getX() % 256d;
    double offsetY = nw.getY() % 256d;
    Point startPoint = new Point(nw.getX() - offsetX, nw.getY() - offsetY);

    while (startPoint.getY() < se.getY()) {
        Point p = new Point(startPoint.getX(), startPoint.getY());
        startPoint = new Point(startPoint.getX(), startPoint.getY() + 256);
        while (p.getX() < se.getX()) {
            int tx = (int) p.getX() / 256;
            int ty = (int) p.getY() / 256;

            TileKey tileKey = new TileKey(tx, ty, zoom);
            usedTiles.add(tileKey);/*from  w  w  w.  j  a va 2 s . co  m*/

            ImageElement img = tiles.remove(tileKey);
            if (img == null) {
                img = Document.get().createImageElement();
                img.getStyle().setBorderStyle(BorderStyle.NONE);
                img.getStyle().setBorderWidth(0d, Unit.PX);
                img.getStyle().setPosition(Position.ABSOLUTE);

                StringBuilder buf = new StringBuilder(endpoint);
                buf.append("&tx=").append(tx);
                buf.append("&ty=").append(ty);
                buf.append("&zm=").append(zoom);
                img.setSrc(buf.toString());

                div.appendChild(img);
            } else {
                img.getStyle().setVisibility(Visibility.VISIBLE);
            }

            img.getStyle().setLeft(p.getX() - nw.getX(), Unit.PX);
            img.getStyle().setTop(p.getY() - nw.getY(), Unit.PX);
            img.getStyle().setWidth(256d, Unit.PX);
            img.getStyle().setHeight(256d, Unit.PX);
            tiles.put(tileKey, img);

            p = new Point(p.getX() + 256, p.getY());
        }
    }

    for (Iterator<Map.Entry<TileKey, ImageElement>> i = tiles.entrySet().iterator(); i.hasNext();) {
        Map.Entry<TileKey, ImageElement> entry = i.next();
        if (!usedTiles.remove(entry.getKey())) {
            if (tiles.size() > TILE_CACHE_SIZE) {
                i.remove();
                entry.getValue().removeFromParent();
            } else {
                entry.getValue().getStyle().setVisibility(Visibility.HIDDEN);
            }
        }
    }
}