Läs på engelska

Dela via


SpatialAnchorTransferManager.TryExportAnchorsAsync Method

Definition

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.

[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<bool> TryExportAnchorsAsync(IEnumerable<KeyValuePair<string,SpatialAnchor>> anchors, IOutputStream stream);
[Windows.Foundation.Metadata.RemoteAsync]
[Windows.Foundation.Metadata.Deprecated("Use SpatialEntityStore instead of SpatialAnchorTransferManager. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 262144, "Windows.Foundation.UniversalApiContract")]
public static IAsyncOperation<bool> TryExportAnchorsAsync(IEnumerable<KeyValuePair<string,SpatialAnchor>> anchors, IOutputStream stream);

Parameters

anchors

IEnumerable<KeyValuePair<String,SpatialAnchor>>

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

stream
IOutputStream

The stream to export anchors to.

Returns

Operation that triggers once the export is complete.

Attributes

Windows requirements

App capabilities
spatialPerception

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 <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Perception.Spatial.h>

using namespace winrt;
using namespace Windows::Foundation::Collections;
using namespace Windows::Perception::Spatial;

IMap<winrt::hstring, SpatialAnchor> CreateMap()
{
    return winrt::single_threaded_map<winrt::hstring, 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");
...

Applies to

Produkt Versioner
WinRT Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100