Пример #1
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);
            }
        }
Пример #2
0
        public void Init(PreferencesFacade preferencesFacade)
        {
            lock (this)
            {
                this.latitude  = preferencesFacade.GetDouble(LATITUDE, 0);
                this.longitude = preferencesFacade.GetDouble(LONGITUDE, 0);

                double maxLatitude  = preferencesFacade.GetDouble(LATITUDE_MAX, Double.NaN);
                double minLatitude  = preferencesFacade.GetDouble(LATITUDE_MIN, Double.NaN);
                double maxLongitude = preferencesFacade.GetDouble(LONGITUDE_MAX, Double.NaN);
                double minLongitude = preferencesFacade.GetDouble(LONGITUDE_MIN, Double.NaN);

                if (isNan(maxLatitude, minLatitude, maxLongitude, minLongitude))
                {
                    this.mapLimit = null;
                }
                else
                {
                    this.mapLimit = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
                }

                this.zoomLevel    = preferencesFacade.GetByte(ZOOM_LEVEL, (sbyte)0);
                this.zoomLevelMax = preferencesFacade.GetByte(ZOOM_LEVEL_MAX, sbyte.MaxValue);
                this.zoomLevelMin = preferencesFacade.GetByte(ZOOM_LEVEL_MIN, (sbyte)0);
                this.scaleFactor  = Math.Pow(2, this.zoomLevel);
            }
        }
Пример #3
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);
            }
        }
Пример #4
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();
            }
        }
Пример #5
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);
        }
Пример #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);

            for (int i = tilePositions.Count - 1; i >= 0; --i)
            {
                DrawTileCoordinates(tilePositions[i], canvas);
            }
        }
Пример #7
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);
            }
        }
Пример #8
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);
                }
            }
        }
Пример #9
0
        public static ISet <Tile> GetTiles(BoundingBox boundingBox, sbyte zoomLevel, 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);

            ISet <Tile> tiles = new HashSet <Tile>();

            for (int tileY = tileTop; tileY <= tileBottom; ++tileY)
            {
                for (int tileX = tileLeft; tileX <= tileRight; ++tileX)
                {
                    tiles.Add(new Tile(tileX, tileY, zoomLevel, tileSize));
                }
            }
            return(tiles);
        }
Пример #10
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);
                }
            }
        }
Пример #11
0
        public virtual void ZoomForBoundsTest()
        {
            // TODO rewrite this unit tests to make it easier to understand
            Dimension[] dimensions = new Dimension[]
            {
                new Dimension(200, 300),
                new Dimension(500, 400),
                new Dimension(1000, 600),
                new Dimension(3280, 1780),
                new Dimension(100, 200),
                new Dimension(500, 200)
            };
            BoundingBox[] boundingBoxes = new BoundingBox[]
            {
                new BoundingBox(12.2, 0, 34.3, 120),
                new BoundingBox(-30, 20, 30, 30),
                new BoundingBox(20.3, 100, 30.4, 120),
                new BoundingBox(4.4, 2, 4.5, 2.2),
                new BoundingBox(50.43, 12.23, 50.44, 12.24),
                new BoundingBox(50.43, 12, 50.44, 40)
            };
            int[] tileSizes = new int[] { 256, 512, 500, 620, 451 };

            sbyte[] results = new sbyte[] { 1, 0, 0, 0, 0, 2, 1, 1, 1, 1, 3, 2, 2, 2, 2, 10, 9, 9, 9, 9, 14, 13, 13, 13, 13, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 3, 2, 2, 1, 2, 5, 4, 4, 3, 4, 11, 10, 10, 10, 10, 15, 14, 14, 13, 14, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 2, 2, 2, 2, 6, 5, 5, 4, 5, 12, 11, 11, 11, 11, 15, 14, 14, 14, 14, 5, 4, 4, 4, 4, 5, 4, 4, 3, 4, 5, 4, 4, 4, 4, 7, 6, 6, 6, 6, 14, 13, 13, 13, 13, 17, 16, 16, 16, 16, 7, 6, 6, 6, 6, 0, 0, 0, 0, 0, 2, 1, 1, 0, 1, 2, 1, 1, 1, 1, 9, 8, 8, 8, 8, 13, 12, 12, 12, 12, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 0, 1, 4, 3, 3, 3, 3, 11, 10, 10, 10, 10, 14, 13, 13, 12, 13, 4, 3, 3, 3, 3 };

            int i = 0;

            foreach (Dimension dimension in dimensions)
            {
                foreach (BoundingBox boundingBox in boundingBoxes)
                {
                    foreach (int tileSize in tileSizes)
                    {
                        Assert.AreEqual(results[i], LatLongUtils.ZoomForBounds(dimension, boundingBox, tileSize));
                        ++i;
                    }
                }
            }
        }
Пример #12
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);
        }
Пример #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>
 /// 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);