Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
中国BDN社区
  • Welcome to Bentley Communities
  • Bentley's Communities
  • 中国BDN社区
  • Cancel
中国BDN社区
中国BDN社区-威客 用户选择保存感兴趣的视图
    • Sign In
    • 中国BDN社区-威客
    • -iTwin.js编程
      • iModel.js Front-End简介
      • iModel.js 样例项目配置与运行
      • iModel.js.UI开发基本介绍
      • iModel.js前端统一选择一致性机制
      • iModel.js基本查询
      • iModel.js若干前端功能开发样例
      • imodel图形显示简单介绍
      • iModel文件的合并等操作
      • Redux基本使用
      • simple-viewer-app源码简单分析
      • TypeScript基本介绍及环境配置
      • 下载视口截图
      • 关于imodel测量单位的转换
      • 关于如何导入与导出imodel中schema文件
      • 基于PresentationRules个性化显示iModel的内容
      • 如何在视窗内添加自定义装饰
      • 如何将2个bim中的图形模型显示在一个视图中
      • 用户选择保存感兴趣的视图
    • +MicroStation CONNECT版SDK的新变化
    • +MicroStation编程技巧
    • +OpenRoads中国版平台开发指南
    • +ORD SDK二次开发编程
    • +一步步学习ABD-CE开发
    • +一步步学习MicroStation CE Addin开发
    • 一步步学习MicroStation CE MDL开发
    • +一步步学习ProjectWise编程
    • 中国优先社区二次开发精华帖汇总
    • +学习Microstation交互式工具开发
    • +过期帖,留存仅供参考
    • +非Bentley社区分享的文章
    • C#、C/C++相关的编程知识汇总

     
     Questions about this article, topic, or product? Click here. 

    用户选择保存感兴趣的视图

    有的时候,用户需要保存一些感兴趣的视图,以方便自己下次快速打开或者通过云共享给其他人。

    实现方法:

    首先将感兴趣的视图ViewState序列化为一个SavedViewProps对象,然后将该对象按照键值对的方式保存到云上。使用的时候,从云上获取该键值对中的SavedViewProps对象,然后将其反序列化为视图ViewState对象即可(注意,此处的键可以选择作为所保存的视图的名称,保持其唯一性即可)。

    具体实现代码如下所示:

    将视图ViewState序列化为SavedViewProps并保存到云上

    async function TestSerializationView() {
      const vp = IModelApp.viewManager.selectedView!.view;
      const viewProp = SavedView.viewStateToProps(vp);
    
      const imodel = UiFramework.getIModelConnection()!;
      const requestContext = await AuthorizedFrontendRequestContext.create();
      const userResult = await IModelApp.settings.saveUserSetting(
        requestContext,
        viewProp,
        "NineZoneSample",
        "SaveView1",
        true,
        imodel.contextId,
        imodel.iModelId
      );
      if (userResult.status === SettingsStatus.Success) {
        alert("保存成功");
      } else {
        alert("保存失败");
      }
    }

    从云上获取SavedViewProps,并将其反序列化为视图ViewState,然后将其设置为当前视口。

    async function TestDeserializationView() {
      const imodel = UiFramework.getIModelConnection()!;
      const requestContext = await AuthorizedFrontendRequestContext.create();
      const userResult = await IModelApp.settings.getUserSettingsByNamespace(
        requestContext,
        "NineZoneSample",
        true,
        imodel.contextId,
        imodel.iModelId
      );
      if (userResult.status == SettingsStatus.Success && userResult.settingsMap) {
        if (userResult.settingsMap && userResult.settingsMap.get("SaveView1")) {
          const v: SavedViewProps | undefined = userResult.settingsMap.get(
            "SaveView1"
          ) as SavedViewProps;
          if (v) {
            const state = await SavedView.viewStateFromProps(imodel, v);
            const vp = IModelApp.viewManager.selectedView!;
            vp.changeView(state!);
          }
        }
      } else {
        alert("获取设置失败");
      }
    }

    • Share
    • History
    • More
    • Cancel
    • Devin Liu Created by Devin Liu
    • When: Thu, Oct 8 2020 8:53 PM
    • Revisions: 1
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies