JS SDK: the 3D roof and panel editor
The Numsolar JS SDK is the 3D roof and panel editor behind the configurator and the offer editor: draw the roofs, place the panels, see the sun and the shade.
| Version | 0.66.8 (the version Numsolar serves today) |
|---|---|
| Host API version | 51 (ROOF_EDITOR_HOST_API_VERSION) |
| Builds | ES module dist/index.js, UMD dist/index.umd.cjs, styles dist/style.css, types dist/index.d.ts |
| Made with | TypeScript, Preact 10, Three.js, Tailwind CSS |
Put the configurator on your website
The embedded configurator is the SDK with your packages and your colours. Visitors draw their roof, see the panels and the price, and ask you for an offer.
- In Numsolar, open Funnels and add an embed: its packages, its language and its slug (the last part of its address).
- Add your website's address to the embed's URLs. The browser shows the embed only inside the websites listed there.
- Put an iframe on your page:
<iframe
src="https://numsolar.com/sv/embedded/YOUR-SLUG"
title="Solar configurator"
style="width: 100%; height: 900px; border: 0"
allow="fullscreen"
></iframe>
/sv/embedded/<slug> shows it in Swedish, /en/embedded/<slug> in English.
For ads, e-mail and flyers, use your public link /i/<your slug> instead: it opens
the configurator with your brand, no iframe needed.
The editor's host API
For partners who run the editor in their own page with a Numsolar connection. The page that shows the editor is the host: it mounts the editor, then sends commands and gets events.
Mount the editor
import ns, { renderComboEditor } from "solar-wizard"; // dist/index.js
import "solar-wizard/style.css";
const numsolar = new ns.lib.Numsolar({ redirectUri: "/" });
const editor = document.getElementById("editor");
renderComboEditor(editor, {
class: "flex-1",
lang: "sv", // the interface language: "sv" or "en"
numsolar,
chrome: "host", // version 30+: only the 3D canvas, your page draws the controls
});
numsolar.connection.connect();
renderComboEditor(element, options)
| Option | Type | Description |
|---|---|---|
numsolarrequired
|
Numsolar | The connection and the data (new ns.lib.Numsolar({redirectUri})). |
lang
|
string | The interface language. |
class
|
string | CSS classes for the editor's root. |
chrome
|
"sdk" | "host" | ["sdk"] "host" (version 30+) mounts only the 3D canvas: no SDK menu, toolbars or 2D editors. |
overlayParent
|
HTMLElement | Where pop-up menus and dialogs go. Default document.body. |
roofEditorProps
|
object | Options of the 3D editor, for example eventPrefix (default "roof-editor:"). |
menuProps, panelsEditorProps, orthoEditorProps
|
object | Options of the SDK's menu and 2D editors (with chrome: "sdk"). |
removeComboEditor(element) unmounts it.
Commands and events
Commands and events travel on numsolar.eventBus, named <prefix><name>
(the prefix is "roof-editor:"). Read the names from RoofEditorApp.HOST_EVENTS and
check RoofEditorApp.HOST_API_VERSION before you use a newer one: an older SDK ignores what
it does not know. Commands may be sent at once, before the scene is ready: the editor keeps the latest
one and runs it on its first frame.
const app = ns.apps.RoofEditorApp;
const prefix = app.DEFAULT_EVENT_PREFIX; // "roof-editor:"
const EV = app.HOST_EVENTS;
numsolar.eventBus.on(prefix + EV.SCENE_READY, (e) => {
console.log("roofs:", e.detail.structures.length);
});
numsolar.eventBus.emit(prefix + EV.CAMERA_PRESET, { preset: "house", animate: true });
if ((app.HOST_API_VERSION ?? 1) >= 2) {
numsolar.eventBus.emit(prefix + EV.VIEW_MODE, { mode: "view" }); // no edit handles
}
| Name | Direction | Payload | Since |
|---|---|---|---|
camera-preset | host → SDK | {preset, animate?, durationMs?, fill?}; presets panels, house, battery, equipment, illustration, solar, plan | 1 |
battery | host → SDK | {kwh}; null or 0 removes it | 1 |
view-mode | host → SDK | {mode: "view" | "edit"} | 2 |
select-face | host → SDK | {structureId, doubleLineId} | 3 |
focus | host → SDK | {structureId, doubleLineId, animate?, inset?}, or null to end | 5 |
scene-ready | SDK → host | {structures, installations}, once, after the first frame with roofs | 1 |
camera-view | SDK → host | {preset} when a camera move lands | 1 |
view-level | host → SDK | {level: map | building | roof, electrical?} (electrical, a true/false field on map and building, since 44) | 41 |
roof-blocks-selected | SDK → host | {structureId, blockId}: a box picked in 3D | 51 |
The other commands and events (obstacles, trees, equipment and wiring, the solar map, the Illustration, drawing buildings, panel racks) are in the SDK's README, with one row per host API version.
Panel fitting
"Fill with solar panels" runs inside Numsolar for the configurator and the API. It is not a public service.