DC-SDK Documentation

repository·master·Indexed 21 days ago

https://github.com/dvt3d/dc-sdk

A WebGIS application framework built on Cesium for developing 2D and 3D all-in-one applications. DC-SDK optimizes Cesium usage and provides additional features, including an Animation module with types like Flying, RadarScan, and GlobeRotate, and a ChartLayer for ECharts integration. It features a Promise-based initialization via DC.ready() and utility functions like getLib() and registerLib() for managing third-party modules.

Tokens
19.1K
Snippets
73
Records
97
Agent score
75%

What's inside @dvgis/dc-sdk

  1. Core Features of DC-SDK

    master

    DC-SDK offers several key capabilities for WebGIS developers:

    • Simplicity: Minimal boilerplate required to initialize a 3D scene.
    • Ease of Use: Uses standard development classes and a straightforward instantiation pattern for scene elements.
    • Extensibility: Supports custom Cesium and GIS algorithm libraries. It provides base classes and element lifecycle hooks to allow developers to extend the core functionality.
  2. Access third-party framework modules via getLib()

    master

    Starting from version 4.0.0, the global __namespace variable has been removed. To access required third-party framework modules (such as Cesium or Turf), use the getLib function instead of relying on global namespace attributes.

    Note: This change applies to versions 4.0.0 and later.

    // Instead of using __namespace, use getLib to retrieve modules
    const cesium = getLib('cesium');
    const turf = getLib('turf');
  3. Use CesiumWidget instead of extending Viewer

    master

    Starting with version 4.0.0, the practice of extending the Viewer class has been removed. Developers should now use CesiumWidget as the primary class for scene construction.

    Note: This applies to versions 4.0.0 and later.

  4. Initialize the DC-SDK Viewer

    master

    To start using the SDK, assign the DC object to the global scope (if required by your environment) and call DC.ready({}). This returns a Promise that resolves when the framework is initialized. Once resolved, you can instantiate a new DC.Viewer to render the 3D scene.

    global.DC = DC
    DC.ready({}).then(() => {
        let viewer = new DC.Viewer()
    })
  5. Initialize the framework using ready().then()

    master

    As of version 3.0.0, the framework entry method has changed. Instead of using global functions like init, mixin, or use, you must use the ready() function, which returns a Promise. The framework is ready to use once the promise resolves.

    Note: This change applies to versions 3.0.0 and later.

    // New entry pattern for version 3.0.0+
    ready().then(() => {
      // Initialize your map/scene here
    });
  6. Initialize DC-SDK using the ready() method

    master

    Starting from version 3.0.0, the framework entry point has changed. Instead of using global functions like init, you must use the ready() method, which returns a Promise. This ensures the framework and its dependencies are fully loaded before you attempt to interact with the scene.

    Note: This applies to versions 3.0.0 and later.

    // For versions 3.0.0 and later
    DC.ready().then(() => {
      // Initialize your application here
    });
  7. Initialize a DC.Viewer

    master

    To start using DC-SDK, wait for the framework to be ready using DC.ready(), then instantiate a new DC.Viewer by passing the ID of the HTML element where the viewer should be rendered.

    DC.ready().then(() => {
      let viewer = new DC.Viewer(divId)
    })
  8. Install @dvgis/dc-sdk via NPM or YARN

    master

    To integrate DC-SDK into a modern web development workflow (e.g., with Webpack or Vite), use a package manager. This is the recommended method as it allows for better bundling and dependency management.

    After installation, import the DC module and its required CSS file into your project entry point.

    yarn add @dvgis/dc-sdk
    # or
    npm install @dvgis/dc-sdk
    import * as DC from '@dvgis/dc-sdk/' 
    import '@dvgis/dc-sdk/dist/dc.min.css' 
  9. Quick Start with DC-SDK

    master
    DC-SDK is designed to simplify 3D WebGIS development. You can build a 3D WebGIS application using just a div and a few lines of code. The SDK provides standard development classes and a simple new operation to instantiate scene elements, making it easy to get started with complex geospatial visualizations.
  10. Install @dvgis/dc-sdk via CDN

    master

    You can include DC-SDK directly in your HTML using a CDN. Ensure you include both the JavaScript file and the CSS stylesheet.

    Important: If using the CDN method, you must place the required static resources in the libs/dc-sdk directory at your project root for the framework to function correctly.

    <script src="https://cdn.jsdelivr.net/npm/@dvgis/dc-sdk/dist/dc.min.js"></script>
    <link
      href="https://cdn.jsdelivr.net/npm/@dvgis/dc-sdk/dist/dc.min.css"
      rel="stylesheet"
      type="text/css"
    />
  11. Coordinate and Spatial Utilities

    master

    DC-SDK provides several utilities for handling spatial data, transformations, and positioning:

    • Position: Represents a spatial point.
    • Transform, T, and CoordTransform: Used for coordinate system transformations.
    • Util and DomUtil: General purpose and DOM-specific utility functions.
    • geo-tools: A collection of geographic calculation tools.
    import { Position, Transform, CoordTransform, Util } from '@dvgis/dc-sdk';
  12. How the Event class manages subscriptions

    master

    The Event class acts as a wrapper around Cesium.Event. It uses an internal cache (_cache) to store Cesium.Event instances mapped to specific event types defined in the constructor.

    When a subclass is implemented, it must call _registerEvent() to initialize the Cesium.Event objects for each type defined in its _types configuration. This allows the class to provide a high-level API (on, once, off, fire) for interacting with the underlying Cesium event system.