use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class OsmandMapLayer method initBoundIntersections.
@NonNull
public QuadTree<QuadRect> initBoundIntersections(RotatedTileBox tileBox) {
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
bounds.inset(-bounds.width() / 4, -bounds.height() / 4);
return new QuadTree<>(bounds, 4, 0.6f);
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class OsmandMapLayer method findAmenity.
public Amenity findAmenity(OsmandApplication app, long id, List<String> names, LatLon latLon, int radius) {
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius);
List<Amenity> amenities = app.getResourceManager().searchAmenities(new BinaryMapIndexReader.SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
return true;
}
@Override
public boolean isEmpty() {
return false;
}
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
Amenity res = null;
for (Amenity amenity : amenities) {
Long amenityId = amenity.getId() >> 1;
if (amenityId == id) {
res = amenity;
break;
}
}
if (res == null && names != null && names.size() > 0) {
for (Amenity amenity : amenities) {
for (String name : names) {
if (name.equals(amenity.getName())) {
res = amenity;
break;
}
}
if (res != null) {
break;
}
}
}
return res;
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class POIMapLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
Set<PoiUIFilter> selectedPoiFilters = app.getPoiFilters().getSelectedPoiFilters();
if (!this.filters.equals(selectedPoiFilters)) {
this.filters = new TreeSet<>(selectedPoiFilters);
data.clearCache();
}
List<Amenity> objects = Collections.emptyList();
List<Amenity> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
if (!filters.isEmpty()) {
if (tileBox.getZoom() >= startZoom) {
data.queryNewData(tileBox);
objects = data.getResults();
if (objects != null) {
float iconSize = poiBackground.getWidth() * 3 / 2;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
for (Amenity o : objects) {
float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()));
}
}
for (Amenity o : fullObjects) {
int x = (int) tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
canvas.drawBitmap(poiBackground, x - poiBackground.getWidth() / 2, y - poiBackground.getHeight() / 2, paintIconBackground);
String id = null;
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
if (st != null) {
if (RenderingIcons.containsSmallIcon(st.getIconKeyName())) {
id = st.getIconKeyName();
} else if (RenderingIcons.containsSmallIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
id = st.getOsmTag() + "_" + st.getOsmValue();
}
}
if (id != null) {
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false);
if (bmp != null) {
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
}
}
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
}
mapTextLayer.putData(this, objects);
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class QuickSearchHelper method findAmenity.
public Amenity findAmenity(String name, double lat, double lon, String lang, boolean transliterate) {
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
List<Amenity> amenities = app.getResourceManager().searchAmenities(new SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
return true;
}
@Override
public boolean isEmpty() {
return false;
}
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
MapPoiTypes types = app.getPoiTypes();
for (Amenity amenity : amenities) {
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate);
if (poiSimpleFormat.equals(name)) {
return amenity;
}
}
for (Amenity amenity : amenities) {
String amenityName = amenity.getName(lang, transliterate);
if (Algorithms.isEmpty(amenityName)) {
AbstractPoiType st = types.getAnyPoiTypeByKey(amenity.getSubType());
if (st != null) {
amenityName = st.getTranslation();
} else {
amenityName = amenity.getSubType();
}
}
if (name.contains(amenityName)) {
return amenity;
}
}
return null;
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class HillshadeLayer method indexHillshadeFiles.
private void indexHillshadeFiles(final OsmandApplication app) {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
private SQLiteDatabase sqliteDb;
@Override
protected Void doInBackground(Void... params) {
File tilesDir = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File cacheDir = app.getCacheDir();
// fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs
sqliteDb = SQLiteDatabase.openDatabase(new File(cacheDir, HILLSHADE_CACHE).getPath(), null, SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING | SQLiteDatabase.CREATE_IF_NECESSARY);
if (sqliteDb.getVersion() == 0) {
sqliteDb.setVersion(1);
sqliteDb.execSQL("CREATE TABLE TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)");
}
Map<String, Long> fileModified = new HashMap<String, Long>();
Map<String, SQLiteTileSource> rs = readFiles(app, tilesDir, fileModified);
indexCachedResources(fileModified, rs);
indexNonCachedResources(fileModified, rs);
sqliteDb.close();
resources = rs;
return null;
}
@Override
protected void onPostExecute(Void result) {
app.getResourceManager().reloadTilesFromFS();
}
private void indexNonCachedResources(Map<String, Long> fileModified, Map<String, SQLiteTileSource> rs) {
for (String filename : fileModified.keySet()) {
try {
log.info("Indexing hillshade file " + filename);
ContentValues cv = new ContentValues();
cv.put("filename", filename);
cv.put("date_modified", fileModified.get(filename));
SQLiteTileSource ts = rs.get(filename);
QuadRect rt = ts.getRectBoundary(ZOOM_BOUNDARY, 1);
if (rt != null) {
indexedResources.insert(filename, rt);
cv.put("left", (int) rt.left);
cv.put("right", (int) rt.right);
cv.put("top", (int) rt.top);
cv.put("bottom", (int) rt.bottom);
sqliteDb.insert("TILE_SOURCES", null, cv);
}
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
}
}
}
private void indexCachedResources(Map<String, Long> fileModified, Map<String, SQLiteTileSource> rs) {
Cursor cursor = sqliteDb.rawQuery("SELECT filename, date_modified, left, right, top, bottom FROM TILE_SOURCES", new String[0]);
if (cursor.moveToFirst()) {
do {
String filename = cursor.getString(0);
long lastModified = cursor.getLong(1);
Long read = fileModified.get(filename);
if (rs.containsKey(filename) && read != null && lastModified == read) {
int left = cursor.getInt(2);
int right = cursor.getInt(3);
int top = cursor.getInt(4);
float bottom = cursor.getInt(5);
indexedResources.insert(filename, new QuadRect(left, top, right, bottom));
fileModified.remove(filename);
}
} while (cursor.moveToNext());
}
cursor.close();
}
private Map<String, SQLiteTileSource> readFiles(final OsmandApplication app, File tilesDir, Map<String, Long> fileModified) {
Map<String, SQLiteTileSource> rs = new LinkedHashMap<String, SQLiteTileSource>();
File[] files = tilesDir.listFiles();
if (files != null) {
for (File f : files) {
if (f != null && f.getName().endsWith(IndexConstants.SQLITE_EXT) && f.getName().toLowerCase().startsWith("hillshade")) {
SQLiteTileSource ts = new SQLiteTileSource(app, f, new ArrayList<TileSourceTemplate>());
rs.put(f.getName(), ts);
fileModified.put(f.getName(), f.lastModified());
}
}
}
return rs;
}
};
executeTaskInBackground(task);
}
Aggregations