問題描述
是否可以通過從外部網頁接收特定 ID 來實現 Forge Viewer 中的突出顯示功能? (Is it possible to implement the highlight function in Forge Viewer by receiving a specific ID from an external web page?)
正在使用 Forge Viewer 查看 IFC 格式項目。IFC 項目元素(頂板、樓板、右牆等)列在外部網頁上,我想實現一個功能,在選擇其中一個時在 Forge Viewer 中突出顯示。
應該我使用'GLOBALID'來實現這個功能?我一直在尋找 Forge Viewer 的 API(v7),但我很好奇它是否提供與上述相同的功能。
參考解法
方法 1:
Yeah, it's possible. Here is a sample demonstrating this idea:
https://github.com/yiskang/forge‑viewer‑iframe‑interoperability
This sample supports two ways to locate objects:
By passing querying strings to viewer page's URL (See public/extlink.html):
- urn: It stands for which model to load by the Forge Viewer.
- idType: It stands for the IFC guid type. If the IFC model is translated by the legacy IFC pipeline, then the idType is
GLOBALID
. On the contrary, if you're using modern pipeline, the idType isIfcGuid
. - guid: It stands for the IFC guid of the object you want to locate.
</ul>With those parameters, you can locate objects after model is loading completely immediately by passing them to the URL like the below:
</li>
</ol>http://localhost:3000/viewer/?urn=dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3bGt3ZWo3eHBiZ3A2M3g0aGwzMzV5Nm0yNm9ha2dnb2YvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X2xlZ2FjeS5pZmM&type=GLOBALID&guid=2cgXCjpDT0ZxBvxMSr3pfm
- By triggering
LOCATE_ELEMENT_EVENT
(See public/index.html):
// Trigger event from iframe's parent page const guid = event.target.getAttribute('data‑guid'); const idType = event.target.getAttribute('data‑idType'); if (!idType || !guid) return; const iframeWind = viewerIframe.contentWindow; iframeWind.NOP_VIEWER.fireEvent({ type: iframeWind.Autodesk.ADN.ElementLocator.Event.LOCATE_ELEMENT_EVENT, idType, guid });
(by DONG HYUK LEE、Eason Kang)
參考文件