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