use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class QuickSearchListItem method getIcon.
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
if (searchResult == null || searchResult.objectType == null) {
return null;
}
int iconId = -1;
switch(searchResult.objectType) {
case CITY:
return getIcon(app, R.drawable.ic_action_building_number);
case VILLAGE:
return getIcon(app, R.drawable.ic_action_home_dark);
case POSTCODE:
case STREET:
return getIcon(app, R.drawable.ic_action_street_name);
case HOUSE:
return getIcon(app, R.drawable.ic_action_building);
case STREET_INTERSECTION:
return getIcon(app, R.drawable.ic_action_intersection);
case POI_TYPE:
if (searchResult.object instanceof AbstractPoiType) {
String iconName = getPoiTypeIconName((AbstractPoiType) searchResult.object);
if (!Algorithms.isEmpty(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
iconId = RenderingIcons.getBigIconResourceId(res.toString());
} else {
iconId = R.drawable.mx_user_defined;
}
}
if (iconId > 0) {
return getIcon(app, iconId);
} else {
return getIcon(app, R.drawable.ic_action_search_dark);
}
case POI:
Amenity amenity = (Amenity) searchResult.object;
String id = getAmenityIconName(app, amenity);
Drawable icon = null;
if (id != null) {
iconId = RenderingIcons.getBigIconResourceId(id);
if (iconId > 0) {
icon = getIcon(app, iconId);
}
}
if (icon == null) {
return getIcon(app, R.drawable.ic_action_search_dark);
} else {
return icon;
}
case LOCATION:
return getIcon(app, R.drawable.ic_action_world_globe);
case FAVORITE:
FavouritePoint fav = (FavouritePoint) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, fav.getColor(), false);
case FAVORITE_GROUP:
FavoriteGroup group = (FavoriteGroup) searchResult.object;
int color = group.color == 0 || group.color == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.color;
return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000);
case REGION:
return getIcon(app, R.drawable.ic_world_globe_dark);
case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) searchResult.object;
if (entry.getName() != null && !Algorithms.isEmpty(entry.getName().getIconName())) {
String iconName = entry.getName().getIconName();
if (RenderingIcons.containsBigIcon(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
} else {
iconId = app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
}
}
if (iconId <= 0) {
iconId = SearchHistoryFragment.getItemIcon(entry.getName());
}
try {
return getIcon(app, iconId);
} catch (Exception e) {
return getIcon(app, SearchHistoryFragment.getItemIcon(entry.getName()));
}
case WPT:
WptPt wpt = (WptPt) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
case UNKNOWN_NAME_FILTER:
break;
}
return null;
}
use of net.osmand.data.Amenity 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.Amenity in project Osmand by osmandapp.
the class POIMapLayer method getObjectName.
@Override
public PointDescription getObjectName(Object o) {
if (o instanceof Amenity) {
Amenity a = (Amenity) o;
String preferredMapLang = app.getSettings().MAP_PREFERRED_LOCALE.get();
String preferredMapAppLang = preferredMapLang;
if (Algorithms.isEmpty(preferredMapAppLang)) {
preferredMapAppLang = app.getLanguage();
}
boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
return new PointDescription(PointDescription.POINT_TYPE_POI, a.getName(a.getType().isWiki() ? preferredMapAppLang : preferredMapLang, transliterateNames));
}
return null;
}
use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class POIMapLayer method getAmenityFromPoint.
public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List<? super Amenity> am) {
List<Amenity> objects = data.getResults();
if (objects != null) {
int ex = (int) point.x;
int ey = (int) point.y;
final int rp = getRadiusPoi(tb);
int compare = rp;
int radius = rp * 3 / 2;
try {
for (int i = 0; i < objects.size(); i++) {
Amenity n = objects.get(i);
int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
if (Math.abs(x - ex) <= compare && Math.abs(y - ey) <= compare) {
compare = radius;
am.add(n);
}
}
} catch (IndexOutOfBoundsException e) {
// that's really rare case, but is much efficient than introduce synchronized block
}
}
}
use of net.osmand.data.Amenity 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);
}
Aggregations