SpatialAnchorTransferManager SpatialAnchorTransferManager SpatialAnchorTransferManager SpatialAnchorTransferManager Class

Definition

Static methods for transferring spatial anchors between devices, so that both devices can reason about the same locations in their users' surroundings.

public : static class SpatialAnchorTransferManagerpublic static class SpatialAnchorTransferManagerPublic Static Class SpatialAnchorTransferManager// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10586.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

Remarks

Important

The export/import approach of sharing spatial anchors between devices is being deprecated. In a future release of Windows, you will need to transition to the SpatialEntityStore API, which provides a shared pool of spatial anchors and metadata, which the system will synchronize on your behalf.

Methods

RequestAccessAsync() RequestAccessAsync() RequestAccessAsync() RequestAccessAsync()

Requests access for an app to export or import spatial anchors. This requires the spatialPerception capability.

public : static IAsyncOperation<SpatialPerceptionAccessStatus> RequestAccessAsync()public static IAsyncOperation<SpatialPerceptionAccessStatus> RequestAccessAsync()Public Static Function RequestAccessAsync() As IAsyncOperation( Of SpatialPerceptionAccessStatus )// You can use this method in JavaScript.
Returns

TryExportAnchorsAsync(IIterable<>>, IOutputStream) TryExportAnchorsAsync(IIterable<>>, IOutputStream) TryExportAnchorsAsync(IIterable<>>, IOutputStream) TryExportAnchorsAsync(IIterable<>>, IOutputStream)

Exports spatial anchors to a stream, which can later be imported on another device. This allows both devices to reason about the same locations in their users' surroundings.

public : static IAsyncOperation<PlatForm::Boolean> TryExportAnchorsAsync(IIterable<IKeyValuePair<PlatForm::String, SpatialAnchor>> anchors, IOutputStream stream)public static IAsyncOperation<bool> TryExportAnchorsAsync(IEnumerable<KeyValuePair<String, SpatialAnchor>> anchors, IOutputStream stream)Public Static Function TryExportAnchorsAsync(anchors As IEnumerable<KeyValuePair<String, SpatialAnchor>>, stream As IOutputStream) As IAsyncOperation( Of bool )// You can use this method in JavaScript.
Parameters
anchors
IIterable<IKeyValuePair<PlatForm::String, SpatialAnchor>> IEnumerable<KeyValuePair<String, SpatialAnchor>> IEnumerable<KeyValuePair<String, SpatialAnchor>> IEnumerable<KeyValuePair<String, SpatialAnchor>>

The collection of anchors to export, each identified by an app-specified string key.

stream
IOutputStream IOutputStream IOutputStream IOutputStream

The stream to export anchors to.

Returns

Operation that triggers once the export is complete.

Remarks

It's the app's responsibility to get the data in the stream to the other device through its own network channel.

This method yields a result of true if the export succeeded. The export can fail if the spatial understanding system times out during the export.

Note: If you're using JavaScript, you can't create the anchors parameter directly, because it's of type IIterable<IKeyValuePair<Platform::String^, Windows::Perception::Spatial::SpatialAnchor^>>. Instead, create a native WinRT helper component that has a CreateMap function:

#include "pch.h"
#include "SpatialAnchorHelper.h"

using namespace SpatialHelper;
using namespace Platform;

Windows::Foundation::Collections::IMap<Platform::String^, Windows::Perception::Spatial::SpatialAnchor^>^ SpatialAnchorHelper::CreateMap()
{
       return ref new Platform::Collections::Map<Platform::String^, Windows::Perception::Spatial::SpatialAnchor^>();
}

Now you can populate the anchors collection in JavaScript and pass it to the TryExportAnchorsAsync method. The following code example shows how to use the SpatialAnchorHelper class to populate the anchors collection.

waitForPositionalTracking(function () {
    var spatialAnchor = Windows.Perception.Spatial.SpatialAnchor.tryCreateRelativeTo(stationaryRef.coordinateSystem);

    if (isLocatableRelativeToUser(spatialAnchor)) {
        var map = SpatialHelper.SpatialAnchorHelper.createMap();
        map.insert("test", spatialAnchor);

        var stream = Windows.Storage.Streams.InMemoryRandomAccessStream();

        console.log("Exporting spatial anchor");
        var exportWatch = new Stopwatch();
        Windows.Perception.Spatial.SpatialAnchorTransferManager.tryExportAnchorsAsync(map.getView(), stream.getOutputStreamAt(0)).then(
            function (succeeded) {
                if (succeeded) {
                    console.log("Exported " + stream.size + " bytes to stream.  Elapsed time: " + exportWatch.stop() + " seconds");
...

TryImportAnchorsAsync(IInputStream) TryImportAnchorsAsync(IInputStream) TryImportAnchorsAsync(IInputStream) TryImportAnchorsAsync(IInputStream)

Imports a stream of spatial anchors that was previously exported from another device. This allows both devices to reason about the same locations in their users' surroundings.

public : static IAsyncOperation<IMapView<PlatForm::String, SpatialAnchor>> TryImportAnchorsAsync(IInputStream stream)public static IAsyncOperation<IReadOnlyDictionary<string, SpatialAnchor>> TryImportAnchorsAsync(IInputStream stream)Public Static Function TryImportAnchorsAsync(stream As IInputStream) As IAsyncOperation( Of IReadOnlyDictionarystring, SpatialAnchor )// You can use this method in JavaScript.
Parameters
stream
IInputStream IInputStream IInputStream IInputStream

The stream to import anchors from.

Returns
IAsyncOperation<IMapView<PlatForm::String, SpatialAnchor>> IAsyncOperation<IReadOnlyDictionary<string, SpatialAnchor>> IAsyncOperation<IReadOnlyDictionary<string, SpatialAnchor>> IAsyncOperation<IReadOnlyDictionary<string, SpatialAnchor>>

The operation that triggers once the import is complete, providing the imported anchors.

Remarks

You must first export the anchors on the source device using the TryExportAnchorsAsync method. It is then the app's responsibility to get the data in the stream to the other device through its own network channel.

This imports the anchors and their supporting data into the device's spatial understanding. An app should then use SpatialAnchorStore.TrySave if it needs to retain access to this anchor.

This method can yield null if the device has reached its limit of spatial anchors, or if the spatial understanding system times out during the import.