Пример #1
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            long tileLeft   = MercatorProjection.LongitudeToTileX(boundingBox.MinLongitude, zoomLevel);
            long tileTop    = MercatorProjection.LatitudeToTileY(boundingBox.MaxLatitude, zoomLevel);
            long tileRight  = MercatorProjection.LongitudeToTileX(boundingBox.MaxLongitude, zoomLevel);
            long tileBottom = MercatorProjection.LatitudeToTileY(boundingBox.MinLatitude, zoomLevel);

            int tileSize = this.displayModel.TileSize;
            int pixelX1  = (int)(MercatorProjection.TileToPixel(tileLeft, tileSize) - topLeftPoint.X);
            int pixelY1  = (int)(MercatorProjection.TileToPixel(tileTop, tileSize) - topLeftPoint.Y);
            int pixelX2  = (int)(MercatorProjection.TileToPixel(tileRight, tileSize) - topLeftPoint.X + tileSize);
            int pixelY2  = (int)(MercatorProjection.TileToPixel(tileBottom, tileSize) - topLeftPoint.Y + tileSize);

            for (int lineX = pixelX1; lineX <= pixelX2 + 1; lineX += tileSize)
            {
                canvas.DrawLine(lineX, pixelY1, lineX, pixelY2, this.paintBack);
            }

            for (int lineY = pixelY1; lineY <= pixelY2 + 1; lineY += tileSize)
            {
                canvas.DrawLine(pixelX1, lineY, pixelX2, lineY, this.paintBack);
            }

            for (int lineX = pixelX1; lineX <= pixelX2 + 1; lineX += tileSize)
            {
                canvas.DrawLine(lineX, pixelY1, lineX, pixelY2, this.paintFront);
            }

            for (int lineY = pixelY1; lineY <= pixelY2 + 1; lineY += tileSize)
            {
                canvas.DrawLine(pixelX1, lineY, pixelX2, lineY, this.paintFront);
            }
        }
Пример #2
0
        protected internal override void Redraw(ICanvas canvas)
        {
            canvas.FillColor(Color.TRANSPARENT);

            float scale = this.displayModel.ScaleFactor;
            ScaleBarLengthAndValue lengthAndValue = this.CalculateScaleBarLengthAndValue();
            ScaleBarLengthAndValue lengthAndValue2;

            if (this.scaleBarMode == ScaleBarMode.BOTH)
            {
                lengthAndValue2 = this.CalculateScaleBarLengthAndValue(this.secondaryDistanceUnitAdapter);
            }
            else
            {
                lengthAndValue2 = new ScaleBarLengthAndValue(0, 0);
            }

            DrawScaleBar(canvas, lengthAndValue.scaleBarLength, lengthAndValue2.scaleBarLength, this.paintScaleBarStroke, scale);
            DrawScaleBar(canvas, lengthAndValue.scaleBarLength, lengthAndValue2.scaleBarLength, this.paintScaleBar, scale);

            string scaleText1 = this.distanceUnitAdapter.GetScaleText(lengthAndValue.scaleBarValue);
            string scaleText2 = this.scaleBarMode == ScaleBarMode.BOTH ? this.secondaryDistanceUnitAdapter.GetScaleText(lengthAndValue2.scaleBarValue) : "";

            DrawScaleText(canvas, scaleText1, scaleText2, this.paintScaleTextStroke, scale);
            DrawScaleText(canvas, scaleText1, scaleText2, this.paintScaleText, scale);
        }
Пример #3
0
        private void DrawTileCoordinates(TilePosition tilePosition, ICanvas canvas)
        {
            int  x    = (int)(tilePosition.Point.X + 8 * displayModel.ScaleFactor);
            int  y    = (int)(tilePosition.Point.Y + 24 * displayModel.ScaleFactor);
            Tile tile = tilePosition.Tile;

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("X: ");
            stringBuilder.Append(tile.TileX);
            string text = stringBuilder.ToString();

            canvas.DrawText(text, x, y, this.paintBack);
            canvas.DrawText(text, x, y, this.paintFront);

            stringBuilder.Length = 0;
            stringBuilder.Append("Y: ");
            stringBuilder.Append(tile.TileY);
            text = stringBuilder.ToString();
            canvas.DrawText(text, x, (int)(y + 24 * displayModel.ScaleFactor), this.paintBack);
            canvas.DrawText(text, x, (int)(y + 24 * displayModel.ScaleFactor), this.paintFront);

            stringBuilder.Length = 0;
            stringBuilder.Append("Z: ");
            stringBuilder.Append(tile.ZoomLevel);
            text = stringBuilder.ToString();
            canvas.DrawText(text, x, (int)(y + 48 * displayModel.ScaleFactor), this.paintBack);
            canvas.DrawText(text, x, (int)(y + 48 * displayModel.ScaleFactor), this.paintFront);
        }
Пример #4
0
        private void DrawParentTileBitmap(ICanvas canvas, Point point, Tile tile)
        {
            Tile cachedParentTile = GetCachedParentTile(tile, 4);

            if (cachedParentTile != null)
            {
                IBitmap bitmap = this.tileCache.GetImmediately(CreateJob(cachedParentTile));
                if (bitmap != null)
                {
                    int   tileSize      = this.displayModel.TileSize;
                    long  translateX    = tile.GetShiftX(cachedParentTile) * tileSize;
                    long  translateY    = tile.GetShiftY(cachedParentTile) * tileSize;
                    sbyte zoomLevelDiff = (sbyte)(tile.ZoomLevel - cachedParentTile.ZoomLevel);
                    float scaleFactor   = (float)Math.Pow(2, zoomLevelDiff);

                    int x = (int)Math.Round(point.X);
                    int y = (int)Math.Round(point.Y);

                    this.matrix.Reset();
                    this.matrix.Translate(x - translateX, y - translateY);
                    this.matrix.Scale(scaleFactor, scaleFactor);

                    canvas.SetClip(x, y, this.displayModel.TileSize, this.displayModel.TileSize);
                    canvas.DrawBitmap(bitmap, this.matrix);
                    canvas.ResetClip();
                    bitmap.DecrementRefCount();
                }
            }
        }
Пример #5
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            lock (this)
            {
                if (this.latLong == null || this.bitmap == null)
                {
                    return;
                }

                long   mapSize = MercatorProjection.GetMapSize(zoomLevel, this.displayModel.TileSize);
                double pixelX  = MercatorProjection.LongitudeToPixelX(this.latLong.Longitude, mapSize);
                double pixelY  = MercatorProjection.LatitudeToPixelY(this.latLong.Latitude, mapSize);

                int halfBitmapWidth  = this.bitmap.Width / 2;
                int halfBitmapHeight = this.bitmap.Height / 2;

                int left   = (int)(pixelX - topLeftPoint.X - halfBitmapWidth + this.horizontalOffset);
                int top    = (int)(pixelY - topLeftPoint.Y - halfBitmapHeight + this.verticalOffset);
                int right  = left + this.bitmap.Width;
                int bottom = top + this.bitmap.Height;

                Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
                Rectangle canvasRectangle = new Rectangle(0, 0, canvas.Width, canvas.Height);
                if (!canvasRectangle.Intersects(bitmapRectangle))
                {
                    return;
                }

                canvas.DrawBitmap(this.bitmap, left, top);
            }
        }
Пример #6
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            IList <TilePosition> tilePositions = LayerUtil.GetTilePositions(boundingBox, zoomLevel, topLeftPoint, this.displayModel.TileSize);

            // In a rotation situation it is possible that drawParentTileBitmap sets the
            // clipping bounds to portrait, while the device is just being rotated into
            // landscape: the result is a partially painted screen that only goes away
            // after zooming (which has the effect of resetting the clip bounds if drawParentTileBitmap
            // is called again).
            // Always resetting the clip bounds here seems to avoid the problem,
            // I assume that this is a pretty cheap operation, otherwise it would be better
            // to hook this into the onConfigurationChanged call chain.
            canvas.ResetClip();

            if (!isTransparent)
            {
                canvas.FillColor(this.displayModel.BackgroundColor);
            }

            ISet <Job> jobs = new HashSet <Job>();

            foreach (TilePosition tilePosition in tilePositions)
            {
                jobs.Add(CreateJob(tilePosition.Tile));
            }
            this.tileCache.WorkingSet = jobs;

            for (int i = tilePositions.Count - 1; i >= 0; --i)
            {
                TilePosition tilePosition = tilePositions[i];
                Point        point        = tilePosition.Point;
                Tile         tile         = tilePosition.Tile;
                T            job          = CreateJob(tile);
                ITileBitmap  bitmap       = this.tileCache.GetImmediately(job);

                if (bitmap == null)
                {
                    if (this.hasJobQueue && !this.tileCache.ContainsKey(job))
                    {
                        this.jobQueue.Add(job);
                    }
                    DrawParentTileBitmap(canvas, point, tile);
                }
                else
                {
                    if (IsTileStale(tile, bitmap) && this.hasJobQueue && !this.tileCache.ContainsKey(job))
                    {
                        this.jobQueue.Add(job);
                    }
                    RetrieveLabelsOnly(job);
                    canvas.DrawBitmap(bitmap, (int)Math.Round(point.X), (int)Math.Round(point.Y));
                    bitmap.DecrementRefCount();
                }
            }
            if (this.hasJobQueue)
            {
                this.jobQueue.NotifyWorkers();
            }
        }
Пример #7
0
        public LayerManager(MapView mapView, MapViewPosition mapViewPosition, IGraphicFactory graphicFactory) : base()
        {
            this.mapView         = mapView;
            this.mapViewPosition = mapViewPosition;

            this.drawingCanvas = graphicFactory.CreateCanvas();
            this.layers        = new Layers(this, mapView.Model.displayModel);
        }
Пример #8
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            IList <TilePosition> tilePositions = LayerUtil.GetTilePositions(boundingBox, zoomLevel, topLeftPoint, this.displayModel.TileSize);

            for (int i = tilePositions.Count - 1; i >= 0; --i)
            {
                DrawTileCoordinates(tilePositions[i], canvas);
            }
        }
Пример #9
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            if (zoomLevel < this.tileSource.ZoomLevelMin || zoomLevel > this.tileSource.ZoomLevelMax)
            {
                return;
            }

            base.Draw(boundingBox, zoomLevel, canvas, topLeftPoint);
        }
Пример #10
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            lock (this)
            {
                if (this.latLongs.Count < 2 || (this.paintStroke == null && this.paintFill == null))
                {
                    return;
                }

                IEnumerator <LatLong> iterator = this.latLongs.GetEnumerator();

                IPath   path    = this.graphicFactory.CreatePath();
                LatLong latLong = iterator.Current;
                long    mapSize = MercatorProjection.GetMapSize(zoomLevel, displayModel.TileSize);
                float   x       = (float)(MercatorProjection.LongitudeToPixelX(latLong.Longitude, mapSize) - topLeftPoint.X);
                float   y       = (float)(MercatorProjection.LatitudeToPixelY(latLong.Latitude, mapSize) - topLeftPoint.Y);
                path.MoveTo(x, y);

                while (iterator.MoveNext())
                {
                    latLong = iterator.Current;
                    x       = (float)(MercatorProjection.LongitudeToPixelX(latLong.Longitude, mapSize) - topLeftPoint.X);
                    y       = (float)(MercatorProjection.LatitudeToPixelY(latLong.Latitude, mapSize) - topLeftPoint.Y);
                    path.LineTo(x, y);
                }

                if (this.paintStroke != null)
                {
                    if (this.keepAligned)
                    {
                        this.paintStroke.SetBitmapShaderShift = topLeftPoint;
                    }
                    canvas.DrawPath(path, this.paintStroke);
                }

                if (this.paintFill != null)
                {
                    if (this.keepAligned)
                    {
                        this.paintFill.SetBitmapShaderShift = topLeftPoint;
                    }

                    canvas.DrawPath(path, this.paintFill);
                }
            }
        }
Пример #11
0
        public MapScaleBar(MapViewPosition mapViewPosition, MapViewDimension mapViewDimension, DisplayModel displayModel, IGraphicFactory graphicFactory, int width, int height)
        {
            this.mapViewPosition  = mapViewPosition;
            this.mapViewDimension = mapViewDimension;
            this.displayModel     = displayModel;
            this.graphicFactory   = graphicFactory;
            this.mapScaleBitmap   = graphicFactory.CreateBitmap((int)(width * this.displayModel.ScaleFactor), (int)(height * this.displayModel.ScaleFactor));

            this.marginHorizontal = DEFAULT_HORIZONTAL_MARGIN;
            this.marginVertical   = DEFAULT_VERTICAL_MARGIN;
            this.scaleBarPosition = DEFAULT_SCALE_BAR_POSITION;

            this.mapScaleCanvas        = graphicFactory.CreateCanvas();
            this.mapScaleCanvas.Bitmap = this.mapScaleBitmap;
            this.distanceUnitAdapter   = MetricUnitAdapter.INSTANCE;
            this.visible      = true;
            this.redrawNeeded = true;
        }
Пример #12
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            lock (this)
            {
                if (this.latLong == null || (this.paintStroke == null && this.paintFill == null))
                {
                    return;
                }

                double latitude      = this.latLong.Latitude;
                double longitude     = this.latLong.Longitude;
                long   mapSize       = MercatorProjection.GetMapSize(zoomLevel, displayModel.TileSize);
                int    pixelX        = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X);
                int    pixelY        = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y);
                int    radiusInPixel = GetRadiusInPixels(latitude, zoomLevel);

                Rectangle canvasRectangle = new Rectangle(0, 0, canvas.Width, canvas.Height);
                if (!canvasRectangle.IntersectsCircle(pixelX, pixelY, radiusInPixel))
                {
                    return;
                }

                if (this.paintStroke != null)
                {
                    if (this.keepAligned)
                    {
                        this.paintStroke.SetBitmapShaderShift = topLeftPoint;
                    }
                    canvas.DrawCircle(pixelX, pixelY, radiusInPixel, this.paintStroke);
                }
                if (this.paintFill != null)
                {
                    if (this.keepAligned)
                    {
                        this.paintFill.SetBitmapShaderShift = topLeftPoint;
                    }
                    canvas.DrawCircle(pixelX, pixelY, radiusInPixel, this.paintFill);
                }
            }
        }
Пример #13
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            ISet <Tile> currentTileSet = LayerUtil.GetTiles(boundingBox, zoomLevel, displayModel.TileSize);

            if (!currentTileSet.Equals(lastTileSet) || lastLabelStoreVersion != labelStore.Version)
            {
                // only need to get new data set if either set of tiles changed or the label store
                lastTileSet           = currentTileSet;
                lastLabelStoreVersion = labelStore.Version;
                IList <MapElementContainer> visibleItems = this.labelStore.GetVisibleItems(currentTileSet);

                // TODO this is code duplicated from CanvasRasterer::drawMapElements, should be factored out
                // what LayerUtil.collisionFreeOrdered gave us is a list where highest priority comes first,
                // so we need to reverse that in order to
                // draw elements in order of priority: lower priority first, so more important
                // elements will be drawn on top (in case of display=true) items.
                elementsToDraw = from element in LayerUtil.CollisionFreeOrdered(visibleItems) orderby element.Priority ascending select element;
            }

            foreach (MapElementContainer item in elementsToDraw)
            {
                item.Draw(canvas, topLeftPoint, this.matrix);
            }
        }
Пример #14
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            if (spacingConfig.ContainsKey(zoomLevel))
            {
                double spacing = spacingConfig[zoomLevel].Value;

                double minLongitude = spacing * (Math.Floor(boundingBox.MinLongitude / spacing));
                double maxLongitude = spacing * (Math.Ceiling(boundingBox.MaxLongitude / spacing));
                double minLatitude  = spacing * (Math.Floor(boundingBox.MinLatitude / spacing));
                double maxLatitude  = spacing * (Math.Ceiling(boundingBox.MaxLatitude / spacing));

                long mapSize = MercatorProjection.GetMapSize(zoomLevel, this.displayModel.TileSize);

                int bottom = (int)(MercatorProjection.LatitudeToPixelY(minLatitude, mapSize) - topLeftPoint.Y);
                int top    = (int)(MercatorProjection.LatitudeToPixelY(maxLatitude, mapSize) - topLeftPoint.Y);
                int left   = (int)(MercatorProjection.LongitudeToPixelX(minLongitude, mapSize) - topLeftPoint.X);
                int right  = (int)(MercatorProjection.LongitudeToPixelX(maxLongitude, mapSize) - topLeftPoint.X);

                for (double latitude = minLatitude; latitude <= maxLatitude; latitude += spacing)
                {
                    int pixelY = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y);
                    canvas.DrawLine(left, pixelY, right, pixelY, this.lineBack);
                }

                for (double longitude = minLongitude; longitude <= maxLongitude; longitude += spacing)
                {
                    int pixelX = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X);
                    canvas.DrawLine(pixelX, bottom, pixelX, top, this.lineBack);
                }

                for (double latitude = minLatitude; latitude <= maxLatitude; latitude += spacing)
                {
                    int pixelY = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y);
                    canvas.DrawLine(left, pixelY, right, pixelY, this.lineFront);
                }

                for (double longitude = minLongitude; longitude <= maxLongitude; longitude += spacing)
                {
                    int pixelX = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X);
                    canvas.DrawLine(pixelX, bottom, pixelX, top, this.lineFront);
                }

                for (double latitude = minLatitude; latitude <= maxLatitude; latitude += spacing)
                {
                    string text   = ConvertCoordinate(latitude);
                    int    pixelX = (canvas.Width - this.textFront.GetTextWidth(text)) / 2;
                    int    pixelY = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y) + this.textFront.GetTextHeight(text) / 2;
                    canvas.DrawText(text, pixelX, pixelY, this.textBack);
                    canvas.DrawText(text, pixelX, pixelY, this.textFront);
                }

                for (double longitude = minLongitude; longitude <= maxLongitude; longitude += spacing)
                {
                    string text   = ConvertCoordinate(longitude);
                    int    pixelX = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X) - this.textFront.GetTextWidth(text) / 2;
                    int    pixelY = (canvas.Height + this.textFront.GetTextHeight(text)) / 2;
                    canvas.DrawText(text, pixelX, pixelY, this.textBack);
                    canvas.DrawText(text, pixelX, pixelY, this.textFront);
                }
            }
        }
Пример #15
0
 /// <summary>
 /// Redraw the mapScaleBar. Make sure you always apply this.displayModel.getScaleFactor() to all coordinates and
 /// dimensions.
 /// </summary>
 /// <param name="canvas">
 ///            The canvas to draw on </param>
 protected internal abstract void Redraw(ICanvas canvas);
Пример #16
0
        private void DrawScaleBar(ICanvas canvas, int scaleBarLength1, int scaleBarLength2, IPaint paint, float scale)
        {
            int maxScaleBarLength = Math.Max(scaleBarLength1, scaleBarLength2);

            switch (scaleBarPosition)
            {
            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_CENTER:
                if (scaleBarLength2 == 0)
                {
                    canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_LEFT:
                if (scaleBarLength2 == 0)
                {
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_RIGHT:
                if (scaleBarLength2 == 0)
                {
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_CENTER:
                if (scaleBarLength2 == 0)
                {
                    canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint);
                }
                else
                {
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_LEFT:
                if (scaleBarLength2 == 0)
                {
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                }
                else
                {
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_RIGHT:
                if (scaleBarLength2 == 0)
                {
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                }
                else
                {
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint);
                    canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint);
                }
                break;
            }
        }
Пример #17
0
 internal CanvasRasterer(IGraphicFactory graphicFactory)
 {
     this.canvas       = graphicFactory.CreateCanvas();
     this.symbolMatrix = graphicFactory.CreateMatrix();
     this.path         = graphicFactory.CreatePath();
 }
Пример #18
0
 /// <summary>
 /// Draws this {@code Layer} on the given canvas.
 /// </summary>
 /// <param name="boundingBox">
 ///            the geographical area which should be drawn. </param>
 /// <param name="zoomLevel">
 ///            the zoom level at which this {@code Layer} should draw itself. </param>
 /// <param name="canvas">
 ///            the canvas on which this {@code Layer} should draw itself. </param>
 /// <param name="topLeftPoint">
 ///            the top-left pixel position of the canvas relative to the top-left map position. </param>
 public abstract void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint);
Пример #19
0
        private void DrawScaleText(ICanvas canvas, string scaleText1, string scaleText2, IPaint paint, float scale)
        {
            switch (scaleBarPosition)
            {
            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_CENTER:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round((canvas.Width - this.paintScaleTextStroke.GetTextWidth(scaleText1)) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_LEFT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_RIGHT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText2)), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_CENTER:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round((canvas.Width - this.paintScaleTextStroke.GetTextWidth(scaleText1)) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText1)), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_LEFT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText1)), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_RIGHT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText1)), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText2)), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;
            }
        }