use of com.codename1.ui.List 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.ui.List 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);
}
}
use of com.codename1.ui.List in project codenameone-google-maps by codenameone.
the class MapLayout method uninstallMarkers.
private void uninstallMarkers() {
actual.setVisible(true);
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
List<MapObject> toRemove = new ArrayList<MapObject>(markers);
List<Component> children = new ArrayList<Component>();
for (Component child : actual) {
children.add(child);
}
for (MapObject marker : toRemove) {
$(() -> map.removeMapObject(marker));
}
for (Component child : children) {
child.putClientProperty(MARKER_KEY, null);
}
markers.clear();
}
use of com.codename1.ui.List in project codenameone-google-maps by codenameone.
the class MapInfoPanel method show.
public void show() {
if (getParent() != null) {
return;
}
Display disp = Display.getInstance();
if (disp.isTablet()) {
if (disp.isPortrait()) {
markers.setLayout(new BoxLayout(BoxLayout.X_AXIS));
for (Component marker : markers) {
if (marker instanceof Button) {
Button btnMarker = (Button) marker;
btnMarker.setTextPosition(Label.BOTTOM);
}
}
InteractionDialog dlg = new InteractionDialog("Map Info");
dlg.setLayout(new BorderLayout());
dlg.add(BorderLayout.CENTER, this);
int dh = disp.getDisplayHeight();
int dw = disp.getDisplayWidth();
dlg.show(3 * dh / 4, 0, 0, 0);
updateMapPosition();
} else {
markers.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
for (Component marker : markers) {
if (marker instanceof Button) {
Button btnMarker = (Button) marker;
btnMarker.setTextPosition(Label.RIGHT);
}
}
InteractionDialog dlg = new InteractionDialog("Map Info");
dlg.setLayout(new BorderLayout());
dlg.add(BorderLayout.CENTER, this);
int dh = disp.getDisplayHeight();
int dw = disp.getDisplayWidth();
// makeTransparent(dlg);
dlg.getAllStyles().setBorder(Border.createEmpty());
dlg.getAllStyles().setBgColor(0x0);
dlg.getAllStyles().setBgTransparency(128);
List<Component> dialogTitle = findByUIID("DialogTitle", dlg);
for (Component c : dialogTitle) {
c.getAllStyles().setFgColor(0xffffff);
}
List<Component> tabsContainer = findByUIID("TabsContainer", dlg);
for (Component c : tabsContainer) {
c.getAllStyles().setBgColor(0xEAEAEA);
// c.getAllStyles().setBackgroundType(Style.BACKGROUND_NONE);
c.getAllStyles().setBgTransparency(255);
}
;
dlg.show(0, 0, 0, dw * 3 / 4);
updateMapPosition();
System.out.println("Making transparent");
// makeTransparent(dlg);
}
} else {
if (disp.isPortrait()) {
markers.setLayout(new BoxLayout(BoxLayout.X_AXIS));
for (Component marker : markers) {
if (marker instanceof Button) {
Button btnMarker = (Button) marker;
btnMarker.setTextPosition(Label.BOTTOM);
}
}
InteractionDialog dlg = new InteractionDialog("Map Info");
dlg.setLayout(new BorderLayout());
dlg.add(BorderLayout.CENTER, this);
int dh = disp.getDisplayHeight();
int dw = disp.getDisplayWidth();
dlg.show(dh / 2, 0, 0, 0);
updateMapPosition();
} else {
markers.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
for (Component marker : markers) {
if (marker instanceof Button) {
Button btnMarker = (Button) marker;
btnMarker.setTextPosition(Label.RIGHT);
}
}
InteractionDialog dlg = new InteractionDialog("Map Info");
dlg.setLayout(new BorderLayout());
dlg.add(BorderLayout.CENTER, this);
int dh = disp.getDisplayHeight();
int dw = disp.getDisplayWidth();
dlg.show(0, dw / 2, 0, 0);
updateMapPosition();
}
}
}
Aggregations