目录

Signal Line

Use Cases

Since version 26.0.0, the signal line function is supported.

A signal line is a colored polyline that dynamically reflects the signal strength on the map. A signal line can predict weak-signal or no-signal road sections on a route and remind users to download an offline map in advance, improving outdoor safety.

Constraints

API Description

The signal line function is mainly provided by MapSignalParams, addSignalLine, and MapSignalLine. For more information about the APIs, please refer to API Reference.

API Description
MapSignalParams Signal line attributes.
addSignalLine(params: mapCommon.MapSignalParams): Promise<MapSignalLine> Adds a signal line.
MapSignalLine Signal line management object.

Enabling the Signal Prediction Capability

To use the signal line function, you need to enable the signal prediction capability first.

Currently, the permission request entry is available only to enterprise developers.

  1. Sign in to AppGallery Connect and click Development and services.

  2. Find the app for which you want to enable the signal prediction capability.

  3. Go to the Manage open capabilities tab page, find Signal Prediction Capability under Map Kit, and click Request.

  4. Click Next after confirming that you meet all the conditions for enabling the signal prediction capability.

  5. Enter the request reason.

    Template for filling in the request reason:

    • App introduction: Specify the app type. For example, "XXX is a [type] app."
    • Usage scenario: Describe how a scope will be used. For example, "In [scenario], the app requires access to [capability]."
    • Request purpose: Explain the intended use of a scope. For example, "After using [feature], users perform [action] to receive [service]."

  6. After the system sends a message to the interaction center, wait for the review. The review result will be sent to the interaction center through an internal message within three working days.

  7. After the request is approved, select Map Kit and Signal Prediction Capability to complete the configuration.

Development Procedure

[h2]Adding a Signal Line

  1. Import required modules.

    import { MapComponent, mapCommon, map } from '@kit.MapKit';
    import { AsyncCallback } from '@kit.BasicServicesKit';
  2. Draw a signal line.

    @Entry
    @Component
    struct MapSignalLineDemo {
      // ...
      private mapOptions?: mapCommon.MapOptions;
      private mapController?: map.MapComponentController;
      private callback?: AsyncCallback<map.MapComponentController>;
      private mapSignalLine?: map.MapSignalLine;
    
      aboutToAppear(): void {
        this.mapOptions = {
          position: {
            target: {
              latitude: 32.055583099352,
              longitude: 118.540076398149
            },
            zoom: 14
          }
        };
    
        this.callback = async (err, mapController) => {
          if (!err) {
            this.mapController = mapController;
            let mapSignalParams: mapCommon.MapSignalParams = {
              signalId: 'signalId1'
            };
            mapSignalParams.points =
              [{ longitude: 118.553695, latitude: 32.050789 }, { longitude: 118.553738, latitude: 32.050884 },
                { longitude: 118.548506, latitude: 32.048543 }, { longitude: 118.548413, latitude: 32.048374 },
                { longitude: 118.547185, latitude: 32.048252 }, { longitude: 118.546939, latitude: 32.048296 },
                { longitude: 118.544343, latitude: 32.048765 }, { longitude: 118.544098, latitude: 32.048780 },
                { longitude: 118.538145, latitude: 32.048836 }, { longitude: 118.537896, latitude: 32.048846 },
                { longitude: 118.537654, latitude: 32.048818 }, { longitude: 118.537446, latitude: 32.048708 },
                { longitude: 118.532201, latitude: 32.049620 }, { longitude: 118.532076, latitude: 32.049583 },
                { longitude: 118.531726, latitude: 32.049490 }, { longitude: 118.531593, latitude: 32.049475 },
                { longitude: 118.531466, latitude: 32.049443 }, { longitude: 118.528349, latitude: 32.052531 },
                { longitude: 118.528298, latitude: 32.053657 }, { longitude: 118.528288, latitude: 32.053851 },
                { longitude: 118.527082, latitude: 32.054653 }, { longitude: 118.526755, latitude: 32.054781 },
                { longitude: 118.526755, latitude: 32.054857 }, { longitude: 118.526654, latitude: 32.055124 },
                { longitude: 118.529706, latitude: 32.057719 }, { longitude: 118.530101, latitude: 32.057906 },
                { longitude: 118.530211, latitude: 32.057911 }, { longitude: 118.532985, latitude: 32.058305 },
                { longitude: 118.538524, latitude: 32.057508 }, { longitude: 118.538571, latitude: 32.057418 },
                { longitude: 118.540255, latitude: 32.058049 }, { longitude: 118.540545, latitude: 32.058251 },
                { longitude: 118.540655, latitude: 32.058285 }, { longitude: 118.543645, latitude: 32.059025 },
                { longitude: 118.543763, latitude: 32.059010 }, { longitude: 118.545292, latitude: 32.059901 },
                { longitude: 118.545397, latitude: 32.059912 }, { longitude: 118.548790, latitude: 32.063339 },
                { longitude: 118.549064, latitude: 32.063531 }, { longitude: 118.550198, latitude: 32.064369 },
                { longitude: 118.552740, latitude: 32.059904 }, { longitude: 118.552866, latitude: 32.059620 },
                { longitude: 118.552929, latitude: 32.059516 }, { longitude: 118.553045, latitude: 32.059157 },
                { longitude: 118.553078, latitude: 32.059049 }, { longitude: 118.553186, latitude: 32.056241 },
                { longitude: 118.553204, latitude: 32.056126 }, { longitude: 118.553062, latitude: 32.053036 },
                { longitude: 118.553555, latitude: 32.051478 }, { longitude: 118.553626, latitude: 32.051203 },
                { longitude: 118.553650, latitude: 32.050680 }, { longitude: 118.553684, latitude: 32.050578 }];
    
            // Add a signal line.
            try {
              this.mapSignalLine = await this.mapController.addSignalLine(mapSignalParams);
            } catch (e) {
              console.error(`Failed to create the signalLine. Code: ${e.code}; message: ${e.message}`);
            }
          } else {
            // Map initialization failed.
            console.error(`Failed to initialize the map. Code: ${err.code}; message: ${err.message}`);
          }
        };
      }
    
      build() {
        // ...
          Stack() {
            Column() {
              MapComponent({ mapOptions: this.mapOptions, mapCallback: this.callback });
            }.width('100%')
          }.height('100%')
    
          // ...
      }
    }

[h2]Removing Cached Signal Line Data from the Map

Use removeSignalLineCache to remove cached signal line data from the map to free up storage space.

// Delete the cached data of the signal line with ID signalId1.
let mapSignalParams: mapCommon.MapSignalParams = {
  signalId: 'signalId1'
};
mapSignalParams.points =
  [{ longitude: 118.553695, latitude: 32.050789 }, { longitude: 118.553738, latitude: 32.050884 },
    { longitude: 118.548506, latitude: 32.048543 }, { longitude: 118.548413, latitude: 32.048374 },
    { longitude: 118.547185, latitude: 32.048252 }, { longitude: 118.546939, latitude: 32.048296 }];
// When a signal line is added for the first time, the line information is automatically cached.
try {
  let mapSignalLine1 = await this.mapController.addSignalLine(mapSignalParams);
  // After the deletion, the cache is triggered when a signal line is added with the same signal ID (no value is passed for points).
  mapSignalLine1.remove();
  let mapSignalLine2 = await this.mapController.addSignalLine({signalId: mapSignalParams.signalId});
  // After the line is deleted again, call removeSignalLineCache to remove the cached signal line data.
  mapSignalLine2.remove();
  this.mapController?.removeSignalLineCache(mapSignalParams.signalId);
} catch (e) {
  console.error(`Operation failed. Code: ${e.code}; message: ${e.message}`);
}