public void Draw(DrawArgs drawArgs) { _prerenderProvider.CreatePrerenders(drawArgs, _map.Size); // apply view matrix drawArgs.PushScale(_zoom); drawArgs.PushTranslation(_pan); // apply level of detail var drawLod = _zoom > 0.5 ? DrawLevelOfDetail.Normal : DrawLevelOfDetail.Low; drawArgs.LevelOfDetail = drawLod; // calculate viewport transform, used for zoom/pan Matrix3x2.Invert(drawArgs.CurrentTransform, out _mapTransform); // calculate visible field coords var bottomLeftFieldCoords = TranslateToFieldCoords(_bottomLeftViewLimit); var blx = bottomLeftFieldCoords.X; var bly = bottomLeftFieldCoords.Y; var topRightFieldCoords = TranslateToFieldCoords(_topRightViewLimit); var urx = topRightFieldCoords.X; var ury = topRightFieldCoords.Y; // have agents draw themselves layer by layer foreach (var drawLayer in DrawLayers) { drawArgs.Layer = drawLayer; var prerender = _prerenderProvider.GetPrerender(drawLod, drawLayer); if (prerender != null) { drawArgs.Ds.DrawImage(prerender, -_tileRadius, -2.0f * _tileRadiusH); } else { // find indicators which are currently on screen var culledIndicators = _indicatorRegistry .GetIndicators(drawLod, drawLayer) .Where(tm => blx <= tm.Position.X && tm.Position.X <= urx && bly <= tm.Position.Y && tm.Position.Y <= ury); foreach (var indicator in culledIndicators) { indicator.Draw(drawArgs); } } } // restore view matrix drawArgs.Pop(); drawArgs.Pop(); }
private void CreatePrerender(PrerenderedLayer prerender, DrawArgs drawArgs, Vector2 size) { prerender.DestroyResources(); var indicators = _indicatorRegistry.GetIndicators(prerender.LevelOfDetail, prerender.Layer); prerender.Version = _indicatorRegistry.GetVersion(prerender.LevelOfDetail, prerender.Layer); CanvasRenderTarget offscreen = new CanvasRenderTarget(drawArgs.Ds.Device, size.X + 2 * _tileRadius, size.Y + 4 * _tileRadiusH, drawArgs.Ds.Dpi); using (CanvasDrawingSession ds = offscreen.CreateDrawingSession()) { var prerenderArgs = new DrawArgs(ds, drawArgs.CurrentTransform, drawArgs.FrameId); prerenderArgs.PushTranslation(_tileRadius, 2.0f * _tileRadiusH); foreach (var indicator in indicators) { indicator.Draw(prerenderArgs); } } prerender.Render = offscreen; }