Beispiel #1
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            lock (this)
            {
                if (!bitmapCreated)
                {
                    try
                    {
                        shaderBitmap = CreateBitmap(relativePathPrefix, src);
                    }
                    catch (IOException)
                    {
                        // no-op
                    }
                    bitmapCreated = true;
                }

                IPaint strokePaint = getStrokePaint(renderContext.rendererJob.tile.ZoomLevel);

                if (shaderBitmap != null)
                {
                    strokePaint.BitmapShader         = shaderBitmap;
                    strokePaint.SetBitmapShaderShift = way.Tile.Origin;
                }

                float dyScale = this.dyScaled[renderContext.rendererJob.tile.ZoomLevel] ?? this.dy;

                renderCallback.RenderWay(renderContext, strokePaint, dyScale, this.level, way);
            }
        }
Beispiel #2
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();
                }
            }
        }
Beispiel #3
0
 /// <param name="latLong">
 ///            the initial geographical coordinates of this marker (may be null). </param>
 /// <param name="bitmap">
 ///            the initial {@code IBitmap} of this marker (may be null). </param>
 /// <param name="horizontalOffset">
 ///            the horizontal marker offset. </param>
 /// <param name="verticalOffset">
 ///            the vertical marker offset. </param>
 public Marker(LatLong latLong, IBitmap bitmap, int horizontalOffset, int verticalOffset) : base()
 {
     this.latLong          = latLong;
     this.bitmap           = bitmap;
     this.horizontalOffset = horizontalOffset;
     this.verticalOffset   = verticalOffset;
 }
Beispiel #4
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            lock (this)
            {
                // this needs to be synchronized as we potentially set a shift in the shader and
                // the shift is particular to the tile when rendered in multi-thread mode
                IPaint fillPaint = getFillPaint(renderContext.rendererJob.tile.ZoomLevel);
                if (shaderBitmap == null && !bitmapInvalid)
                {
                    try
                    {
                        shaderBitmap = CreateBitmap(relativePathPrefix, src);
                        if (shaderBitmap != null)
                        {
                            fillPaint.BitmapShader = shaderBitmap;
                            shaderBitmap.DecrementRefCount();
                        }
                    }
                    catch (IOException)
                    {
                        bitmapInvalid = true;
                    }
                }

                fillPaint.SetBitmapShaderShift = way.Tile.Origin;

                renderCallback.RenderArea(renderContext, fillPaint, getStrokePaint(renderContext.rendererJob.tile.ZoomLevel), this.level, way);
            }
        }
Beispiel #5
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            if (Display.NEVER == this.display)
            {
                return;
            }

            if (this.bitmap == null && !this.bitmapInvalid)
            {
                try
                {
                    this.bitmap = CreateBitmap(relativePathPrefix, src);
                }
                catch (IOException)
                {
                    this.bitmapInvalid = true;
                }
            }

            float dyScale = this.dyScaled[renderContext.rendererJob.tile.ZoomLevel] ?? this.dy;

            if (this.bitmap != null)
            {
                renderCallback.RenderWaySymbol(renderContext, this.display, this.priority, this.bitmap, dyScale, this.alignCenter, this.repeat, this.repeatGap, this.repeatStart, this.rotate, way);
            }
        }
Beispiel #6
0
 public virtual void FrameFinished(MapPosition frameMapPosition)
 {
     lock (this)
     {
         // swap both bitmap references
         IBitmap bitmapTemp = this.bitmap1;
         this.bitmap1 = this.bitmap2;
         this.bitmap2 = bitmapTemp;
     }
     // taking this out of the synchronized region removes a deadlock potential
     // at the small risk of an inconsistent zoom
     this.frameBufferModel.MapPosition = frameMapPosition;
 }
Beispiel #7
0
 private void DestroyBitmaps()
 {
     if (this.bitmap1 != null)
     {
         this.bitmap1.DecrementRefCount();
         this.bitmap1 = null;
     }
     if (this.bitmap2 != null)
     {
         this.bitmap2.DecrementRefCount();
         this.bitmap2 = null;
     }
 }
        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);
            }
        }
Beispiel #9
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;
        }
Beispiel #10
0
 public void RenderWaySymbol(RenderContext renderContext, Display display, int priority, IBitmap symbol, float dy, bool alignCenter, bool repeat, float repeatGap, float repeatStart, bool rotate, PolylineContainer way)
 {
     WayDecorator.RenderSymbol(symbol, display, priority, dy, alignCenter, repeat, repeatGap, repeatStart, rotate, way.CoordinatesAbsolute, renderContext.labels);
 }
Beispiel #11
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));
        }
Beispiel #12
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));
        }
Beispiel #13
0
        public Caption(IGraphicFactory graphicFactory, DisplayModel displayModel, string elementName, XmlReader reader, IDictionary <string, Symbol> symbols) : base(graphicFactory, displayModel)
        {
            this.fill       = graphicFactory.CreatePaint();
            this.fill.Color = Color.BLACK;
            this.fill.Style = Style.FILL;
            this.fills      = new Dictionary <sbyte?, IPaint>();

            this.stroke       = graphicFactory.CreatePaint();
            this.stroke.Color = Color.BLACK;
            this.stroke.Style = Style.STROKE;
            this.strokes      = new Dictionary <sbyte?, IPaint>();
            this.dyScaled     = new Dictionary <sbyte?, float?>();


            this.display = Display.IFSPACE;

            this.gap = DEFAULT_GAP * displayModel.ScaleFactor;

            ExtractValues(graphicFactory, displayModel, elementName, reader);

            if (!string.ReferenceEquals(this.symbolId, null))
            {
                Symbol symbol = symbols[this.symbolId];
                if (symbol != null)
                {
                    this.bitmap = symbol.Bitmap;
                }
            }

            if (this.position == null)
            {
                // sensible defaults: below if symbolContainer is present, center if not
                if (this.bitmap == null)
                {
                    this.position = Position.CENTER;
                }
                else
                {
                    this.position = Position.BELOW;
                }
            }
            else if (this.position == Position.CENTER || this.position == Position.BELOW || this.position == Position.ABOVE)
            {
                this.stroke.TextAlign = Align.CENTER;
                this.fill.TextAlign   = Align.CENTER;
            }
            else if (this.position == Position.BELOW_LEFT || this.position == Position.ABOVE_LEFT || this.position == Position.LEFT)
            {
                this.stroke.TextAlign = Align.RIGHT;
                this.fill.TextAlign   = Align.RIGHT;
            }
            else if (this.position == Position.BELOW_RIGHT || this.position == Position.ABOVE_RIGHT || this.position == Position.RIGHT)
            {
                this.stroke.TextAlign = Align.LEFT;
                this.fill.TextAlign   = Align.LEFT;
            }
            else
            {
                throw new System.ArgumentException("Position invalid");
            }

            this.maxTextWidth = displayModel.MaxTextWidth;
        }
Beispiel #14
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;
            }
        }