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

适用于