SuperMap iClient JavaScript Documentation

repository·master·Indexed 21 days ago

https://github.com/supermap/iclient-javascript

An open-source WebGIS development kit providing a unified client interface for SuperMap GIS platforms. It supports multi-source data maps across multiple terminals and browsers. The SDK includes specialized packages such as @supermapgis/iclient-classic, @supermapgis/iclient-leaflet, @supermapgis/iclient-mapboxgl, and @supermapgis/iclient-common, as well as support for Vue 2.x via vue-iclient and Cordova for Android development.

Tokens
59.4K
Snippets
178
Records
266
Agent score
75%

What's inside SuperMap iClient JavaScript

  1. Overview of SuperMap iClient JavaScript

    master

    SuperMap iClient JavaScript is an open-source WebGIS client application development kit built on modern Web technologies. It serves as a common JavaScript client for SuperMap Cloud GIS and Online GIS platform products.

    Key capabilities include:

    • Library Integration: Integrates leading open-source map and visualization libraries (such as Leaflet, MapboxGL, MapLibreGL, and OpenLayers).
    • Data Support: Supports multi-source data services and map services.
    • Cross-Platform: Supports multiple terminals and cross-browser compatibility.
    • Advanced Visualization: Provides specialized functions for large-scale data visualization and real-time flow data visualization in GIS environments.
  2. Distinguish between QueryService and FeatureService

    master

    Choosing the wrong service for a URL will cause errors. They serve different purposes and require different parameter formats:

    1. QueryService: Used for /rest/maps/ (Map Layer queries).

      • Uses QueryBySQLParameters.
      • Parameter names use the format: "LayerName@DataSource".
      • Results are found in result.result.recordsets[0].features.
    2. FeatureService: Used for /rest/data (Dataset queries).

      • Uses GetFeaturesBySQLParameters.
      • Parameter names use the format: "DataSource:DatasetName".
      • Results are found in result.result.features.
    // ✅ Using QueryService for /rest/maps/
    var param = new mapboxgl.supermap.QueryBySQLParameters({
        queryParams: [{ name: 'Countries@World', attributeFilter: 'POP > 10000000' }]
    });
    new mapboxgl.supermap.QueryService(mapUrl).queryBySQL(param)
        .then(function(result) {
            var features = result.result.recordsets[0].features;
        });
    
    // ✅ Using FeatureService for /rest/data
    var param = new mapboxgl.supermap.GetFeaturesBySQLParameters({
        queryParameter: { name: 'World:Countries', attributeFilter: 'POP > 10000000' },
        datasetNames: ['World:Countries']
    });
    new mapboxgl.supermap.FeatureService(dataUrl).getFeaturesBySQL(param)
        .then(function(result) {
            var features = result.result.features;
        });
  3. Choose between QueryService and FeatureService

    master

    The choice between QueryService and FeatureService depends on the type of service you are accessing (REST Map vs. REST Data). Using the wrong service will result in incorrect URL patterns and data access paths.

    FeatureQueryServiceFeatureService
    Service TypeREST Map (/rest/maps/{mapName})REST Data (/rest/data)
    Identifier FormatLayerName@DataSourceDataSource:DatasetName
    Result Data Pathresult.recordsets[0].featuresresult.features

    API Selection Guide:

    • Load REST Map (Raster): initMap(url) or initMap(url, {type:'raster'})
    • Load REST Map (Vector Tile): initMap(url, {type:'vector-tile'})
    • Query REST Data: Use mapboxgl.supermap.FeatureService (e.g., getFeaturesBySQL)
    • Query REST Map: Use mapboxgl.supermap.QueryService (e.g., queryBySQL)
    • Spatial Analysis: Use mapboxgl.supermap.SpatialAnalystService
  4. Understand the FeatureService serviceResult structure

    master

    The FeatureService methods return a serviceResult object. The most important part for Mapbox GL JS users is result.features, which is a standard GeoJSON FeatureCollection that can be passed directly to map.addSource().

    Structure:

    FieldDescription
    result.featuresGeoJSON FeatureCollection (directly usable with map.addSource())
    result.features.featuresArray of GeoJSON Feature objects
    result.datasetInfoMetadata about the dataset (name, dataSourceName, type, prjCoordSys, bounds)
    {
        result: {
            features: {
                type: "FeatureCollection",
                features: [...]  // GeoJSON Feature[]
            },
            datasetInfo: {
                name: string,
                dataSourceName: string,
                type: string,
                prjCoordSys: {...},
                bounds: {...}
            }
        }
    }
  5. Understand the SuperMap iClient for MapboxGL Skills workflow

    master

    The supermap-iclient-mapboxgl-skills tool is designed to help developers generate code snippets and complete HTML examples for SuperMap iClient for MapboxGL. It uses a two-layer strategy to ensure accuracy:

    1. Metadata Layer (metadata/): This is the authoritative source for API precision. It contains complete JSDoc JSON metadata used to look up exact parameter names, types, and return value structures.
    2. Module Layer (modules/): This provides pre-built templates for high-frequency scenarios. These modules serve as supplements, offering parameter descriptions, return value examples, and complete, runnable code.

    Workflow Logic:

    • The system identifies user intent via rules/intent-mapping.json.
    • It first attempts to retrieve API details from metadata/iclient-mapboxgl/.
    • If successful, it uses the metadata definitions to construct code examples sourced from modules/.
    • If metadata retrieval fails, it searches for similar templates in modules/.
    • If required parameters are missing, it uses prompts/fallback-questions.md to ask the user for clarification before generating the final HTML or code snippet.
  6. Compare FeatureService and QueryService

    master

    It is important to choose the correct service based on your data source and target:

    FeatureFeatureService
    URL Pattern/rest/data
    Service TypeREST Data Service
    Query TargetDatasets
    Parameter KeyqueryParameter / datasetNames
    Return Formatresult.features (GeoJSON)
    FeatureQueryService
    URL Pattern/rest/maps/{mapName}
    Service TypeREST Map Service
    Query TargetMap Layers (visible layers)
    Parameter KeyqueryParams (FilterParameter[])
    Return Formatresult.recordsets[].features (GeoJSON)
  7. WMTS URL identification and format

    master

    When working with SuperMap iServer WMTS services, ensure your URLs follow these rules:

    • Identification: The URL must contain the string WMTS or wmts (case-insensitive).
    • Path Structure: iServer WMTS services do not use the /rest/maps/ path. Instead, use the direct service path format: /iserver/services/{wmtsServiceName}.
    • Example Format: https://{host}:{port}/iserver/services/{wmtsServiceName}
  8. Understand the QueryService response format

    master

    The QueryService returns a serviceResult object. Unlike FeatureService (which returns a direct GeoJSON FeatureCollection), QueryService results are nested within a recordsets array.

    To use the results directly with Mapbox GL map.addSource(), you must access the features via serviceResult.result.recordsets[0].features.

    serviceResult Structure

    {
        result: {
            currentCount: number, // Number of features in current response
            totalCount: number,   // Total number of features matching criteria
            recordsets: [
                {
                    features: [...],  // GeoJSON FeatureCollection
                    datasetName: string,
                    dataSourceName: string
                }
            ]
        }
    }
    var features = serviceResult.result.recordsets[0].features;
    // features is a GeoJSON FeatureCollection object
  9. Compare QueryService and FeatureService

    master

    When choosing between QueryService and FeatureService in the Mapbox GL module, consider the following differences:

    FeatureQueryService
    URL Pattern/rest/maps/{mapName}
    Service TypeREST Map Service
    Query ScopeMap layers (visible layers)
    Parameter KeyqueryParams (Array of FilterParameter)
    Result Formatresult.recordsets[].features (Nested)
    FeatureFeatureService
    URL Pattern/rest/data
    Service TypeREST Data Service
    Query ScopeDatasets
    Parameter KeyqueryParameter / datasetNames
    Result Formatresult.features (Direct GeoJSON)
  10. Coordinate system requirements for map layers

    master

    When working with SuperMap iClient JavaScript and MapboxGL, ensure your data layers match the required coordinate systems to avoid overlay errors:

    Layer TypeCoordinate System Requirement
    Base Map (initMap)Supports multiple systems (EPSG:3857, EPSG:4326, local coordinate systems, etc.)
    GeoJSONMust be WGS84 (EPSG:4326)
    Raster TilesMust match the Base Map projection
    Vector TilesMust match the Base Map projection

    Key Defaults:

    • The default Base Map projection is Web Mercator (EPSG:3857).
    • GeoJSON data must always be WGS84 (EPSG:4326).