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());
}
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;
}
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());
}
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);
}
}
Aggregations