Søren Pedersen
Søren Pedersen

Reputation: 856

Loading pushpin in the forge viewer does not respect the viewerState

We are using the "Autodesk.BIM360.Extension.PushPin" extension inside the forge viewer to enable push pins.

When a push pin has been added to the model, we serialize the pushpin data and store it in our database. An example of such a pushpin is here:

{
    "id": "12",
    "label": "12",
    "status": "quality_issues-not_approved",
    "position": {
        "x": 15.324803588519861,
        "y": -10.150864635427533,
        "z": -5.532972775562976
    },
    "type": "issues",
    "objectId": 24518,
    "externalId": "d9a1e318-14d0-4d08-b7ab-6d1c331454c2-002793d1",
    "viewerState": {
        "seedURN": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6MDQyY2QwMmUtNzU0Yi00ZDY2LTgyYTMtNjBmYjFlOWVjMjcxL2U5ODAxZTA4LTUwZjQtNDc0ZS05ZWU4LTAxYWQ0ZGM0ODFiYl9WMV9Lb25nZXN0aWVuKzMwKy0rVGlsYnlnbmluZystK0clMjVDMyUyNUE2bGRlbmRlK2QuKzA1LjA2LnJ2dA",
        "objectSet": [{
            "id": [],
            "isolated": [],
            "hidden": [],
            "explodeScale": 0,
            "idType": "lmv"
        }],
        "viewport": {
            "name": "",
            "eye": ["-15.17842530349136", "-0.9048862425583284", "0.6506974303790392"],
            "target": ["-22.06049144652811", "0.915848677106827", "-0.4205110420886964"],
            "up": [-0.14385076361076257, 0.038057482024001874, 0.9888673247056924],
            "worldUpVector": [0, 0, 1],
            "pivotPoint": ["-22.510046835506888", "1.6223793651751013", "3.668585646439837"],
            "distanceToOrbit": 7.198985875545766,
            "aspectRatio": 1.491792224702381,
            "projection": "orthographic",
            "isOrthographic": true,
            "orthographicHeight": 7.198985875545767
        },
        "renderOptions": {
            "environment": "Boardwalk",
            "ambientOcclusion": {
                "enabled": true,
                "radius": 13.123359580052492,
                "intensity": 1
            },
            "toneMap": {
                "method": 1,
                "exposure": -7,
                "lightMultiplier": -1e-20
            },
            "appearance": {
                "ghostHidden": true,
                "ambientShadow": true,
                "antiAliasing": true,
                "progressiveDisplay": true,
                "swapBlackAndWhite": false,
                "displayLines": true,
                "displayPoints": true
            }
        },
        "cutplanes": [],
        "globalOffset": {
            "x": -20.808594999999997,
            "y": 6.686511499999999,
            "z": 8.456207
        }
    },
    "objectData": {
        "guid": "6de5f80c-73da-30ae-b2d1-8a78f177c2a4",
        "urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6MDQyY2QwMmUtNzU0Yi00ZDY2LTgyYTMtNjBmYjFlOWVjMjcxL2U5ODAxZTA4LTUwZjQtNDc0ZS05ZWU4LTAxYWQ0ZGM0ODFiYl9WMV9Lb25nZXN0aWVuKzMwKy0rVGlsYnlnbmluZystK0clMjVDMyUyNUE2bGRlbmRlK2QuKzA1LjA2LnJ2dA",
        "viewableId": "aaff5911-e8b1-4ae2-b41c-4284d0703eb4-00150218",
        "viewName": "{3D}"
    }
}

We then load the pushpin into the model again at a later point (when the user reopens the model), like this:

pushPinExtension.loadItems([pushPinItem]);

The result is that the pushpin is added in the model at the correct place, but the viewer state is incorrect. It seems like the viewer state for the pushpin is set to the viewer state of the model at the time when we load the pushpin - and not to the viewer state stored inside the pushpin.

Is this expected behaviour? - and if so, how do I use the viewer state from the pushpin instead?

Upvotes: 0

Views: 323

Answers (1)

Bryan Huang
Bryan Huang

Reputation: 5342

why not explicitly load the viewer state stored in the pushpin separately after loading the pushpin:

pushPinExtension.loadItems([pushPinItem]);
viewer.restoreState(pushPinItem.viewerState)

EDIT:

Try restore the viewer state when an item is clicked - subscribe to the click event with:

   viewer.restoreState(...)
   //...
})

Upvotes: 1

Related Questions