use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRenderer method drawObject.
void drawObject(RenderingContext rc, Canvas cv, RenderingRuleSearchRequest req, List<MapDataObjectPrimitive> array, int objOrder) {
// double polygonLimit = 100;
// float orderToSwitch = 0;
double minPolygonSize = 1. / rc.polygonMinSizeToDisplay;
for (int i = 0; i < array.size(); i++) {
rc.allObjects++;
BinaryMapDataObject mObj = array.get(i).obj;
TagValuePair pair = mObj.getMapIndex().decodeType(mObj.getTypes()[array.get(i).typeInd]);
if (array.get(i).objectType == 3) {
if (array.get(i).order > minPolygonSize + ((int) array.get(i).order)) {
continue;
}
// polygon
drawPolygon(mObj, req, cv, rc, pair, array.get(i).area);
} else if (array.get(i).objectType == 2) {
drawPolyline(mObj, req, cv, rc, pair, mObj.getSimpleLayer(), objOrder == 1);
} else if (array.get(i).objectType == 1) {
drawPoint(mObj, req, cv, rc, pair, array.get(i).typeInd == 0);
}
if (i % 25 == 0 && rc.interrupted) {
return;
}
}
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class DownloadedRegionsLayer method queryData.
private List<BinaryMapDataObject> queryData(RotatedTileBox tileBox) {
if (tileBox.getZoom() >= ZOOM_AFTER_BASEMAP) {
if (!checkIfMapEmpty(tileBox)) {
return Collections.emptyList();
}
}
LatLon lt = tileBox.getLeftTopLatLon();
LatLon rb = tileBox.getRightBottomLatLon();
// if (tileBox.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) {
// lt = rb = tileBox.getCenterLatLon();
// }
List<BinaryMapDataObject> result = null;
int left = MapUtils.get31TileNumberX(lt.getLongitude());
int right = MapUtils.get31TileNumberX(rb.getLongitude());
int top = MapUtils.get31TileNumberY(lt.getLatitude());
int bottom = MapUtils.get31TileNumberY(rb.getLatitude());
try {
result = osmandRegions.queryBbox(left, right, top, bottom);
} catch (IOException e) {
return result;
}
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (tileBox.getZoom() < ZOOM_TO_SHOW_SELECTION) {
//
} else {
if (!osmandRegions.contain(o, left / 2 + right / 2, top / 2 + bottom / 2)) {
it.remove();
}
}
}
return result;
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class DownloadedRegionsLayer method getFilter.
public String getFilter(StringBuilder btnName) {
StringBuilder filter = new StringBuilder();
int zoom = view.getZoom();
RotatedTileBox queriedBox = data.getQueriedBox();
final List<BinaryMapDataObject> currentObjects = data.results;
if (osmandRegions.isInitialized() && queriedBox != null) {
if (zoom >= ZOOM_TO_SHOW_MAP_NAMES && Math.abs(queriedBox.getZoom() - zoom) <= ZOOM_THRESHOLD && currentObjects != null) {
btnName.setLength(0);
btnName.append(view.getResources().getString(R.string.shared_string_download));
filter.setLength(0);
Set<String> set = new TreeSet<String>();
int cx = view.getCurrentRotatedTileBox().getCenter31X();
int cy = view.getCurrentRotatedTileBox().getCenter31Y();
if ((currentObjects.size() > 0)) {
for (int i = 0; i < currentObjects.size(); i++) {
final BinaryMapDataObject o = currentObjects.get(i);
if (!osmandRegions.contain(o, cx, cy)) {
continue;
}
String fullName = osmandRegions.getFullName(o);
WorldRegion rd = osmandRegions.getRegionData(fullName);
if (rd != null && rd.isRegionMapDownload() && rd.getRegionDownloadName() != null) {
String name = rd.getLocaleName();
if (checkIfObjectDownloaded(rd.getRegionDownloadName())) {
return null;
}
if (!set.add(name)) {
continue;
}
if (set.size() > 1) {
btnName.append(" ").append(view.getResources().getString(R.string.shared_string_or)).append(" ");
filter.append(", ");
} else {
btnName.append(" ");
}
filter.append(name);
btnName.append(name);
}
}
}
}
}
if (filter.length() == 0) {
return null;
}
return filter.toString();
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class DownloadedRegionsLayer method drawBorders.
private void drawBorders(Canvas canvas, RotatedTileBox tileBox, final List<BinaryMapDataObject> objects, Path path, Paint paint) {
path.reset();
for (BinaryMapDataObject o : objects) {
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
path.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
for (int j = 1; j < o.getPointsLength(); j++) {
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
path.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
}
}
canvas.drawPath(path, paint);
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class MapRenderRepositories method readRouteDataAsMapObjects.
private void readRouteDataAsMapObjects(SearchRequest<BinaryMapDataObject> sr, BinaryMapIndexReader c, final ArrayList<BinaryMapDataObject> tempResult, final TLongSet ids) {
final boolean basemap = c.isBasemap();
try {
for (RouteRegion reg : c.getRoutingIndexes()) {
List<RouteSubregion> parent = sr.getZoom() < 15 ? reg.getBaseSubregions() : reg.getSubregions();
List<RouteSubregion> searchRouteIndexTree = c.searchRouteIndexTree(sr, parent);
final MapIndex nmi = new MapIndex();
c.loadRouteIndexData(searchRouteIndexTree, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject r) {
if (basemap) {
renderedState |= 1;
} else {
renderedState |= 2;
}
if (checkForDuplicateObjectIds && !basemap) {
if (ids.contains(r.getId()) && r.getId() > 0) {
// do not add object twice
return false;
}
ids.add(r.getId());
}
int[] coordinantes = new int[r.getPointsLength() * 2];
int[] roTypes = r.getTypes();
for (int k = 0; k < roTypes.length; k++) {
int type = roTypes[k];
registerMissingType(nmi, r, type);
}
for (int k = 0; k < coordinantes.length / 2; k++) {
coordinantes[2 * k] = r.getPoint31XTile(k);
coordinantes[2 * k + 1] = r.getPoint31YTile(k);
}
BinaryMapDataObject mo = new BinaryMapDataObject(r.getId(), coordinantes, new int[0][], RenderingRulesStorage.LINE_RULES, true, roTypes, null);
TIntObjectHashMap<String> names = r.getNames();
if (names != null) {
TIntObjectIterator<String> it = names.iterator();
while (it.hasNext()) {
it.advance();
registerMissingType(nmi, r, it.key());
mo.putObjectName(it.key(), it.value());
}
}
mo.setMapIndex(nmi);
tempResult.add(mo);
return false;
}
private void registerMissingType(final MapIndex nmi, RouteDataObject r, int type) {
if (!nmi.isRegisteredRule(type)) {
RouteTypeRule rr = r.region.quickGetEncodingRule(type);
String tag = rr.getTag();
int additional = ("highway".equals(tag) || "route".equals(tag) || "railway".equals(tag) || "aeroway".equals(tag) || "aerialway".equals(tag)) ? 0 : 1;
nmi.initMapEncodingRule(additional, type, rr.getTag(), rr.getValue());
}
}
@Override
public boolean isCancelled() {
return !interrupted;
}
});
}
} catch (IOException e) {
// $NON-NLS-1$
log.debug("Search failed " + c.getRegionNames(), e);
}
}
Aggregations