Skip to content

Commit

Permalink
Add telemetry module registration
Browse files Browse the repository at this point in the history
  • Loading branch information
sebstryczek committed Dec 10, 2024
1 parent f6eddac commit 8fcff10
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Layer3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {

import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

import { registerTelemetry } from "./telemetry";

/**
* The altitude of a mesh can be relative to the ground surface, or to the mean sea level
*/
Expand Down Expand Up @@ -287,6 +289,8 @@ export class Layer3D implements CustomLayerInterface {
* Automatically called when the layer is added. (should not be called manually)
*/
onAdd?(map: MapSDK, gl: WebGL2RenderingContext): void {
registerTelemetry(map);

this.map = map;
this.renderer = new WebGLRenderer({
canvas: map.getCanvas(),
Expand Down
1 change: 1 addition & 0 deletions src/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./registerTelemetry";
34 changes: 34 additions & 0 deletions src/telemetry/registerTelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as maptilersdk from "@maptiler/sdk";
import packagejson from "../../package.json";

/**
* TODO: Remove when telemetry will be implemented
*/
declare module "@maptiler/sdk" {
interface Map {
telemetry: {
registerModule: (name: string, version: string) => void;
};
}
}

maptilersdk.Map.prototype.telemetry = {
registerModule: (name: string, version: string) => {
console.log(`Telemetry module registered: ${name} ${version}`);
},
};
/* *** */

let isRegistered = false;

function registerTelemetry(map: maptilersdk.Map) {
if (isRegistered === true) {
return;
}

map.telemetry.registerModule(packagejson.name, packagejson.version);

isRegistered = true;
}

export { registerTelemetry };

0 comments on commit 8fcff10

Please sign in to comment.