Search in sources :

Example 46 with QuadRect

use of net.osmand.data.QuadRect 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);
                }
            }
        }
    }
}
Also used : QuadTree(net.osmand.data.QuadTree) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint)

Example 47 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class TextRenderer method findTextIntersection.

private boolean findTextIntersection(Canvas cv, RenderingContext rc, QuadTree<TextDrawInfo> boundIntersections, TextDrawInfo text) {
    // for test purposes
    // drawTestBox(cv, text.bounds, text.pathRotate, text.text);
    boundIntersections.queryInBox(text.bounds, tempSearch);
    for (int i = 0; i < tempSearch.size(); i++) {
        TextDrawInfo t = tempSearch.get(i);
        if (intersects(text.bounds, text.pathRotate, t.bounds, t.pathRotate)) {
            return true;
        }
    }
    if (text.minDistance > 0) {
        QuadRect boundsSearch = new QuadRect(text.bounds);
        boundsSearch.inset(-Math.max(rc.getDensityValue(5.0f), text.minDistance), -rc.getDensityValue(15));
        boundIntersections.queryInBox(boundsSearch, tempSearch);
        // drawTestBox(cv, &boundsSearch, text.pathRotate, paintIcon, text.text, NULL/*paintText*/);
        for (int i = 0; i < tempSearch.size(); i++) {
            TextDrawInfo t = tempSearch.get(i);
            if (t.minDistance > 0 && t.text.equals(text.text) && intersects(boundsSearch, text.pathRotate, t.bounds, t.pathRotate)) {
                return true;
            }
        }
    }
    boundIntersections.insert(text, text.bounds);
    return false;
}
Also used : QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint)

Example 48 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class RegionAddressRepositoryBinary method getClosestCity.

public City getClosestCity(LatLon l, List<City> cache) {
    City closest = null;
    if (l != null) {
        int y31 = MapUtils.get31TileNumberY(l.getLatitude());
        int x31 = MapUtils.get31TileNumberX(l.getLongitude());
        int dz = (31 - ZOOM_QTREE);
        if (cache == null) {
            cache = new ArrayList<City>();
        }
        cache.clear();
        citiesQtree.queryInBox(new QuadRect((x31 >> dz) - 1, (y31 >> dz) - 1, (x31 >> dz) + 1, (y31 >> dz) + 1), cache);
        int min = -1;
        for (City c : cache) {
            double d = MapUtils.getDistance(l, c.getLocation());
            if (min == -1 || d < min) {
                min = (int) d;
                closest = c;
            }
        }
    }
    return closest;
}
Also used : City(net.osmand.data.City) QuadRect(net.osmand.data.QuadRect)

Example 49 with QuadRect

use of net.osmand.data.QuadRect 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;
        }
    }
}
Also used : QuadTree(net.osmand.data.QuadTree) Rect(android.graphics.Rect) QuadRect(net.osmand.data.QuadRect) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap)

Example 50 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class MenuBuilder method processNearstWiki.

protected boolean processNearstWiki() {
    if (showNearestWiki && latLon != null) {
        QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250);
        nearestWiki = app.getResourceManager().searchAmenities(new BinaryMapIndexReader.SearchPoiTypeFilter() {

            @Override
            public boolean accept(PoiCategory type, String subcategory) {
                return type.isWiki();
            }

            @Override
            public boolean isEmpty() {
                return false;
            }
        }, rect.top, rect.left, rect.bottom, rect.right, -1, null);
        Collections.sort(nearestWiki, new Comparator<Amenity>() {

            @Override
            public int compare(Amenity o1, Amenity o2) {
                double d1 = MapUtils.getDistance(latLon, o1.getLocation());
                double d2 = MapUtils.getDistance(latLon, o2.getLocation());
                return Double.compare(d1, d2);
            }
        });
        Long id = objectId;
        if (id != 0) {
            for (Amenity wiki : nearestWiki) {
                if (wiki.getId().equals(id)) {
                    nearestWiki.remove(wiki);
                    break;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Amenity(net.osmand.data.Amenity) PoiCategory(net.osmand.osm.PoiCategory) QuadRect(net.osmand.data.QuadRect)

Aggregations

QuadRect (net.osmand.data.QuadRect)60 Paint (android.graphics.Paint)19 ArrayList (java.util.ArrayList)19 LatLon (net.osmand.data.LatLon)13 Bitmap (android.graphics.Bitmap)8 RotatedTileBox (net.osmand.data.RotatedTileBox)8 WptPt (net.osmand.plus.GPXUtilities.WptPt)8 TIntArrayList (gnu.trove.list.array.TIntArrayList)7 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)6 Amenity (net.osmand.data.Amenity)5 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 Point (com.vividsolutions.jts.geom.Point)4 List (java.util.List)4 QuadPointDouble (net.osmand.data.QuadPointDouble)4 TransportStop (net.osmand.data.TransportStop)4 PoiCategory (net.osmand.osm.PoiCategory)4 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 Rect (android.graphics.Rect)3 RectF (android.graphics.RectF)3 File (java.io.File)3