Instantiate a dizmo

Using the viewer and bundle object you can instantiate one dizmo from within another one. To do so you need to have the bundleID of the dizmo you want to instantiate. You can read the list of installed bundles using the viewer.getBundles function:

var bundleList=viewer.getBundles();

// get the Ids of all installed bundles
var to_bundle_id = function(bndl) {
        return bndl.identifier;
};
var installedBundleIds = bundleList.map(to_bundle_id);

This will return an array of bundle identifiers that can be used to produce new instances of dizmos using the instantiateDizmo function.

When instantiating a dizmo using instantiateDizmo(options, publicProperties, privateProperties, callback); you may supply initializing values for most of the attributes of the dizmo in the options object. This may be used for example to make the dizmo appear in a specific location on the screen when it is created or to set its background color. Please check Dizmo coordinate system for more details about dizmoViewer coordinates.

// instantiate a clock dizmo at the location x = 150 , y = 100
var newBundle = new dizmojs.Bundle('com.dizmo.clock');
newBundle.instantiateDizmo({
   'geometry/x' : 150 ,
   'geometry/y' : 100
});

To set some initial values in the public or private storage of the dizmo being created use the second and third object in the parameterlist of the instantiateDizmo function.

// instantiate a clock dizmo with the public property foo set to bar
var newBundle = new dizmojs.Bundle('com.dizmo.clock');
newBundle.instantiateDizmo({
   'geometry/x' : 150 ,
   'geometry/y' : 100
},
{
    'foo' : 'bar'
});

You can also include these initial values for dizmo attributes, private tree nodes and public tree nodes in package.json

"settings": {
    "tree_values": {
        "attributes": {
            "geometry/x": 10
        },
        "public": {
            "foo": "bar"
        }
    }
}

The fourth parameter callback can be used to get a reference to the just created dizmo and will be called once the new dizmo has been instantiated.