Function setWorkersUrl

  • Sets the base URL directory where worker scripts are hosted for CSP compatibility.

    This function configures both the MapLibre and collision system workers to load from external URLs instead of using inline blob URLs. The SDK expects two specific worker files to be available in the provided directory:

    • maplibre-worker.csp.js - For MapLibre map rendering
    • collision-worker.csp.js - For the collision detection system

    Using this approach enables compatibility with strict Content Security Policies that block unsafe-eval and blob: URLs.

    Parameters

    Returns void

    import { setWorkersUrl } from '@mappedin/mappedin-js';

    // Call before initializing any maps
    setWorkersUrl('https://cdn.example.com/workers');
    // This will load:
    // - https://cdn.example.com/workers/maplibre-worker.csp.js
    // - https://cdn.example.com/workers/collision-worker.csp.js
    • The worker files can be found in the published package at: node_modules/@mappedin/mappedin-js/lib/esm/workers/
    • For deployment, copy these files to your web server or CDN
    • A better approach is to add these files to your build process to ensure they're always in sync with your application
    • Call this function before creating any map instances