Skip to content

JS API Client 4.x

This page is about the Micrio client version 4. Use the links below to navigate to alternative versions.

After creating a Micrio embed in your website using a <micr-io> embed, you can gain full control over the Micrio image by using the Micrio JavaScript (JS) API.

For the technical documentation, see our Micrio client documentation pages at /client/api/4.1/index.html.

INFO

This article does not apply to <iframe> Micrio embeds.

Accessing the Micrio JS instance

You can access a Micrio JS instance by simply querying the Micrio HTML element (<micr-io>):

js
const micrioInstance = document.getElementById('your-micrio-id');
const micrioInstance = document.getElementById('your-micrio-id');

From there on, you can continue with these topics:

  1. JS Developer API

    The Micrio JS client is fully documented using typedoc, and has auto-generated documentation pages of the entire client API. See the Typedoc API documentation here!

    This contains several modules you can control, for instance:

    • HTMLMicrioElement: The main Micrio HTML element which is also its main controller class.

    • Camera: The virtual camera object, which gives you full control of what the user sees in their screen, including a bunch of animations.

    • State: Newly introduced in Micrio 4 is the replacement of the way you can interact with markers and tours from a classic imperative JavaScript API to a Svelte-inspired, store-based state management using SvelteStore.

      This has greatly simplified the internal workings and has made the HTML interface fully reactive based on the image state instead of being interwoven in the previous JS API itself.The main Micrio state controllers where you can control the active markers, tours, and more.

    • Events: Set or remove specific event listeners, such as touch and keyboard events, or behavior specific events such as pinch to zoom, and two-finger pan.

    • Micrio.Models: All model definitions for the JSON data used in the client.

  2. JS Events API

    Read and control everything that happens with your image.

TypeScript API Workspace integration

For TypeScript project integrations (and neat VS Code autocompletion), you can use this declarations .d.ts reference file: https://b.micr.io/micrio-4.1.min.d.ts!

Simply include the d.ts file in your project in a directory included in your project, and implement it:

js
import type { HTMLMicrioElement } from 'Micrio';

// This gives you full type checking and any editor autocompletion
const micrio = document.querySelector('micr-io') as HTMLMicrioElement;

// VS Code will fully know what you're doing here
micrio.camera.flyToView([.2,.2,.3,.3]).then(() => console.log('done!'));
import type { HTMLMicrioElement } from 'Micrio';

// This gives you full type checking and any editor autocompletion
const micrio = document.querySelector('micr-io') as HTMLMicrioElement;

// VS Code will fully know what you're doing here
micrio.camera.flyToView([.2,.2,.3,.3]).then(() => console.log('done!'));

Change logs

You can view the Micrio general change logs here.