Skip to content

Standalone module

This module can be used as a standalone library (D2M), although we recommend the use of DVM library as a module manager. The standalone module is available here:

Dynamic JSON Badge

<script src='https://tk3d.tk3dapi.com/d2m/v2/stable/viewer.js' type='text/javascript' charset='UTF-8'></script>

Dynamic JSON Badge

<script src='https://tk3d.tk3dapi.com/d2m/v2/latest/viewer.js' type='text/javascript' charset='UTF-8'></script>

Migrating from standalone library to DVM

Standalone module is instantiated synchronously. This can lead to somo problems if the instance needs to download asynchronously some features.

Since version 2.2.0, the module has available the ìnit method, which ensures that the module is 100% initialized once the promise is resolved.

For backward compatibility purposes, all the default API is already included in the module once instantiated, but if you use plugins, we cannot assure that the plugin API will be available synchronously.

In DVM, loadModule doesn't resolves until the module is fully initialized, so this problem cannot happen.

Once the module has been instantiated and initialized, the use of the module is exactly the same in both cases:

Standalone module

var instance_options = {
    container: "container",
    ...
};
var viewer = new D2M.Viewer(instance_options);

/* 
 * It is recommended not to do anything until viewer 
 * it is initialized through "init" method 
 */
viewer.init()
    .then(function() {
        // Module is fully initialized here
        start(viewer);
    })
    .catch(function(err) {
        console.error(err);
    });

function start(viewer) {
    // Start here...
    // ...
    viewer.flags.automatic_selection = false;
    viewer.flags.fixed_aspect_ratio = false;
    viewer.loadMap({...})
        .then(...)
        .catch(...);
    // ....
}

This is also valid, but not recommended. If there were plugins they might not work synchronously:

var instance_options = {
    container: "container",
    ...
};
var viewer = new D2M.Viewer(instance_options);
viewer.flags.automatic_selection = false;
viewer.flags.fixed_aspect_ratio = false;
viewer.loadMap({...})
    .then(...)
    .catch(...);

DVM module

var instance_options = {
    container: "container",
    ...
};

DVM.loadModule("map_viewer", instance_options)
    .then(function(viewer) {
        // Module is fully initialized here
        start(viewer);
    })
    .catch(function(err) {
        console.error(err);
    });

function start(viewer) {
    // Start here...
    // ...
    viewer.flags.automatic_selection = false;
    viewer.flags.fixed_aspect_ratio = false;
    viewer.loadMap({...})
        .then(...)
        .catch(...);
    // ....
}