共用方式為


SpatialAnchorTransferManager.TryExportAnchorsAsync 方法

定義

將空間錨點匯出至資料流程,稍後可以在另一部裝置上匯入。 這可讓這兩部裝置在使用者周圍的環境中推斷相同的位置。

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)

參數

anchors

IIterable<IKeyValuePair<String,SpatialAnchor>>

IEnumerable<KeyValuePair<String,SpatialAnchor>>

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

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

要匯出的錨點集合,每個錨點都是由應用程式指定的字串索引鍵所識別。

stream
IOutputStream

要匯出錨點的資料流程。

傳回

匯出完成後觸發的作業。

屬性

Windows 需求

應用程式功能
spatialPerception

備註

應用程式必須負責透過自己的網路通道將資料串流傳送至其他裝置。

如果匯出成功,這個方法會產生 true 的結果。 如果空間理解系統在匯出期間逾時,匯出可能會失敗。

注意: 如果您使用 JavaScript,則無法直接建立 錨點 參數,因為它的類型為 IIterable < IKeyValuePair < Platform::String^、Windows::P erception::Spatial::SpatialAnchor^ >> 。 請改為建立具有 CreateMap 函式的原生 WinRT 協助程式元件:

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

現在,您可以在 JavaScript 中填入錨點集合,並將其傳遞至 TryExportAnchorsAsync 方法。 下列程式碼範例示範如何使用 SpatialAnchorHelper 類別來填入錨點集合。

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

適用於