Rendering a map off-screen

2435
4
02-11-2016 02:26 PM
AaronHigh
New Contributor III

Hello,

Previously using the ArcGIS WPF Runtime I could create and initialize a map off-screen and render it to a bitmap using RenderTargetBitmap. I'm wondering if there is a preferred method to doing this as I'm currently unable to get a MapView to render unless it's in view, which isn't an option for this use case.

// Sample code

Grid grid = new Grid(){Width=width, Height=height};

Map map = new Map(){Width=width, Height=height};

map.Layers.Add(someLayer);

grid.Children.Add(map);

grid.Measure(new Size(width, height));

grid.Arrange(new Rect(new Size(width, height)));

grid.UpdateLayout();

map.Extent = someExtent;

RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);

rtb.Render(grid);

// Do something with the image here

// End Sample

The sample above is a simplified version of what I'm doing, but the fundamentals are the same. In the .NET 10.2.7 runtime this results in blank images. How can I recreate this behavior in the .NET Runtime? It appears that the map is never initialized unless I bring it into view.

Thanks,

Aaron

Tags (1)
0 Kudos
4 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Aaron,

Probably it is because the Maps are initialized asynchronously after being created. Have you checked about this doc talks about Map initialization: Maps and layers—ArcGIS Runtime SDK for .NET | ArcGIS for Developers

Also, there is another doc mention about  Layer.InitializeAsync Method

0 Kudos
AaronHigh
New Contributor III

Hi Yue,

Thanks for getting back to me, unfortunately neither of the provided methods seem to have any effect. The "Loaded", "LayerLoaded", and "ExtentChanged" events never fire unless the control is visible on screen. I was able to get just the LayerLoaded to fire by calling the internal MapView::CreateCoreViewBase via reflection, but that still doesn't actually render the map or allow map updates to occur.

If you have any other insight that would be great, this is a bit of a show-stopper for us.

0 Kudos
AnttiKajanus1
Occasional Contributor III

Hi Aaron,

Could you describe what is the use case and workflow in this use case?

0 Kudos
AaronHigh
New Contributor III

Good Morning Antti,

The basic use case is to provide a secondary "map" that exists on a background thread that can provide images to a proprietary scene rendering engine for use as textures.

BitmapSource PrimaryMap::GetBitmapTexture(Envelope envelope, double imgWidth, double imgHeight)

The key for us here is that the secondary map is able to change extents without impacting the primary map while remaining hidden/off-screen. The secondary map will however always mirror the layers of the primary map.

0 Kudos