Skip to content

Instantly share code, notes, and snippets.

@ahmedengu
Last active September 11, 2016 21:17
Show Gist options
  • Save ahmedengu/c8c3f9a09f498f9b602c856f285c6515 to your computer and use it in GitHub Desktop.
Save ahmedengu/c8c3f9a09f498f9b602c856f285c6515 to your computer and use it in GitHub Desktop.
Yandex Maps Provider for codenameone // tileFor() not working correctly
import com.codename1.maps.*;
import com.codename1.maps.providers.TiledProvider;
import com.codename1.ui.geom.Dimension;
//TODO: fix tileFor()
public class YandexMapsProvider extends TiledProvider {
/**
* @return the tileSize
*/
public static int getTileSize() {
return tileSize;
}
/**
* @param aTileSize the tileSize to set
*/
public static void setTileSize(int aTileSize) {
tileSize = aTileSize;
}
private int type;
private String language = "en-US";
private static int tileSize = 450;
/**
* This is a regular road map
*/
public static final int REGULAR = 0;
/**
* This is a satellite map
*/
public static final int SATELLITE = 1;
/**
* This is a satellite + road map
*/
public static final int HYBRID = 2;
/**
* Yandex maps provider Constructor
*/
public YandexMapsProvider() {
super("https://static-maps.yandex.ru/1.x/?", new Mercator(), new Dimension(tileSize, tileSize));
}
/**
* Sets the map type
*/
public void setMapType(int type) {
this.type = type;
}
/**
* {@inheritDoc}
*/
public int maxZoomLevel() {
return 17;
}
/**
* {@inheritDoc}
*/
public String attribution() {
return "Yandex";
}
/**
* {@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("ll=");
sb.append(c.getLatitude());
sb.append(",");
sb.append(c.getLongitude());
sb.append("&z=" + _zoomLevel);
sb.append("&size=");
sb.append(tileSize);
sb.append(",");
sb.append(tileSize);
sb.append("&lang=");
sb.append(language);
if (type == REGULAR) {
sb.append("&l=map");
} else if (type == SATELLITE) {
sb.append("&l=sat");
} else if (type == HYBRID) {
sb.append("&l=sat,skl");
}
return new ProxyHttpTile(tileSize(), bbox, sb.toString());
}
/**
* Defines the language to use for display of labels on map tiles.
* Note that this parameter is only supported for some country tiles;
* if the specific language requested is not supported for the tile set,
* then the default language for that tileset will be used.
*
* Should be the form "language_region"
* language — Two-letter language code. Specified in ISO 639-1 format.
* region — Two-letter country code. Specified in ISO 3166-1 format. Determines regional settings such as measurement units.
*
* Doc: https://tech.yandex.com/maps/doc/staticapi/1.x/dg/concepts/input_params-docpage/
*
* @return the language
*/
public String getLanguage() {
return language;
}
/**
* Defines the language to use for display of labels on map tiles.
* Note that this parameter is only supported for some country tiles;
* if the specific language requested is not supported for the tile set,
* then the default language for that tileset will be used.
*
* Should be the form "language_region"
* language — Two-letter language code. Specified in ISO 639-1 format.
* region — Two-letter country code. Specified in ISO 3166-1 format. Determines regional settings such as measurement units.
*
* Doc: https://tech.yandex.com/maps/doc/staticapi/1.x/dg/concepts/input_params-docpage/
*
* @param language the language to set
*/
public void setLanguage(String language) {
this.language = language;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment