Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP maps, add 3D object

Tags:

uwp-maps

I would like to add 3D object in Windows 10 UWP map control.

This object would be "polygon with height", e.g. simple representation of a house - cuboid or cube.

Illustration image:

Illustration

I know that I can add Xaml control (and inside it 3D object e.g. Cube) but then this Cube is not 'map object', only pinned to a certain Lat/Lon.

Any idea how to implement this?

like image 397
Amir Avatar asked Jul 21 '16 12:07

Amir


1 Answers

Microsoft has added MapElement3D in Windows 10 Insider Preview v10.0.16257.0. - that's the falls creators update. It allows you to add objects, turn them, control their size, and direction. You can make them move too!

Example

Example

How-To

Represents a 3D element displayed on a MapControl.

It's usage appears to be very similar to other MapElements, such as MapIcons and MapBillboards.

map3dSphereStreamReference = RandomAccessStreamReference.CreateFromUri
   (new Uri("ms-appx:///Assets/trainengine.3mf"));    

 var myModel = await MapModel3D.CreateFrom3MFAsync(map3dSphereStreamReference,
     MapModel3DShadingOption.Smooth);

 var my3DElement = new MapElement3D();
 my3DElement.Location = myMap.Center;
 my3DElement.Model = myModel;

 myMap.MapElements.Add(my3DElement);   

Beware of two undocumented issues:

  • Attempting to add the same 3DMapElement to two different MapControls will result in System.AccessViolationException. This can happen if you cached the 3D model but not the page with the map control.

HResult=-2147467261 Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

  • Attempting to call MapModel3D.CreateFrom3MFAsync() from a non-Ui thread will cause a crash. This must be called from a UI thread.
like image 71
Vladimir Akopyan Avatar answered Oct 23 '22 04:10

Vladimir Akopyan