### Install Project Dependencies with Yarn Source: https://github.com/heatech/tgapi4document/blob/main/README.md Installs all necessary project dependencies using Yarn. This is a prerequisite for running local development or building the project. ```bash yarn ``` -------------------------------- ### Start Local Development Server with Yarn Source: https://github.com/heatech/tgapi4document/blob/main/README.md Starts a local development server for the Docusaurus website. Changes are reflected live without requiring a server restart. This command opens the website in a browser. ```bash yarn start ``` -------------------------------- ### Get Services Information (JavaScript) Source: https://context7.com/heatech/tgapi4document/llms.txt Queries and retrieves information about all currently loaded services, including their configuration details such as name, mode, URL, and token. ```javascript // Retrieve information about all services appInstance.uniCall('getServicesInfo', {}, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。", // "mode": "streaming", // "services": [ // { // "name": "serviceName1", // "default": true, // "url": "https://www.tuguan.net/scenes/abc", // "token": "ABCDEFG" // }, // { // "name": "serviceName2", // "default": false, // "url": "https://www.tuguan.net/scenes/abc", // "token": "ABCDEFG" // } // ] // } }); ``` -------------------------------- ### Get Scenes Information Source: https://context7.com/heatech/tgapi4document/llms.txt Retrieves comprehensive information about all scenes, including details about custom resources like icons and models. ```APIDOC ## Get Scenes Information ### Description Retrieve comprehensive information about all scenes including custom resources. ### Method `uniCall` ### Endpoint `getScenesInfo` ### Parameters #### Request Body (This endpoint does not require a request body; an empty object `{}` can be passed). ### Request Example ```json { } ``` ### Response #### Success Response (200) - **result** (number) - Indicates success (typically 1). - **message** (string) - Confirmation message (e.g., "成功"). - **mode** (string) - Scene mode (e.g., "streaming"). - **scenes** (array) - Array of scene objects, each containing: - **name** (string) - The name of the scene. - **default** (boolean) - Whether this is the default scene. - **primitiveCoord** (string) - The coordinate system used (e.g., "Planner3857"). - **url** (string) - The URL to the scene data. - **token** (string) - Authentication token for the scene. - **customIcons** (array) - Array of custom icon objects, each containing: - **name** (string) - The name of the custom icon. - **url** (string) - URL for the icon (for streaming). - **bitmap** (string) - Base64 encoded bitmap for the icon (client-side). - **customModels** (array) - Array of custom model names. - **customModelsLocalFile** (array) - Array of custom model names available locally. - **customModelsLocalServer** (array) - Array of custom model names available on the local server. #### Response Example ```json { "result": 1, "message": "成功。", "mode": "streaming", "scenes": [ { "name": "sceneName1", "default": true, "primitiveCoord": "Planner3857", "url": "https://www.tuguan.net/scenes/abc", "token": "ABCDEFG" } ], "customIcons": [ { "name": "custom-摄像头", "url": "", "bitmap": "" } ], "customModels": ["ModelName1", "ModelName2"], "customModelsLocalFile": ["ModelName1"], "customModelsLocalServer": ["ModelName1"] } ``` ``` -------------------------------- ### Switch Service and Listen for Event (JavaScript) Source: https://context7.com/heatech/tgapi4document/llms.txt Allows switching between preloaded services without re-initializing the application. It also includes an event listener for the 'onServiceSwitch' event to confirm the switch. ```javascript // Switch to a preloaded service appInstance.uniCall('switchService', { name: 'secondaryService' }, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } }); // Listen for service switch event appInstance.uniCall('addEventListener', { eventName: 'onServiceSwitch', callback: (event) => { console.log('Switched to service:', event); // { // "name": "secondaryService", // "default": false // } } }); ``` -------------------------------- ### Initialize Streaming Rendering Service (JavaScript) Source: https://context7.com/heatech/tgapi4document/llms.txt Initializes the streaming rendering service for high-performance server-side rendering. It requires connection details, a token, and optional scene/state names. It also subscribes to the 'onServiceInit' event. ```javascript appInstance.initService({ name: '默认', container: document.getElementById('container'), mode: 'streaming', // "streaming" for server-side rendering token: 'XXX', // Streaming token from platform url: '192.168.X.X', // Streaming server address sceneName: 'sceneName', // Optional: scene to load immediately stateName: 'stateName', // Optional: initial state name editMode: false // Enable/disable edit mode }, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } // Subscribe to service initialization event appInstance.uniCall('addEventListener', { eventName: 'onServiceInit', callback: (res) => { console.log('Service initialized:', res); // { // "name": "默认", // "default": true // } } }); }); ``` -------------------------------- ### Responsive Layout API Source: https://context7.com/heatech/tgapi4document/llms.txt Implement responsive scaling for the 3D container to adapt to browser window size changes. ```APIDOC ## Responsive Layout API ### Description Implement responsive scaling to adapt the 3D container to browser window size changes, ensuring the application fits the viewport while maintaining aspect ratio. ### Method Call the `scale()` function initially and on window resize events. ### Parameters This function does not take direct parameters but relies on global variables and DOM elements. - `window.innerWidth`: Current browser window width. - `window.innerHeight`: Current browser window height. - `manualWidth`: The design width of the application (e.g., 1920). - `manualHeight`: The design height of the application (e.g., 1080). - `#app`: The DOM element selector for the application container. ### Code ```javascript // Scale the application container to fit viewport function scale() { // Get viewport dimensions let visibleWidth = window.innerWidth; let visibleHeight = window.innerHeight; // Define design dimensions let manualWidth = 1920; let manualHeight = 1080; // Calculate scale factors let widthPercentage = (1.0 * visibleWidth) / manualWidth; let heightPercentage = (1.0 * visibleHeight) / manualHeight; // Use minimum scale to maintain aspect ratio let scale = Math.min(widthPercentage, heightPercentage); // Apply CSS transform document.querySelector('#app').style.transform = `translateX(-50%) translateY(-50%) scale(${scale})`; } // Initial scale scale(); // Re-scale on window resize window.onresize = scale; ``` ### CSS Requirement The `#app` element should have the following CSS properties: ```css position: absolute; left: 50%; top: 50%; transform-origin: 0 0; ``` ``` -------------------------------- ### Listen for Service Events with TGAPI Source: https://context7.com/heatech/tgapi4document/llms.txt This snippet demonstrates how to listen for various service lifecycle events using the TGAPI's addEventListener method. It covers connection, initialization, switching, preloading, and disconnection events, providing callback functions to handle each event with logging. ```javascript // Listen for service connection appInstance.uniCall('addEventListener', { eventName: 'onServiceConnected', callback: (event) => { console.log('Service connected'); } }); // Listen for service initialization appInstance.uniCall('addEventListener', { eventName: 'onServiceInit', callback: (event) => { console.log('Service initialized:', event); // { // "name": "serviceName", // "default": false // } } }); // Listen for service switch appInstance.uniCall('addEventListener', { eventName: 'onServiceSwitch', callback: (event) => { console.log('Service switched:', event); // { // "name": "newServiceName", // "default": false // } } }); // Listen for service preload completion appInstance.uniCall('addEventListener', { eventName: 'onServiceLoad', callback: (event) => { console.log('Service preloaded:', event); // { // "name": "preloadedService", // "default": false // } } }); // Listen for service disconnection appInstance.uniCall('addEventListener', { eventName: 'onServiceDisconnected', callback: (event) => { console.log('Service disconnected:', event); // { // "name": "serviceName", // "code": "204", // "message": "和服务器网络连接异常。" // } // Error codes: // 201: Server terminated by admin // 202: Usage time limit reached // 203: Server process crashed // 204: Network connection error } }); ``` -------------------------------- ### Deploy Website with Yarn (SSH and Non-SSH Options) Source: https://github.com/heatech/tgapi4document/blob/main/README.md Deploys the Docusaurus website. Two options are provided: using SSH for deployment or specifying a GitHub username for deployment without SSH. This is particularly useful for GitHub Pages. ```bash USE_SSH=true yarn deploy ``` ```bash GIT_USER= yarn deploy ``` -------------------------------- ### Build Static Website Content with Yarn Source: https://github.com/heatech/tgapi4document/blob/main/README.md Generates the static content for the website, typically into a 'build' directory. The generated content can be hosted on any static content hosting service. ```bash yarn build ``` -------------------------------- ### Switch Scene with Camera Configuration (JavaScript) Source: https://context7.com/heatech/tgapi4document/llms.txt Switches between different scenes within the current service, allowing for customized camera positioning. It accepts scene name, coordinate types, focus point, camera distance, pitch, heading, and transition duration. ```javascript // Switch to a different scene with camera configuration let sceneData = { name: 'sceneName', // Scene identifier (streaming only) serviceName: 'service1', // Optional: target service name coordType: 0, // 0: lon/lat, 1: meters from origin coordTypeZ: 0, // 0: sea level, 1: ground, 2: model surface centerCoord: [103.956291, 1.406699], // Camera focus point [lon, lat] coordZ: 150, // Height in meters distance: 1000, // Camera distance from center (meters) pitch: 30, // Camera pitch angle (5-89) heading: 0, // Camera heading (0=north, 0-359) duration: 2 // Transition duration in seconds }; appInstance.uniCall('switchScene', sceneData, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } }); ``` -------------------------------- ### Attach HTML Tip to Landmark with JavaScript Source: https://context7.com/heatech/tgapi4document/llms.txt Attaches an HTML popup tip to a landmark, which can display custom content. This involves creating an HTML element, defining its content and ID, and then using `addOverlayTip` to link it to a specific landmark layer. Event listeners can be added for interactions like clicks. ```javascript // Create HTML element for the tip const landmarkerTipDiv = document.createElement('div'); landmarkerTipDiv.id = 'landmarkerTip'; landmarkerTipDiv.innerHTML = "居民楼"; landmarkerTipDiv.className = "landmarkerTipDiv"; document.body.appendChild(landmarkerTipDiv); // Attach tip to the landmark let tipData = { id: 'pointLayer', // Target landmark layer ID url: '', // External URL (optional) divId: 'landmarkerTip', // HTML element ID isShowClose: true, // Show close button size: [300, 150], // [width, height] in pixels offset: [50, 50], // [x, y] offset from center overlayType: 'landmark' // Overlay type }; appInstance.uniCall('addOverlayTip', tipData, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } }); // Listen for landmark clicks appInstance.uniCall('addEventListener', { eventName: 'onLandmarkClick', callback: (event) => { console.log('Landmark clicked:', event); // Display the tip when landmark is clicked } }); ``` -------------------------------- ### Add Overlay Tip Source: https://context7.com/heatech/tgapi4document/llms.txt Attaches an HTML popup tip to an overlay, such as a landmark, which can be displayed on interaction. ```APIDOC ## Add Overlay Tip ### Description Display an HTML popup tip when a landmark is clicked. ### Method `uniCall` ### Endpoint `addOverlayTip` ### Parameters #### Request Body - **id** (string) - Required - The ID of the target overlay (e.g., landmark ID). - **url** (string) - Optional - URL for loading content remotely (if not using `divId`). - **divId** (string) - Required - The ID of the HTML element to be used as the tip content. - **isShowClose** (boolean) - Optional - Whether to display a close button on the tip (defaults to true). - **size** (array) - Optional - The size of the tip in pixels `[width, height]`. - **offset** (array) - Optional - Offset of the tip from the overlay's center `[x, y]`. - **overlayType** (string) - Required - The type of overlay the tip is attached to (e.g., 'landmark'). ### Request Example ```json { "id": "pointLayer", "url": "", "divId": "landmarkerTip", "isShowClose": true, "size": [300, 150], "offset": [50, 50], "overlayType": "landmark" } ``` ### Response #### Success Response (200) - **result** (number) - Indicates success (typically 1). - **message** (string) - Confirmation message (e.g., "成功"). #### Response Example ```json { "result": 1, "message": "成功。" } ``` ### Prerequisites 1. An HTML element must exist with the `divId` specified (e.g., `
...
`). 2. An overlay (like a landmark) must be added to the scene. 3. Interaction must be enabled for the overlay using `pickOverlay`. 4. An event listener for the relevant overlay interaction (e.g., `onLandmarkClick`) should be set up to trigger the tip display logic. ### Related Actions - **addEventListener**: To listen for overlay interactions that trigger tip display. ```javascript appInstance.uniCall('addEventListener', { eventName: 'onLandmarkClick', callback: (event) => { console.log('Landmark clicked:', event); // Logic to ensure tip is visible or updated } }); ``` ``` -------------------------------- ### Add Landmark Overlay to Scene with JavaScript Source: https://context7.com/heatech/tgapi4document/llms.txt Adds an interactive landmark (icon marker) to the scene at specified coordinates. It allows for setting the icon, label, custom tag, coordinates (lon/lat or meters), and height. Interaction can be enabled using `pickOverlay`. ```javascript // Add a landmark overlay to the scene let landmarkData = { id: 'pointLayer', // Unique layer identifier coordType: 0, // 0: lon/lat, 1: meters coordTypeZ: 0, // 0: sea level, 1: ground, 2: model surface iconName: 'residence', // Built-in icon name label: '', // Text label for icon tag: 'custominfo', // Custom metadata coord: [116.34953788361443, 40.08387756599562], // [longitude, latitude] coordZ: 65, // Height in meters visible: true // Initial visibility }; appInstance.uniCall('addLandmark', landmarkData, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } // Enable click interaction on the landmark appInstance.uniCall('pickOverlay', { overlayType: 'landmark', idLayer: 'pointLayer', type: 'click', isShowDecorator: false // Show selection decoration }); }); ``` -------------------------------- ### Service Events API Source: https://context7.com/heatech/tgapi4document/llms.txt This section covers how to listen for various service lifecycle events such as connection, initialization, switching, preloading, and disconnection. ```APIDOC ## Service Events API ### Description Monitor service connection status and lifecycle events using event listeners. ### Method `appInstance.uniCall('addEventListener', { eventName: 'EVENT_NAME', callback: (event) => { ... } })` ### Events - **onServiceConnected**: Triggered when the service successfully connects. - **onServiceInit**: Triggered when the service has been initialized. The event object contains service details like `name` and `default` status. - **onServiceSwitch**: Triggered when the service is switched to a new one. The event object contains details of the new service. - **onServiceLoad**: Triggered when a service has completed its preloading phase. The event object contains service details. - **onServiceDisconnected**: Triggered when the service disconnects. The event object contains service name, error code, and message. Common error codes include: - `201`: Server terminated by admin - `202`: Usage time limit reached - `203`: Server process crashed - `204`: Network connection error ### Request Example ```javascript // Example for onServiceConnected appInstance.uniCall('addEventListener', { eventName: 'onServiceConnected', callback: (event) => { console.log('Service connected'); } }); // Example for onServiceInit appInstance.uniCall('addEventListener', { eventName: 'onServiceInit', callback: (event) => { console.log('Service initialized:', event); // event structure: { "name": "serviceName", "default": false } } }); ``` ### Response Example Callback functions receive an event object with specific details depending on the event triggered. ``` -------------------------------- ### Preload Service (JavaScript) Source: https://context7.com/heatech/tgapi4document/llms.txt Preloads additional services in the background to enable faster switching between them. This function requires service details such as name, URL, mode, and token. ```javascript let serviceData = { name: 'secondaryService', // Service identifier url: 'serviceUrl', // Service URL mode: 'scene', // "scene" or "streaming" token: 'serviceToken' // Service authentication token }; appInstance.uniCall('loadService', serviceData, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } }); ``` -------------------------------- ### Implement Viewport Scaling for Responsive Layout Source: https://context7.com/heatech/tgapi4document/llms.txt This JavaScript code scales an application container to fit the browser's viewport. It calculates the appropriate scale factor based on the viewport and design dimensions to maintain the aspect ratio and applies it via CSS transforms. The scaling is performed on initial load and re-scaled on window resize. ```javascript // Scale the application container to fit viewport function scale() { // Get viewport dimensions let visibleWidth = window.innerWidth; let visibleHeight = window.innerHeight; // Define design dimensions let manualWidth = 1920; let manualHeight = 1080; // Calculate scale factors let widthPercentage = (1.0 * visibleWidth) / manualWidth; let heightPercentage = (1.0 * visibleHeight) / manualHeight; // Use minimum scale to maintain aspect ratio let scale = Math.min(widthPercentage, heightPercentage); // Apply CSS transform document.querySelector('#app').style.transform = `translateX(-50%) translateY(-50%) scale(${scale})`; } // Initial scale scale(); // Re-scale on window resize window.onresize = scale; // The #app element should have CSS: // position: absolute; // left: 50%; // top: 50%; // transform-origin: 0 0; ``` -------------------------------- ### Retrieve Scene Information with JavaScript Source: https://context7.com/heatech/tgapi4document/llms.txt Retrieves comprehensive information about all scenes, including custom resources like icons and models. The `getScenesInfo` function is called via `appInstance.uniCall` and returns details about scene configuration and custom assets. ```javascript // Get detailed scene information appInstance.uniCall('getScenesInfo', {}, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。", // "mode": "streaming", // "scenes": [ // { // "name": "sceneName1", // "default": true, // "primitiveCoord": "Planner3857", // "url": "https://www.tuguan.net/scenes/abc", // "token": "ABCDEFG" // } // ], // "customIcons": [ // { // "name": "custom-摄像头", // "url": "", // URL for streaming // "bitmap": "" // Base64 bitmap for client-side // } // ], // "customModels": ["ModelName1", "ModelName2"], // "customModelsLocalFile": ["ModelName1"], // "customModelsLocalServer": ["ModelName1"] // } }); ``` -------------------------------- ### Configure Scene Rendering Effects with JavaScript Source: https://context7.com/heatech/tgapi4document/llms.txt Configures visual effects and rendering parameters for the scene. It accepts an object with various properties to control lighting, layering, shadows, and selection highlighting. The function `setSceneEffect` is called via `appInstance.uniCall`. ```javascript // Configure scene rendering effects let effectData = { lightPower: 1.0, // Emissive light intensity (0.0-10.0) lightPowerTip: 1.0, // 3D tip lighting (streaming only) isLayerTopMost: true, // Render layers above all models divTipMovingDelay: 200, // HTML tip sync delay (ms) focusDuration: 0.6, // Focus animation duration (0-30 seconds) gis3dtileShadow: true, // Enable 3D tile shadows clickColor: '#ff0000', // Selection highlight color (client-side) clickEdgeWidth: 1, // Selection edge width 1-5 (client-side) tipMoveOnEdge: true, // Move tips away from screen edges labelColorStyle: 'default' // Label color algorithm (streaming) }; appInstance.uniCall('setSceneEffect', effectData, (result) => { console.log(result); // Expected output: // { // "result": 1, // "message": "成功。" // } }); ``` -------------------------------- ### Add Landmark Source: https://context7.com/heatech/tgapi4document/llms.txt Adds an interactive landmark (icon marker) to the scene at specified coordinates and allows for interaction configuration. ```APIDOC ## Add Landmark ### Description Add an interactive landmark (icon marker) to the scene at specified coordinates. ### Method `uniCall` ### Endpoint `addLandmark` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (string) - Required - Unique layer identifier for the landmark. - **coordType** (number) - Required - Coordinate type: 0 for lon/lat, 1 for meters. - **coordTypeZ** (number) - Required - Altitude reference: 0 for sea level, 1 for ground, 2 for model surface. - **iconName** (string) - Required - Name of the built-in icon to use. - **label** (string) - Optional - Text label to display with the icon. - **tag** (string) - Optional - Custom metadata associated with the landmark. - **coord** (array) - Required - Array containing coordinates [longitude, latitude] or [x, y] depending on `coordType`. - **coordZ** (number) - Optional - Height in meters above the `coordTypeZ` reference. - **visible** (boolean) - Optional - Initial visibility state of the landmark (defaults to true). ### Request Example ```json { "id": "pointLayer", "coordType": 0, "coordTypeZ": 0, "iconName": "residence", "label": "", "tag": "custominfo", "coord": [116.34953788361443, 40.08387756599562], "coordZ": 65, "visible": true } ``` ### Response #### Success Response (200) - **result** (number) - Indicates success (typically 1). - **message** (string) - Confirmation message (e.g., "成功"). #### Response Example ```json { "result": 1, "message": "成功。" } ``` ### Related Actions - **pickOverlay**: To enable interaction (click/hover) on the added landmark. ```javascript appInstance.uniCall('pickOverlay', { overlayType: 'landmark', idLayer: 'pointLayer', type: 'click', isShowDecorator: false }); ``` ``` -------------------------------- ### Set Scene Effects Source: https://context7.com/heatech/tgapi4document/llms.txt Configures visual effects and rendering parameters for the scene, controlling aspects like lighting, layer rendering, and shadow casting. ```APIDOC ## Set Scene Effects ### Description Configure visual effects and rendering parameters for the scene. ### Method `uniCall` ### Endpoint `setSceneEffect` ### Parameters #### Request Body - **lightPower** (number) - Optional - Emissive light intensity (0.0-10.0) - **lightPowerTip** (number) - Optional - 3D tip lighting (streaming only) - **isLayerTopMost** (boolean) - Optional - Render layers above all models - **divTipMovingDelay** (number) - Optional - HTML tip sync delay (ms) - **focusDuration** (number) - Optional - Focus animation duration (0-30 seconds) - **gis3dtileShadow** (boolean) - Optional - Enable 3D tile shadows - **clickColor** (string) - Optional - Selection highlight color (client-side) - **clickEdgeWidth** (number) - Optional - Selection edge width 1-5 (client-side) - **tipMoveOnEdge** (boolean) - Optional - Move tips away from screen edges - **labelColorStyle** (string) - Optional - Label color algorithm (streaming) ### Request Example ```json { "lightPower": 1.0, "lightPowerTip": 1.0, "isLayerTopMost": true, "divTipMovingDelay": 200, "focusDuration": 0.6, "gis3dtileShadow": true, "clickColor": "#ff0000", "clickEdgeWidth": 1, "tipMoveOnEdge": true, "labelColorStyle": "default" } ``` ### Response #### Success Response (200) - **result** (number) - Indicates success (typically 1). - **message** (string) - Confirmation message (e.g., "成功"). #### Response Example ```json { "result": 1, "message": "成功。" } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.