SpatialAnchorTransferManager.TryExportAnchorsAsync Methode

Definition

Exportiert Raumanker in einen Stream, der später auf einem anderen Gerät importiert werden kann. Dies ermöglicht es beiden Geräten, über die gleichen Standorte in der Umgebung ihrer Benutzer zu argumentieren.

public:
 static IAsyncOperation<bool> ^ TryExportAnchorsAsync(IIterable<IKeyValuePair<Platform::String ^, SpatialAnchor ^> ^> ^ anchors, IOutputStream ^ stream);
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<bool> TryExportAnchorsAsync(IIterable<IKeyValuePair<winrt::hstring, SpatialAnchor const&>> const& anchors, IOutputStream const& 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")]
 static IAsyncOperation<bool> TryExportAnchorsAsync(IIterable<IKeyValuePair<winrt::hstring, SpatialAnchor const&>> const& anchors, IOutputStream const& stream);
[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);
function tryExportAnchorsAsync(anchors, stream)
Public Shared Function TryExportAnchorsAsync (anchors As IEnumerable(Of KeyValuePair(Of String, SpatialAnchor)), stream As IOutputStream) As IAsyncOperation(Of Boolean)

Parameter

anchors

IIterable<IKeyValuePair<String,SpatialAnchor>>

IEnumerable<KeyValuePair<String,SpatialAnchor>>

IIterable<IKeyValuePair<Platform::String,SpatialAnchor>>

IIterable<IKeyValuePair<winrt::hstring,SpatialAnchor>>

Die Auflistung der zu exportierenden Anker, die jeweils durch einen von der App angegebenen Zeichenfolgenschlüssel identifiziert werden.

stream
IOutputStream

Der Stream, in den Anker exportiert werden sollen.

Gibt zurück

Vorgang, der ausgelöst wird, nachdem der Export abgeschlossen ist.

Attribute

Windows-Anforderungen

App-Funktionen
spatialPerception

Hinweise

Es liegt in der Verantwortung der App, die Daten im Stream über einen eigenen Netzwerkkanal an das andere Gerät zu übertragen.

Diese Methode ergibt das Ergebnis true , wenn der Export erfolgreich war. Der Export kann fehlschlagen, wenn beim System für räumliches Verständnis während des Exports ein Zeitausfall auftritt.

Hinweis: Wenn Sie JavaScript verwenden, können Sie den Anchors-Parameter nicht direkt erstellen, da er vom Typ IIterable<IKeyValuePair<Platform::String^, Windows::P erception::Spatial::SpatialAnchor^>>ist. Erstellen Sie stattdessen eine native WinRT-Hilfskomponente, die über die CreateMap-Funktion verfügt:

#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>();
}
#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^>();
}

Jetzt können Sie die Anchors-Auflistung in JavaScript auffüllen und an die TryExportAnchorsAsync-Methode übergeben. Im folgenden Codebeispiel wird gezeigt, wie die SpatialAnchorHelper-Klasse zum Auffüllen der Anchors-Auflistung verwendet wird.

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");
...

Gilt für: