use of net.osmand.data.QuadTree in project Osmand by osmandapp.
the class TextRenderer method drawTextOverCanvas.
public void drawTextOverCanvas(RenderingContext rc, Canvas cv, String preferredLocale) {
int size = rc.textToDraw.size();
// 1. Sort text using text order
Collections.sort(rc.textToDraw, new Comparator<TextDrawInfo>() {
@Override
public int compare(TextDrawInfo object1, TextDrawInfo object2) {
return object1.textOrder - object2.textOrder;
}
});
QuadRect r = new QuadRect(0, 0, rc.width, rc.height);
r.inset(-100, -100);
QuadTree<TextDrawInfo> nonIntersectedBounds = new QuadTree<TextDrawInfo>(r, 4, 0.6f);
for (int i = 0; i < size; i++) {
TextDrawInfo text = rc.textToDraw.get(i);
if (text.text != null && text.text.length() > 0) {
if (preferredLocale.length() > 0) {
text.text = Junidecode.unidecode(text.text);
}
// sest text size before finding intersection (it is used there)
float textSize = text.textSize * rc.textScale;
paintText.setTextSize(textSize);
if (text.bold && text.italic) {
paintText.setTypeface(boldItalicTypeface);
} else if (text.bold) {
paintText.setTypeface(boldTypeface);
} else if (text.italic) {
paintText.setTypeface(italicTypeface);
} else {
paintText.setTypeface(defaultTypeface);
}
paintText.setFakeBoldText(text.bold);
paintText.setColor(text.textColor);
// align center y
text.centerY += (-paintText.ascent());
// calculate if there is intersection
boolean intersects = findTextIntersection(cv, rc, nonIntersectedBounds, text);
if (!intersects) {
if (text.drawOnPath != null) {
if (text.textShadow > 0) {
paintText.setColor(text.textShadowColor);
paintText.setStyle(Style.STROKE);
paintText.setStrokeWidth(2 + text.textShadow);
cv.drawTextOnPath(text.text, text.drawOnPath, 0, text.vOffset - (paintText.ascent() / 2 + paintText.descent()), paintText);
// reset
paintText.setStyle(Style.FILL);
paintText.setStrokeWidth(2);
paintText.setColor(text.textColor);
}
cv.drawTextOnPath(text.text, text.drawOnPath, 0, text.vOffset - (paintText.ascent() / 2 + paintText.descent()), paintText);
} else {
drawShieldIcon(rc, cv, text, text.shieldRes);
drawShieldIcon(rc, cv, text, text.shieldResIcon);
drawWrappedText(cv, text, textSize);
}
}
}
}
}
use of net.osmand.data.QuadTree in project Osmand by osmandapp.
the class OsmandRenderer method drawIconsOverCanvas.
private void drawIconsOverCanvas(RenderingContext rc, Canvas cv) {
// 1. Sort text using text order
Collections.sort(rc.iconsToDraw, new Comparator<IconDrawInfo>() {
@Override
public int compare(IconDrawInfo object1, IconDrawInfo object2) {
return object1.iconOrder - object2.iconOrder;
}
});
QuadRect bounds = new QuadRect(0, 0, rc.width, rc.height);
bounds.inset(-bounds.width() / 4, -bounds.height() / 4);
QuadTree<RectF> boundIntersections = new QuadTree<RectF>(bounds, 4, 0.6f);
List<RectF> result = new ArrayList<RectF>();
for (IconDrawInfo icon : rc.iconsToDraw) {
if (icon.resId != null) {
Bitmap ico = RenderingIcons.getIcon(context, icon.resId, true);
if (ico != null) {
if (icon.y >= 0 && icon.y < rc.height && icon.x >= 0 && icon.x < rc.width) {
int visbleWidth = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getWidth();
int visbleHeight = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getHeight();
boolean intersects = false;
float coeff = rc.getDensityValue(rc.screenDensityRatio * rc.textScale);
RectF rf = calculateRect(rc, icon, ico.getWidth(), ico.getHeight());
RectF visibleRect = null;
if (visbleHeight > 0 && visbleWidth > 0) {
visibleRect = calculateRect(rc, icon, visbleWidth, visbleHeight);
boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result);
for (RectF r : result) {
if (r.intersects(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)) {
intersects = true;
break;
}
}
}
if (!intersects) {
Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId, true);
if (shield != null) {
RectF shieldRf = calculateRect(rc, icon, shield.getWidth(), shield.getHeight());
if (coeff != 1f) {
Rect src = new Rect(0, 0, shield.getWidth(), shield.getHeight());
drawBitmap(cv, shield, shieldRf, src);
} else {
drawBitmap(cv, shield, shieldRf);
}
}
if (coeff != 1f) {
Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf, src);
drawBitmap(cv, ico, rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf, src);
} else {
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf);
drawBitmap(cv, ico, rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf);
}
if (visibleRect != null) {
visibleRect.inset(-visibleRect.width() / 4, -visibleRect.height() / 4);
boundIntersections.insert(visibleRect, new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom));
}
}
}
}
}
if (rc.interrupted) {
return;
}
}
}
use of net.osmand.data.QuadTree 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);
}
Aggregations