Ejemplo n.º 1
0
        private void DrawPath(ShapePaintContainer shapePaintContainer, Point[][] coordinates, float dy)
        {
            this.path.Clear();

            foreach (Point[] innerList in coordinates)
            {
                Point[] points;
                if (dy != 0f)
                {
                    points = RendererUtils.ParallelPath(innerList, dy);
                }
                else
                {
                    points = innerList;
                }
                if (points.Length >= 2)
                {
                    Point point = points[0];
                    this.path.MoveTo((float)point.X, (float)point.Y);
                    for (int i = 1; i < points.Length; ++i)
                    {
                        point = points[i];
                        this.path.LineTo((int)point.X, (int)point.Y);
                    }
                }
            }

            this.canvas.DrawPath(this.path, shapePaintContainer.paint);
        }
Ejemplo n.º 2
0
        private void AdjustFrameBufferMatrix(MapPosition mapPositionFrameBuffer, Dimension mapViewDimension, double scaleFactor, LatLong pivot)
        {
            MapPosition mapViewPosition = this.model.mapViewPosition.MapPosition;

            long mapSize = MercatorProjection.GetMapSize(mapPositionFrameBuffer.ZoomLevel, model.displayModel.TileSize);

            Point pointFrameBuffer = MercatorProjection.GetPixel(mapPositionFrameBuffer.LatLong, mapSize);
            Point pointMapPosition = MercatorProjection.GetPixel(mapViewPosition.LatLong, mapSize);

            double diffX = pointFrameBuffer.X - pointMapPosition.X;
            double diffY = pointFrameBuffer.Y - pointMapPosition.Y;
            // we need to compute the pivot distance from the map center
            // as we will need to find the pivot point for the
            // frame buffer (which generally has not the same size as the
            // map view).
            double pivotDistanceX = 0d;
            double pivotDistanceY = 0d;

            if (pivot != null)
            {
                Point pivotXY = MercatorProjection.GetPixel(pivot, mapSize);
                pivotDistanceX = pivotXY.X - pointFrameBuffer.X;
                pivotDistanceY = pivotXY.Y - pointFrameBuffer.Y;
            }

            float currentScaleFactor = (float)(scaleFactor / Math.Pow(2, mapPositionFrameBuffer.ZoomLevel));

            this.frameBuffer.AdjustMatrix((float)diffX, (float)diffY, currentScaleFactor, mapViewDimension, (float)pivotDistanceX, (float)pivotDistanceY);
        }
Ejemplo n.º 3
0
        public void RenderPointOfInterestCircle(RenderContext renderContext, float radius, IPaint fill, IPaint stroke, int level, PointOfInterest poi)
        {
            Point poiPosition = MercatorProjection.GetPixelRelativeToTile(poi.Position, renderContext.rendererJob.tile);

            renderContext.AddToCurrentDrawingLayer(level, new ShapePaintContainer(new CircleContainer(poiPosition, radius), stroke));
            renderContext.AddToCurrentDrawingLayer(level, new ShapePaintContainer(new CircleContainer(poiPosition, radius), fill));
        }
Ejemplo n.º 4
0
        private void DrawCircleContainer(ShapePaintContainer shapePaintContainer)
        {
            CircleContainer circleContainer = (CircleContainer)shapePaintContainer.shapeContainer;
            Point           point           = circleContainer.point;

            this.canvas.DrawCircle((int)point.X, (int)point.Y, (int)circleContainer.radius, shapePaintContainer.paint);
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 7
0
 public virtual bool Contains(Point center, Point point)
 {
     lock (this)
     {
         Rectangle r = new Rectangle(center.X - (float)bitmap.Width / 2 + this.horizontalOffset, center.Y - (float)bitmap.Height / 2 + this.verticalOffset, center.X + (float)bitmap.Width / 2 + this.horizontalOffset, center.Y + (float)bitmap.Height / 2 + this.verticalOffset);
         return(r.Contains(point));
     }
 }
Ejemplo n.º 8
0
 private static Point[] GetTilePixelCoordinates(int tileSize)
 {
     Point[] result = new Point[5];
     result[0] = new Point(0, 0);
     result[1] = new Point(tileSize, 0);
     result[2] = new Point(tileSize, tileSize);
     result[3] = new Point(0, tileSize);
     result[4] = result[0];
     return(result);
 }
Ejemplo n.º 9
0
 private void Scale(float scaleFactor, float pivotDistanceX, float pivotDistanceY)
 {
     if (scaleFactor != 1)
     {
         Point center = this.dimension.Center;
         float pivotX = (float)(pivotDistanceX + center.X);
         float pivotY = (float)(pivotDistanceY + center.Y);
         this.matrix.Scale(scaleFactor, scaleFactor, pivotX, pivotY);
     }
 }
Ejemplo n.º 10
0
        protected internal override void DoWork()
        {
            long startTime = System.DateTime.Now.Ticks;

            this.redrawNeeded = false;

            FrameBuffer frameBuffer = this.mapView.FrameBuffer;
            IBitmap     bitmap      = frameBuffer.DrawingBitmap;

            if (bitmap != null)
            {
                this.drawingCanvas.Bitmap = bitmap;

                MapPosition mapPosition     = this.mapViewPosition.MapPosition;
                Dimension   canvasDimension = this.drawingCanvas.Dimension;
                int         tileSize        = this.mapView.Model.displayModel.TileSize;
                BoundingBox boundingBox     = MapPositionUtil.GetBoundingBox(mapPosition, canvasDimension, tileSize);
                Point       topLeftPoint    = MapPositionUtil.GetTopLeftPoint(mapPosition, canvasDimension, tileSize);

                foreach (Layer layer in this.layers)
                {
                    if (layer.Visible)
                    {
                        layer.Draw(boundingBox, mapPosition.ZoomLevel, this.drawingCanvas, topLeftPoint);
                    }
                }

                if (!mapViewPosition.AnimationInProgress())
                {
                    // this causes a lot of flickering when an animation
                    // is in progress
                    frameBuffer.FrameFinished(mapPosition);
                    this.mapView.Repaint();
                }
                else
                {
                    // make sure that we redraw at the end
                    this.redrawNeeded = true;
                }
            }

            long elapsedMilliseconds = (System.DateTime.Now.Ticks - startTime) / 10000;
            long timeSleep           = MILLISECONDS_PER_FRAME - elapsedMilliseconds;

            if (timeSleep > 1 && !Interrupted)
            {
                System.Threading.Tasks.Task.Delay((int)timeSleep);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Computes a polyline with distance dy parallel to given coordinates.
        /// http://objectmix.com/graphics/132987-draw-parallel-polyline-algorithm-needed.html
        /// </summary>
        internal static Point[] ParallelPath(Point[] p, double dy)
        {
            int n = p.Length - 1;

            Point[] u = new Point[n];
            Point[] h = new Point[p.Length];

            // Generate an array u[] of unity vectors of each direction
            for (int k = 0; k < n; ++k)
            {
                double c = p[k + 1].X - p[k].X;
                double s = p[k + 1].Y - p[k].Y;
                double l = Math.Sqrt(c * c + s * s);
                if (l == 0)
                {
                    u[k] = new Point(0, 0);
                }
                else
                {
                    u[k] = new Point(c / l, s / l);
                }
            }

            // For the start point calculate the normal
            h[0] = new Point(p[0].X - dy * u[0].Y, p[0].Y + dy * u[0].X);

            // For 1 to N-1 calculate the intersection of the offset lines
            for (int k = 1; k < n; k++)
            {
                double l = dy / (1 + u[k].X * u[k - 1].X + u[k].Y * u[k - 1].Y);
                h[k] = new Point(p[k].X - l * (u[k].Y + u[k - 1].Y), p[k].Y + l * (u[k].X + u[k - 1].X));
            }

            // For the end point use the normal
            h[n] = new Point(p[n].X - dy * u[n - 1].Y, p[n].Y + dy * u[n - 1].X);

            return(h);
        }
Ejemplo n.º 12
0
        private void DrawPath(ShapePaintContainer shapePaintContainer, Point[][] coordinates, float dy)
        {
            if (canvas == null)
            {
                return;
            }

            // TODO
            //this.path.Clear();
            var path = this.graphicFactory.CreatePath();

            foreach (Point[] innerList in coordinates)
            {
                Point[] points;
                if (dy != 0f)
                {
                    points = RendererUtils.ParallelPath(innerList, dy);
                }
                else
                {
                    points = innerList;
                }
                if (points.Length >= 2)
                {
                    Point point = points[0];
                    path.MoveTo((float)point.X, (float)point.Y);
                    for (int i = 1; i < points.Length; ++i)
                    {
                        point = points[i];
                        path.LineTo((int)point.X, (int)point.Y);
                    }
                }
            }

            this.canvas.DrawPath(path, shapePaintContainer.paint);
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
0
        public void RenderPointOfInterestSymbol(RenderContext renderContext, Display display, int priority, IBitmap symbol, PointOfInterest poi)
        {
            Point poiPosition = MercatorProjection.GetPixelAbsolute(poi.Position, renderContext.rendererJob.tile.MapSize);

            renderContext.labels.Add(new SymbolContainer(poiPosition, display, priority, symbol));
        }
Ejemplo n.º 15
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            lock (this)
            {
                if (this.latLongs.Count == 0 || this.paintStroke == null)
                {
                    return;
                }

                IEnumerator <LatLong> iterator = this.latLongs.GetEnumerator();
                if (!iterator.MoveNext())
                {
                    return;
                }

                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);

                IPath path = this.graphicFactory.CreatePath();
                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.keepAligned)
                {
                    this.paintStroke.SetBitmapShaderShift = topLeftPoint;
                }
                canvas.DrawPath(path, this.paintStroke);
            }
        }
Ejemplo n.º 16
0
        public void RenderPointOfInterestCaption(RenderContext renderContext, Display display, int priority, string caption, float horizontalOffset, float verticalOffset, IPaint fill, IPaint stroke, Position position, int maxTextWidth, PointOfInterest poi)
        {
            Point poiPosition = MercatorProjection.GetPixelAbsolute(poi.Position, renderContext.rendererJob.tile.MapSize);

            renderContext.labels.Add(this.graphicFactory.CreatePointTextContainer(poiPosition.Offset(horizontalOffset, verticalOffset), display, priority, caption, fill, stroke, null, position, maxTextWidth));
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
 internal CircleContainer(Point point, float radius)
 {
     this.point  = point;
     this.radius = radius;
 }
Ejemplo n.º 19
0
        public void RenderAreaSymbol(RenderContext renderContext, Display display, int priority, IBitmap symbol, PolylineContainer way)
        {
            Point centerPosition = way.CenterAbsolute;

            renderContext.labels.Add(new SymbolContainer(centerPosition, display, priority, symbol));
        }
Ejemplo n.º 20
0
        internal static void RenderSymbol(IBitmap symbolBitmap, Display display, int priority, float dy, bool alignCenter, bool repeatSymbol, float repeatGap, float repeatStart, bool rotate, Point[][] coordinates, ICollection <MapElementContainer> currentItems)
        {
            int skipPixels = (int)repeatStart;

            Point[] c;
            if (dy == 0f)
            {
                c = coordinates[0];
            }
            else
            {
                c = RendererUtils.ParallelPath(coordinates[0], dy);
            }

            // get the first way point coordinates
            double previousX = c[0].X;
            double previousY = c[0].Y;

            // draw the symbolContainer on each way segment
            float segmentLengthRemaining;
            float segmentSkipPercentage;
            float theta = 0;

            for (int i = 1; i < c.Length; ++i)
            {
                // get the current way point coordinates
                double currentX = c[i].X;
                double currentY = c[i].Y;

                // calculate the length of the current segment (Euclidian distance)
                double diffX = currentX - previousX;
                double diffY = currentY - previousY;
                double segmentLengthInPixel = Math.Sqrt(diffX * diffX + diffY * diffY);
                segmentLengthRemaining = (float)segmentLengthInPixel;

                while (segmentLengthRemaining - skipPixels > repeatStart)
                {
                    // calculate the percentage of the current segment to skip
                    segmentSkipPercentage = skipPixels / segmentLengthRemaining;

                    // move the previous point forward towards the current point
                    previousX += diffX * segmentSkipPercentage;
                    previousY += diffY * segmentSkipPercentage;
                    if (rotate)
                    {
                        // if we do not rotate theta will be 0, which is correct
                        theta = (float)Math.Atan2(currentY - previousY, currentX - previousX);
                    }

                    Point point = new Point(previousX, previousY);

                    currentItems.Add(new SymbolContainer(point, display, priority, symbolBitmap, theta, alignCenter));

                    // check if the symbolContainer should only be rendered once
                    if (!repeatSymbol)
                    {
                        return;
                    }

                    // recalculate the distances
                    diffX = currentX - previousX;
                    diffY = currentY - previousY;

                    // recalculate the remaining length of the current segment
                    segmentLengthRemaining -= skipPixels;

                    // set the amount of pixels to skip before repeating the symbolContainer
                    skipPixels = (int)repeatGap;
                }

                skipPixels -= (int)segmentLengthRemaining;
                if (skipPixels < repeatStart)
                {
                    skipPixels = (int)repeatStart;
                }

                // set the previous way point coordinates for the next loop
                previousX = currentX;
                previousY = currentY;
            }
        }
Ejemplo n.º 21
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);
            }
        }
Ejemplo n.º 22
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);
            }
        }
Ejemplo n.º 23
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);
                }
            }
        }
Ejemplo n.º 24
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);
Ejemplo n.º 25
0
 public TilePosition(Tile tile, Point point)
 {
     this.Tile  = tile;
     this.Point = point;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Handles a long press event. A long press event is only triggered if the map was not moved. A return value of true
 /// indicates that the long press event has been handled by this overlay and stops its propagation to other overlays.
 /// <para>
 /// The default implementation of this method does nothing and returns false.
 ///
 /// </para>
 /// </summary>
 /// <param name="tapLatLong">
 ///            the geographic position of the long press. </param>
 /// <param name="layerXY">
 ///            the xy position of the layer element (if available) </param>
 /// <param name="tapXY">
 ///            the xy position of the tap </param>
 /// <returns> true if the long press event was handled, false otherwise. </returns>
 public virtual bool OnLongPress(LatLong tapLatLong, Point layerXY, Point tapXY)
 {
     return(false);
 }
Ejemplo n.º 27
0
        public static IList <TilePosition> GetTilePositions(BoundingBox boundingBox, sbyte zoomLevel, Point topLeftPoint, int tileSize)
        {
            int tileLeft   = MercatorProjection.LongitudeToTileX(boundingBox.MinLongitude, zoomLevel);
            int tileTop    = MercatorProjection.LatitudeToTileY(boundingBox.MaxLatitude, zoomLevel);
            int tileRight  = MercatorProjection.LongitudeToTileX(boundingBox.MaxLongitude, zoomLevel);
            int tileBottom = MercatorProjection.LatitudeToTileY(boundingBox.MinLatitude, zoomLevel);

            int initialCapacity = (tileRight - tileLeft + 1) * (tileBottom - tileTop + 1);
            IList <TilePosition> tilePositions = new List <TilePosition>(initialCapacity);

            for (int tileY = tileTop; tileY <= tileBottom; ++tileY)
            {
                for (int tileX = tileLeft; tileX <= tileRight; ++tileX)
                {
                    double pixelX = MercatorProjection.TileToPixel(tileX, tileSize) - topLeftPoint.X;
                    double pixelY = MercatorProjection.TileToPixel(tileY, tileSize) - topLeftPoint.Y;

                    tilePositions.Add(new TilePosition(new Tile(tileX, tileY, zoomLevel, tileSize), new Point(pixelX, pixelY)));
                }
            }

            return(tilePositions);
        }
Ejemplo n.º 28
0
        public void RenderAreaCaption(RenderContext renderContext, Display display, int priority, string caption, float horizontalOffset, float verticalOffset, IPaint fill, IPaint stroke, Position position, int maxTextWidth, PolylineContainer way)
        {
            Point centerPoint = way.CenterAbsolute.Offset(horizontalOffset, verticalOffset);

            renderContext.labels.Add(this.graphicFactory.CreatePointTextContainer(centerPoint, display, priority, caption, fill, stroke, null, position, maxTextWidth));
        }
Ejemplo n.º 29
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);
            }
        }
Ejemplo n.º 30
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);
            }
        }