Search in sources :

Example 91 with List

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;
}
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 92 with List

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

Example 93 with List

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();
}
Also used : ArrayList(java.util.ArrayList) Component(com.codename1.ui.Component) MapObject(com.codename1.googlemaps.MapContainer.MapObject)

Example 94 with List

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();
        }
    }
}
Also used : InteractionDialog(com.codename1.components.InteractionDialog) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) BoxLayout(com.codename1.ui.layouts.BoxLayout) Component(com.codename1.ui.Component) Display(com.codename1.ui.Display)

Aggregations

Paint (com.codename1.charts.compat.Paint)26 ArrayList (java.util.ArrayList)24 Component (com.codename1.ui.Component)16 List (com.codename1.ui.List)13 Point (com.codename1.charts.models.Point)11 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 Hashtable (java.util.Hashtable)11 Container (com.codename1.ui.Container)9 ContainerList (com.codename1.ui.list.ContainerList)9 Button (com.codename1.ui.Button)8 List (java.util.List)8 TextArea (com.codename1.ui.TextArea)7 Dimension (com.codename1.ui.geom.Dimension)7 EncodedImage (com.codename1.ui.EncodedImage)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)5 ActionListener (com.codename1.ui.events.ActionListener)5 JList (javax.swing.JList)4 FileEncodedImage (com.codename1.components.FileEncodedImage)3 StorageImage (com.codename1.components.StorageImage)3