void AdjustTextBounds(NMapView mapView)
        {
            //  Determine the screen coordinates of the selected MapLocation
            mapView.MapProjection.ToPixels(MOverlayItem.PointInUtmk, MTempPoint);

            var title = MOverlayItem.Title;

            mTextPaint.GetTextBounds(title, 0, title.Length, MTempRect);

            //  Setup the callout with the appropriate size & location
            MTempRectF.Set(MTempRect);
            MTempRectF.Inset(-CALLOUT_TEXT_PADDING_X, -CALLOUT_TEXT_PADDING_Y);
            mOffsetX = MTempPoint.X - MTempRect.Width() / 2;
            mOffsetY = MTempPoint.Y - MTempRect.Height() - MItemBounds.Height() - CALLOUT_TEXT_PADDING_Y;
            MTempRectF.Offset(mOffsetX, mOffsetY);
        }
Example #2
0
        void AdjustTextBounds(NMapView mapView)
        {
            //  First determine the screen coordinates of the selected MapLocation
            mapView.MapProjection.ToPixels(MOverlayItem.PointInUtmk, MTempPoint);

            int mapViewWidth = mapView.MapController.ViewFrameVisibleWidth;

            if (mTitleTruncated == null || mWidthTitleTruncated != mapViewWidth)
            {
                mWidthTitleTruncated = mapViewWidth;
                float maxWidth = mWidthTitleTruncated - 2 * mMarginX - 2 * mPaddingX;
                if (DEBUG)
                {
                    Log.Info(LOG_TAG, "adjustTextBounds: maxWidth=" + maxWidth + ", mMarginX=" + mMarginX + ", mPaddingX="
                             + mPaddingX);
                }

                if (mDrawableRightButton != null)
                {
                    maxWidth -= mPaddingX + mCalloutRightButtonWidth;
                }

                if (mTailText != null)
                {
                    mTextPaint.GetTextBounds(mTailText, 0, mTailText.Length, MTempRect);
                    mTailTextWidth = MTempRect.Width();

                    maxWidth -= mTailGapX + mTailTextWidth;
                }

                var title = TextUtils.Ellipsize(MOverlayItem.Title, mTextPaint, maxWidth,
                                                TextUtils.TruncateAt.End).ToString();

                mTitleTruncated = title;

                if (DEBUG)
                {
                    Log.Info(LOG_TAG, "adjustTextBounds: mTitleTruncated=" + mTitleTruncated + ", length="
                             + mTitleTruncated.Length);
                }
            }

            mTextPaint.GetTextBounds(mTitleTruncated, 0, mTitleTruncated.Length, MTempRect);

            if (mDrawableRightButton != null)
            {
                MTempRect.Right += (int)(mPaddingX + mCalloutRightButtonWidth);
            }

            if (mTailText != null)
            {
                MTempRect.Right += (int)(mTailGapX + mTailTextWidth);
            }

            if (DEBUG)
            {
                Log.Info(LOG_TAG, "adjustTextBounds: mTempRect.width=" + MTempRect.Width() + ", mTempRect.height="
                         + MTempRect.Height());
            }

            //  Setup the callout with the right size & location
            MTempRectF.Set(MTempRect);
            var dy = (mBackgroundHeight - MTempRect.Height()) / 2;

            MTempRectF.Inset(-mPaddingX, -dy);
            //mTempRectF.inset(-mPaddingX, -mPaddingY);

            // set minimum size
            if (MTempRectF.Width() < mMinimumWidth)
            {
                var dx = (mMinimumWidth - MTempRectF.Width()) / 2;
                MTempRectF.Inset(-dx, 0);
            }

            // set position
            float left = MTempPoint.X - (int)(MTempRectF.Width() * MOverlayItem.AnchorXRatio);
            float top  = MTempPoint.Y - (int)(MItemBounds.Height() * MOverlayItem.AnchorYRatio) - mItemGapY - mTotalHeight;

            MTempRectF.Set(left, top, left + MTempRectF.Width(), top + MTempRectF.Height());
        }