Search in sources :

Example 36 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class Component method contains.

/**
 * Returns true if the given absolute coordinate is contained in the Component
 *
 * <p>NOTE: This will return true upon a "hit" even if the component is not
 * visible, or if that part of the component is currently clipped by a parent
 * component.  To check if a point is contained in the visible component bounds
 * use {@link #visibleBoundsContains(int, int) }</p>
 *
 * @param x the given absolute x coordinate
 * @param y the given absolute y coordinate
 * @return true if the given absolute coordinate is contained in the
 * Component; otherwise false
 *
 * @see #visibleBoundsContains(int, int)
 */
public boolean contains(int x, int y) {
    int absX = getAbsoluteX() + getScrollX();
    int absY = getAbsoluteY() + getScrollY();
    return (x >= absX && x < absX + getWidth() && y >= absY && y < absY + getHeight());
}
Also used : Point(com.codename1.ui.geom.Point)

Example 37 with Point

use of com.codename1.charts.models.Point in project codenameone-google-maps by codenameone.

the class MapContainer method getScreenCoordinates.

/**
 * Returns the screen points for a list of coordinates.  This is likely more efficient
 * than calling {@link #getScreenCoordinate(com.codename1.maps.Coord) } for each coordinate
 * in the list because this only involves a single call to the native layer.
 * @param coords The coordinates to convert to points.
 * @return A list of points relative to (0,0) of the map container.
 */
public List<Point> getScreenCoordinates(List<Coord> coords) {
    List<Point> out = new ArrayList<Point>(coords.size());
    BoundingBox bbox = getBoundingBox();
    Mercator proj = new Mercator();
    BoundingBox projectedBox = proj.fromWGS84(bbox);
    for (Coord crd : coords) {
        Coord projectedCrd = proj.fromWGS84(crd);
        Point p;
        if (getWidth() <= 0 || getHeight() <= 0) {
            p = new Point(-100, -100);
        } else {
            // Point p = map.getScreenCoordinate(crd);
            double projectedWidth = projectedBox.longitudeDifference();
            double projectedHeight = projectedBox.latitudeDifference();
            double xCoord = (projectedCrd.getLongitude() - projectedBox.getSouthWest().getLongitude()) / projectedWidth * getWidth();
            double yCoord = (projectedBox.getNorthEast().getLatitude() - projectedCrd.getLatitude()) / projectedHeight * getHeight();
            p = new Point((int) xCoord, (int) yCoord);
        }
        out.add(p);
    }
    return out;
}
Also used : Coord(com.codename1.maps.Coord) Mercator(com.codename1.maps.Mercator) BoundingBox(com.codename1.maps.BoundingBox) ArrayList(java.util.ArrayList) Point(com.codename1.ui.geom.Point)

Example 38 with Point

use of com.codename1.charts.models.Point in project codenameone-google-maps by codenameone.

the class MapContainer method getScreenCoordinate.

/**
 * Returns the screen position for the coordinate in component relative position
 * @param lat the latitude
 * @param lon the longitude
 * @return the x/y position in component relative position
 */
public Point getScreenCoordinate(double lat, double lon) {
    if (internalNative == null) {
        if (internalLightweightCmp != null) {
            Point p = internalLightweightCmp.getPointFromCoord(new Coord(lat, lon));
            p.setX(p.getX());
            p.setY(p.getY());
            return p;
        }
        Point p = dummyMapComponent.getPointFromCoord(new Coord(lat, lon));
        p.setX(p.getX());
        p.setY(p.getY());
        return p;
    // browserBridge.waitForReady();
    // String coord = (String)browserBridge.bridge.call("getScreenCoord", new Object[]{lat, lon});
    /*
            String coord = (String)internalBrowser.executeAndWait("callback.onSuccess("+BRIDGE+".getScreenCoord(${0}, ${1}))", new Object[]{lat, lon}).toString();
            try {
                String xStr = coord.substring(0, coord.indexOf(" "));
                String yStr = coord.substring(coord.indexOf(" ")+1);
                Point out =  new Point(
                        (int)Double.parseDouble(xStr), 
                        (int)Double.parseDouble(yStr)
                );
                //out.setX(out.getX() + getAbsoluteX());
                //out.setY(out.getY() + getAbsoluteY());
                return out;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            
            return new Point(0, 0);
            */
    }
    internalNative.calcScreenPosition(lat, lon);
    return new Point(internalNative.getScreenX() + getStyle().getPaddingLeft(false), internalNative.getScreenY() + getStyle().getPaddingTop());
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point)

Example 39 with Point

use of com.codename1.charts.models.Point in project codenameone-google-maps by codenameone.

the class MapLayout method mapPositionUpdated.

@Override
public void mapPositionUpdated(Component source, int zoom, Coord center) {
    // if (true) return;
    Runnable r = new Runnable() {

        public void run() {
            inUpdate = true;
            try {
                List<Coord> coords = new ArrayList<>();
                List<Component> cmps = new ArrayList<>();
                int len = actual.getComponentCount();
                for (Component current : actual) {
                    Coord crd = (Coord) current.getClientProperty(COORD_KEY);
                    coords.add(crd);
                    cmps.add(current);
                }
                int startingUpdateCounter = ++updateCounter;
                List<Point> points = map.getScreenCoordinates(coords);
                if (startingUpdateCounter != updateCounter || len != points.size()) {
                    // in which case, that update would be more recent than this one.
                    return;
                }
                for (int i = 0; i < len; i++) {
                    Component current = cmps.get(i);
                    Point p = points.get(i);
                    current.putClientProperty(POINT_KEY, p);
                }
                if (!pressed) {
                    // If the pointer is pressed
                    // we're showing the bitmap versions of the markers anyways
                    // so we don't need to revalidate the overlay aggressively.
                    actual.setShouldCalcPreferredSize(true);
                    actual.revalidate();
                }
                if (nextUpdate != null) {
                    Runnable nex = nextUpdate;
                    nextUpdate = null;
                    callSerially(nex);
                }
            } finally {
                inUpdate = false;
            }
        }
    };
    if (inUpdate) {
        nextUpdate = r;
    } else {
        nextUpdate = null;
        callSerially(r);
    }
}
Also used : Coord(com.codename1.maps.Coord) ArrayList(java.util.ArrayList) Point(com.codename1.ui.geom.Point) Component(com.codename1.ui.Component) Point(com.codename1.ui.geom.Point)

Aggregations

Point (com.codename1.ui.geom.Point)11 Point (com.codename1.charts.models.Point)10 Coord (com.codename1.maps.Coord)9 Paint (com.codename1.charts.compat.Paint)7 Component (com.codename1.ui.Component)5 TextArea (com.codename1.ui.TextArea)3 Dimension (com.codename1.ui.geom.Dimension)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Rectangle (com.codename1.ui.geom.Rectangle)3 Border (com.codename1.ui.plaf.Border)3 ArrayList (java.util.ArrayList)3 SeriesSelection (com.codename1.charts.models.SeriesSelection)2 Container (com.codename1.ui.Container)2 EncodedImage (com.codename1.ui.EncodedImage)2 Form (com.codename1.ui.Form)2 Image (com.codename1.ui.Image)2 Label (com.codename1.ui.Label)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 Style (com.codename1.ui.plaf.Style)2