Search in sources :

Example 11 with Coord

use of com.codename1.maps.Coord in project CodenameOne by codenameone.

the class TiledProvider method scale.

/**
 * Scale to the zoom level
 * @param zoomLevel to scale to
 *
 * @return a scaled coordinate.
 */
public Coord scale(int zoomLevel) {
    int divider = (1 << zoomLevel);
    double longitude = (1.0 * projection().extent().longitudeDifference()) / divider / tileSize().getWidth();
    double latitude = (1.0 * projection().extent().latitudeDifference()) / divider / tileSize().getHeight();
    return new Coord(latitude, longitude, false);
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point)

Example 12 with Coord

use of com.codename1.maps.Coord in project CodenameOne by codenameone.

the class GoogleMapsProvider method tileFor.

/**
 * {@inheritDoc}
 */
public Tile tileFor(BoundingBox bbox) {
    StringBuilder sb = new StringBuilder(_url);
    Coord ne = bbox.getNorthEast();
    Coord c = projection().toWGS84(new Coord(ne.getLatitude() - bbox.latitudeDifference() / 2, ne.getLongitude() - bbox.longitudeDifference() / 2, true));
    sb.append("center=");
    sb.append(c.getLatitude());
    sb.append(",");
    sb.append(c.getLongitude());
    sb.append("&format=png");
    sb.append("&zoom=" + _zoomLevel);
    sb.append("&size=");
    sb.append(tileSize);
    sb.append("x");
    sb.append(tileSize);
    sb.append("&sensor=");
    sb.append(sensor);
    if (language != null) {
        sb.append("&language=");
        sb.append(language);
    }
    if (type == SATELLITE) {
        sb.append("&maptype=satellite");
    } else if (type == HYBRID) {
        sb.append("&maptype=hybrid");
    }
    sb.append("&key=" + apiKey);
    return new ProxyHttpTile(tileSize(), bbox, sb.toString());
}
Also used : Coord(com.codename1.maps.Coord) ProxyHttpTile(com.codename1.maps.ProxyHttpTile)

Example 13 with Coord

use of com.codename1.maps.Coord in project CodenameOne by codenameone.

the class LayerWithZoomLevels method keyPressed.

/**
 * {@inheritDoc}
 */
public void keyPressed(int keyCode) {
    int oldZoom = _zoom;
    Coord oldCenter = _center;
    if (isLeftKey(keyCode)) {
        moveLeft();
    } else if (isRightKey(keyCode)) {
        moveRight();
    } else if (isDownKey(keyCode)) {
        moveDown();
    } else if (isUpKey(keyCode)) {
        moveUp();
    }
    if (!_map.projection().extent().contains(_center)) {
        _center = oldCenter;
    }
    if (isZoomInKey(keyCode)) {
        zoomIn();
    }
    if (isZoomOutKey(keyCode)) {
        zoomOut();
    }
    if (isZoomToLayersKey(keyCode)) {
        zoomToLayers();
    }
    super.keyPressed(keyCode);
    if (_center != oldCenter || _zoom != oldZoom) {
        _needTiles = true;
    }
    super.repaint();
    fireMapListenerEvent();
}
Also used : Point(com.codename1.ui.geom.Point)

Example 14 with Coord

use of com.codename1.maps.Coord in project CodenameOne by codenameone.

the class LayerWithZoomLevels method getTiles.

private void getTiles() throws RuntimeException {
    _tiles = new Vector();
    Dimension tileSize = _map.tileSize();
    int posY = 0;
    _delta = null;
    while (posY - tileSize.getHeight() < getHeight()) {
        int posX = 0;
        while (posX - tileSize.getWidth() < getWidth()) {
            Tile tile;
            Coord cur = _map.translate(_center, _zoom, posX - getWidth() / 2, getHeight() / 2 - posY);
            if (_map.projection().extent().contains(cur)) {
                tile = _map.tileFor(_map.bboxFor(cur, _zoom));
                if (_delta == null) {
                    _delta = tile.pointPosition(cur);
                }
                tile.setsTileReadyListener(new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        refreshLayers = true;
                        repaint();
                    }
                });
                _tiles.addElement(new PositionedTile(new Point(posX, posY), tile));
            }
            posX += tileSize.getWidth();
        }
        posY += tileSize.getHeight();
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Dimension(com.codename1.ui.geom.Dimension) Point(com.codename1.ui.geom.Point) Vector(java.util.Vector) Point(com.codename1.ui.geom.Point)

Example 15 with Coord

use of com.codename1.maps.Coord in project CodenameOne by codenameone.

the class LayerWithZoomLevels method screenTile.

/**
 * {@inheritDoc}
 */
private Tile screenTile() {
    Dimension componentDimension = new Dimension(getWidth(), getHeight());
    Coord southWest = _map.translate(_center, _zoom, -getWidth() / 2, -getHeight() / 2);
    Coord northEast = _map.translate(_center, _zoom, getWidth() / 2, getHeight() / 2);
    BoundingBox bbox = new BoundingBox(southWest, northEast);
    return new Tile(componentDimension, bbox, null);
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Coord (com.codename1.maps.Coord)19 Point (com.codename1.ui.geom.Point)14 BoundingBox (com.codename1.maps.BoundingBox)7 Component (com.codename1.ui.Component)3 EncodedImage (com.codename1.ui.EncodedImage)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 ActionListener (com.codename1.ui.events.ActionListener)3 Dimension (com.codename1.ui.geom.Dimension)3 MapObject (com.codename1.googlemaps.MapContainer.MapObject)2 Mercator (com.codename1.maps.Mercator)2 PointsLayer (com.codename1.maps.layers.PointsLayer)2 Button (com.codename1.ui.Button)2 Image (com.codename1.ui.Image)2 ArrayList (java.util.ArrayList)2 FloatingActionButton (com.codename1.components.FloatingActionButton)1 InteractionDialog (com.codename1.components.InteractionDialog)1 ToastBar (com.codename1.components.ToastBar)1 MapContainer (com.codename1.googlemaps.MapContainer)1 MarkerOptions (com.codename1.googlemaps.MapContainer.MarkerOptions)1 Util (com.codename1.io.Util)1