use of net.osmand.map.TileSourceManager.TileSourceTemplate in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method defineNewEditLayer.
public static void defineNewEditLayer(final Activity activity, final ResultMatcher<TileSourceTemplate> resultMatcher) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final OsmandSettings settings = app.getSettings();
final Map<String, String> entriesMap = settings.getTileSourceEntries(false);
TileSourceTemplate ts = new TileSourceTemplate("NewMapnik", "http://mapnik.osmand.net/{0}/{1}/{2}.png", "png", 17, 5, 256, 16, 32000);
final TileSourceTemplate[] result = new TileSourceTemplate[] { ts };
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
View view = activity.getLayoutInflater().inflate(R.layout.editing_tile_source, null);
final EditText name = (EditText) view.findViewById(R.id.Name);
final Spinner existing = (Spinner) view.findViewById(R.id.TileSourceSpinner);
final EditText urlToLoad = (EditText) view.findViewById(R.id.URLToLoad);
final EditText minZoom = (EditText) view.findViewById(R.id.MinZoom);
final EditText maxZoom = (EditText) view.findViewById(R.id.MaxZoom);
final EditText expire = (EditText) view.findViewById(R.id.ExpirationTime);
final CheckBox elliptic = (CheckBox) view.findViewById(R.id.EllipticMercator);
updateTileSourceEditView(ts, name, urlToLoad, minZoom, maxZoom, expire, elliptic);
final ArrayList<String> templates = new ArrayList<>(entriesMap.keySet());
templates.add(0, "");
ArrayAdapter<String> adapter = new ArrayAdapter<>(view.getContext(), android.R.layout.simple_spinner_item, templates);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
existing.setAdapter(adapter);
existing.setSelection(0);
existing.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position > 0) {
File f = ((OsmandApplication) activity.getApplication()).getAppPath(IndexConstants.TILES_INDEX_DIR + templates.get(position));
TileSourceTemplate template = TileSourceManager.createTileSourceTemplate(f);
if (template != null) {
result[0] = template.copy();
updateTileSourceEditView(result[0], name, urlToLoad, minZoom, maxZoom, expire, elliptic);
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
bld.setView(view);
bld.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TileSourceTemplate r = result[0];
try {
r.setName(name.getText().toString());
r.setExpirationTimeMinutes(expire.getText().length() == 0 ? -1 : Integer.parseInt(expire.getText().toString()));
r.setMinZoom(Integer.parseInt(minZoom.getText().toString()));
r.setMaxZoom(Integer.parseInt(maxZoom.getText().toString()));
r.setEllipticYTile(elliptic.isChecked());
r.setUrlToLoad(urlToLoad.getText().toString().equals("") ? null : urlToLoad.getText().toString().replace("{$x}", "{1}").replace("{$y}", "{2}").replace("{$z}", "{0}"));
if (r.getName().length() > 0) {
if (settings.installTileSource(r)) {
Toast.makeText(activity, activity.getString(R.string.edit_tilesource_successfully, r.getName()), Toast.LENGTH_SHORT).show();
resultMatcher.publish(r);
}
}
} catch (RuntimeException e) {
Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.show();
}
use of net.osmand.map.TileSourceManager.TileSourceTemplate in project Osmand by osmandapp.
the class HillshadeLayer method createTileSource.
private SQLiteTileSource createTileSource(MapActivity activity) {
return new SQLiteTileSource(activity.getMyApplication(), null, new ArrayList<TileSourceTemplate>()) {
@Override
protected SQLiteConnection getDatabase() {
throw new UnsupportedOperationException();
}
public boolean isLocked() {
return false;
}
List<String> getTileSource(int x, int y, int zoom) {
ArrayList<String> ls = new ArrayList<String>();
int z = (zoom - ZOOM_BOUNDARY);
if (z > 0) {
indexedResources.queryInBox(new QuadRect(x >> z, y >> z, (x >> z), (y >> z)), ls);
} else {
indexedResources.queryInBox(new QuadRect(x << -z, y << -z, (x + 1) << -z, (y + 1) << -z), ls);
}
return ls;
}
@Override
public boolean exists(int x, int y, int zoom) {
List<String> ts = getTileSource(x, y, zoom);
for (String t : ts) {
SQLiteTileSource sqLiteTileSource = resources.get(t);
if (sqLiteTileSource != null && sqLiteTileSource.exists(x, y, zoom)) {
return true;
}
}
return false;
}
@Override
public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) {
List<String> ts = getTileSource(x, y, zoom);
for (String t : ts) {
SQLiteTileSource sqLiteTileSource = resources.get(t);
if (sqLiteTileSource != null) {
Bitmap bmp = sqLiteTileSource.getImage(x, y, zoom, timeHolder);
if (bmp != null) {
return sqLiteTileSource.getImage(x, y, zoom, timeHolder);
}
}
}
return null;
}
@Override
public int getBitDensity() {
return 32;
}
@Override
public int getMinimumZoomSupported() {
return 5;
}
@Override
public int getMaximumZoomSupported() {
return 11;
}
@Override
public int getTileSize() {
return 256;
}
@Override
public boolean couldBeDownloadedFromInternet() {
return false;
}
@Override
public String getName() {
return "Hillshade";
}
@Override
public String getTileFormat() {
return "jpg";
}
};
}
use of net.osmand.map.TileSourceManager.TileSourceTemplate in project Osmand by osmandapp.
the class OsmandSettings method getTileSourceByName.
public ITileSource getTileSourceByName(String tileName, boolean warnWhenSelected) {
if (tileName == null || tileName.length() == 0) {
return null;
}
List<TileSourceTemplate> knownTemplates = TileSourceManager.getKnownSourceTemplates();
File tPath = ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, tileName);
if (!dir.exists()) {
return checkAmongAvailableTileSources(dir, knownTemplates);
} else if (tileName.endsWith(IndexConstants.SQLITE_EXT)) {
return new SQLiteTileSource(ctx, dir, knownTemplates);
} else if (dir.isDirectory() && !dir.getName().startsWith(".")) {
TileSourceTemplate t = TileSourceManager.createTileSourceTemplate(dir);
if (warnWhenSelected && !t.isRuleAcceptable()) {
ctx.showToastMessage(R.string.warning_tile_layer_not_downloadable, dir.getName());
}
if (!TileSourceManager.isTileSourceMetaInfoExist(dir)) {
TileSourceTemplate ret = checkAmongAvailableTileSources(dir, knownTemplates);
if (ret != null) {
t = ret;
}
}
return t;
}
return null;
}
use of net.osmand.map.TileSourceManager.TileSourceTemplate in project Osmand by osmandapp.
the class OsmandSettings method checkAmongAvailableTileSources.
private TileSourceTemplate checkAmongAvailableTileSources(File dir, List<TileSourceTemplate> list) {
if (list != null) {
for (TileSourceTemplate l : list) {
if (dir.getName().equals(l.getName())) {
try {
dir.mkdirs();
TileSourceManager.createMetaInfoFile(dir, l, true);
} catch (IOException e) {
}
return l;
}
}
}
return null;
}
use of net.osmand.map.TileSourceManager.TileSourceTemplate in project Osmand by osmandapp.
the class YandexTrafficAdapter method updateTimeStampImpl.
protected void updateTimeStampImpl() {
String YANDEX_BASE_URL;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
YANDEX_BASE_URL = "https://jgo.maps.yandex.net";
else
YANDEX_BASE_URL = "http://jgo.maps.yandex.net";
if (mTimestamp == null || (System.currentTimeMillis() - lastTimestampUpdated) > DELTA) {
// $NON-NLS-1$
log.info("Updating timestamp");
try {
URLConnection connection = NetworkUtils.getHttpURLConnection(YANDEX_BASE_URL + "/trf/stat.js");
// $NON-NLS-1$
BufferedInputStream in = new BufferedInputStream(connection.getInputStream(), 1024);
ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
BufferedOutputStream out = new BufferedOutputStream(dataStream, 1024);
Algorithms.streamCopy(in, out);
out.flush();
String str = dataStream.toString();
// JSONObject json = new JSONObject(str.replace("YMaps.TrafficLoader.onLoad(\"stat\",", "").replace("});", "}"));
// $NON-NLS-1$
int start = str.indexOf("timestamp:");
// $NON-NLS-1$
start = str.indexOf('\"', start) + 1;
// $NON-NLS-1$
int end = str.indexOf('\"', start);
// exception case
if (start < 0 || end < 0) {
// $NON-NLS-1$
log.info("Timestamp wasn't updated " + str);
return;
}
String newTimestamp = str.substring(start, end);
lastTimestampUpdated = System.currentTimeMillis();
Algorithms.closeStream(in);
Algorithms.closeStream(out);
// $NON-NLS-1$
log.info("Timestamp updated to " + newTimestamp);
if (!newTimestamp.equals(mTimestamp)) {
mTimestamp = newTimestamp;
TileSourceTemplate template = new TileSourceTemplate(YANDEX_PREFFIX + mTimestamp, YANDEX_BASE_URL + "/1.1/tiles?l=trf,trfe&x={1}&y={2}&z={0}&tm=" + mTimestamp, ".png", 17, 7, 256, 8, 18000);
template.setEllipticYTile(true);
template.setExpirationTimeMinutes(20);
clearCache();
this.layer.setMapForMapTileAdapter(template, this);
}
} catch (IOException e) {
log.info("Exception while updating yandex traffic template", e);
}
}
}
Aggregations