@3ddv/dvm
v2.8.3
Published
This package is a helper to use [DVM](https://docs.3ddvapis.com/js/dvm/). Instead of just adding the script to your website, you can use this package to:
Readme
README
This package is a helper to use DVM. Instead of just adding the script to your website, you can use this package to:
- Use ES6 import/export syntax.
- Get Typescript definitions.
Using this package will still continue to download the core DVM from our CDN, adding it to your website.
If you use this package, you must not add manually the dvm.js script in your html.
Installation
npm install --save @3ddv/dvm
How to use it
This package exports the following functions:
loadModule: equivalent toDVM.loadModule.allowFeatureDetection:trueby default.falseif you want to disable feature detection entirely. You have to call it before loading any module. Check more information here.useModernBuild:falseby default.trueif you want to load directly ES2020+ modules without checking any feature detection. You have to call it before loading any module. Check more information here.setDVMVersion: You can specify from which namespace you want to download DVM. By default, it will be downloaded fromstable. It has to be called before the firstloadModulecall. You should leave it by default unless we specify something else. This would be the equivalent to include the specific script.setDefaultModuleVersion: You can specify the default version branch for a specific module. By default, all modules usesstablebranch.setDefaultEnvironment: Switch the CDN environment from which DVM is downloaded. Defaults to"pro".getBuiltinDVMVersion: Returns the builtin version of DVM.getBuiltinModuleVersion: Returns the builtin version of a module.getDefaultModuleVersion: Returns the currently configured default branch for a module.
loadModule also accepts the following per-call options that override the global defaults:
version— branch (e.g."stable","latest") or numeric version (e.g."2.5.6") for this call.feature_detection: false— disable feature detection just for this call.modern: true— request the ES2020+ build of the module for this call.polyfills— load the polyfills chunk. Defaults totruefor ES5 builds andfalsefor ES2020+ builds; set explicitly to override.plugins— array of plugin names to preload with the module. Each module has its own plugins; see the module's documentation.client_id— set only if 3D Digital Venue has provided one for you.
import { loadModule, setDVMVersion, setDefaultModuleVersion } from "@3ddv/dvm";
setDVMVersion("stable"); // stable is already set by default
setDefaultModuleVersion("map_viewer", "stable");
loadModule("map_viewer", { container: "container-id" })
.then((viewer) => {
return viewer.loadMap({ venue_id: "venue" });
})
.then(() => {
console.log("map loaded");
});Feature detection and modern build
Starting with v2.8, @3ddv/dvm no longer performs any feature detection itself, so it will never try
to eval or run inline code on your page. The DVM library it downloads from our CDN does perform
feature detection by default, but that work is isolated in a separate file — if it's blocked by a
browser extension or CSP, the rest of the loader still runs.
Feature detection can be turned off entirely. Call allowFeatureDetection(false) before any module
instancing:
import { loadModule, allowFeatureDetection } from "@3ddv/dvm";
allowFeatureDetection(false);
loadModule("3d_viewer", { container: "container-id" });It can also be disabled per call:
loadModule("3d_viewer", { container: "container-id", feature_detection: false });When feature detection is disabled, the ES5 build is downloaded by default. You can force the
ES2020+ build with useModernBuild(true) or the per-call modern: true flag:
import { loadModule, useModernBuild } from "@3ddv/dvm";
useModernBuild(true);
// or, per call:
loadModule("3d_viewer", { container: "container-id", modern: true });Builtin versions
You can specify the specific version with which this package was published:
import { loadModule, setDVMVersion, setDefaultModuleVersion } from '@3ddv/dvm';
setDVMVersion('builtin');
setDefaultModuleVersion('map_viewer', 'builtin');
setDefaultModuleVersion('3d_viewer', 'builtin');
loadModule('map_viewer', { container: 'container-id' })
.then((viewer) => {
...
});Specific versions
You can specify a specific numeric version of a module.
import { loadModule, setDVMVersion, setDefaultModuleVersion } from '@3ddv/dvm';
setDefaultModuleVersion('map_viewer', '2.5.6');
loadModule('map_viewer', { container: 'container-id' })
.then((viewer) => {
...
});