Example usage for com.google.gwt.maps.client.base HasPoint getX

List of usage examples for com.google.gwt.maps.client.base HasPoint getX

Introduction

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

Prototype

public double getX();

Source Link

Document

The X coordinate.

Usage

From source file:com.google.mobile.trippy.web.client.widget.InfoWindowView.java

License:Apache License

@Override
public void draw() {

    HasPoint point = getProjection().fromLatLngToDivPixel(position);

    Style contentStyle = infoWindowContent.getElement().getStyle();
    contentStyle.setPosition(Position.ABSOLUTE);
    int mapWidth = getMap().getDiv().getClientWidth();

    int infoWidth = infoWindowContent.getOffsetWidth();
    int pos = (int) (point.getX() - (infoWidth / 2));
    int shift = infoWidth - (getMap().getDiv().getAbsoluteRight() - pos);
    //    if (shift > 0) {
    //      pos -= shift;
    //    }/*from  ww  w.j  a  v  a 2s.c  o  m*/
    contentStyle.setLeft(pos, Unit.PX);
    contentStyle.setTop(point.getY() - 70, Unit.PX);
}

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  av a  2s .c  o  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);
            }
        }
    }
}