目录

Map

has.createMapContext

has.createMapContext(string mapId): MapContext

Creates a MapContext object of the map component.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
mapId string Yes ID of the map component.

Returns

MapContext object.

Example:

let mapContext = has.createMapContext('mapId');

MapContext

[h2]MapContext.getCenterLocation

MapContext.getCenterLocation(Object object)

Obtains the longitude and latitude of the current map center point. This API returns coordinates in the GCJ02 coordinate system.

Since: 1.0.0

Precautions: If network resources are required when this API is called, you need to configure the server domain name first.

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
iconPath string No Icon path, which can be a network path, local path, or code package path.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
longitude number Longitude.
latitude number Latitude.

Error codes

Error Code Error Message
101 fail to get center position.
70000301

1. getCenterLocation error.

2. iconPath is not exist.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.getCenterLocation({
  iconPath: '/path/icon.png', // Replace the example with the actual image resource address.
  success: (res) => {
    console.info('getCenterLocation success, res:', res);
  },
  fail: (err) => {
    console.error('getCenterLocation fail, err:', err);
  },
  complete: (res) => {
    console.info('getCenterLocation complete, res:', res);
  }
});

[h2]MapContext.getRegion

MapContext.getRegion(Object object)

Obtains the view scope of the current map.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
southwest Object Longitude and latitude of the southwest corner.
northeast Object Longitude and latitude of the northeast corner.

Return value of southwest

Parameter Type Description
longitude number Longitude.
latitude number Latitude.

Return value of northeast

Parameter Type Description
longitude number Longitude.
latitude number Latitude.

Error codes

Error Code Error Message
101

1. map component is not exist.

2. fail to get center position.

70000401

1. fail to get current region.

2. getRegion error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.getRegion({
  success: (res) => {
    console.info('getRegion success, res:', res);
  },
  fail: (err) => {
    console.error('getRegion fail, err:', err);
  },
  complete: (res) => {
    console.info('getRegion complete, res:', res);
  }
});

[h2]MapContext.getRotate

MapContext.getRotate(Object object)

Obtains the rotation angle of the current map.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
rotate number Rotation angle.

Error codes

Error Code Error Message
101

1. map component is not exist.

2. fail to get center position.

70000501

1. fail to get rotate.

2. getRotate error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.getRotate({
  success: (res) => {
    console.info('getRotate success, res:', res);
  },
  fail: (err) => {
    console.error('getRotate fail, err:', err);
  },
  complete: (res) => {
    console.info('getRotate complete, res:', res);
  }
});

[h2]MapContext.getScale

MapContext.getScale(Object object)

Obtains the zoom level of the current map.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
scale number Zoom level.

Error codes

Error Code Error Message
101

1. map component is not exist.

2. fail to get center position.

70000601

1. fail to get scale.

2. getScale error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.getScale({
  success: (res) => {
    console.info('getScale success, res:', res);
  },
  fail: (err) => {
    console.error('getScale fail, err:', err);
  },
  complete: (res) => {
    console.info('getScale complete, res:', res);
  }
});

[h2]MapContext.getSkew

MapContext.getSkew(Object object)

Obtains the tilt angle of the current map.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
skew number Tilt angle.

Error codes

Error Code Error Message
101

1. map component is not exist.

2. fail to get center position.

70000701

1. fail to get skew

2. getSkew error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.getSkew({
  success: (res) => {
    console.info('getSkew success, res:', res);
  },
  fail: (err) => {
    console.error('getSkew fail, err:', err);
  },
  complete: (res) => {
    console.info('getSkew complete, res:', res);
  }
});

[h2]MapContext.includePoints

MapContext.includePoints(Object object)

Zooms in or out on the map to ensure that all input coordinate points are in the visible area.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
points Array<Object> Yes List of coordinate points to be displayed in the visible area.
padding Array<number> No Distance from the edges of a coordinate-defined rectangle to the map edges, in pixels. Format: [top,right,bottom,left]
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Attributes in points

Parameter Type Mandatory Description
longitude number Yes Longitude.
latitude number Yes Latitude.

Error codes

Error Code Error Message
101 map component is not exist.
102 padding is invalid, length must be 4.
70000801 1. includePoints error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.includePoints({
  points: [
    { latitude: 30.492150773775826, longitude: 114.5387855706236 },
    { latitude: 31.492150773775826, longitude: 113.5387855706236 }
  ],
  padding: [20, 20, 20, 20],
  success: () => {
    console.info('includePoints success');
  },
  fail: (err) => {
    console.error('includePoints fail, err:', err);
  },
  complete: (res) => {
    console.info('includePoints complete, res:', res);
  }
});

[h2]MapContext.moveToLocation

MapContext.moveToLocation(Object object)

Moves the map center to the current location. To use this function, you need to set show-location to true.

Since: 1.0.0

Required permissions:

  1. ohos.permission.APPROXIMATELY_LOCATION, which needs to be declared in module.json5.

  2. scope.userLocation permission, which is applied for using has.authorize().

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
longitude number No Longitude.
latitude number No Latitude.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101

1. map component is not exist.

2. fail to get center position.

102 latitude is invalid.
103

1. authorize error.

2. has no permission.

70001001 moveToLocation error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.moveToLocation({
  longitude: 114.2342423,
  latitude: 34.232424232,
  success: () => {
    console.info('moveToLocation success');
  },
  fail: (err) => {
    console.error('moveToLocation fail, err:', err);
  },
  complete: (res) => {
    console.info('moveToLocation complete, res:', res);
  }
});

[h2]MapContext.translateMarker

MapContext.translateMarker(Object object)

Moves a marker, with animation effects displayed in the process.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Default Value Mandatory Description
markerId number - Yes Marker ID.
destination Object - Yes Destination point to which the marker is moved.
autoRotate boolean - Yes Indicates whether to automatically rotate a marker during the movement.
rotate number 0 No Rotation angle of the marker.
duration number 1000 No Duration of the animation.
animationEnd function - No Callback triggered when the animation ends.
success function - No Callback triggered when the API call is successful.
fail function - No Callback triggered when the API call fails.
complete function - No Callback triggered when the API call is complete, regardless of success or failure.

Attributes in destination

Parameter Type Mandatory Description
longitude number Yes Longitude.
latitude number Yes Latitude.

Error codes

Error Code Error Message
101

1. markerMap is not exist.

2. map component is not exist.

102

1. longitude or latitude cannot empty.

2. marker is not exist.

3. latitude is invalid.

70001101 translateMarker error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.translateMarker({
  markerId: 1000,
  destination: {
    longitude: 78.232323,
    latitude: 23.121212
  },
  autoRotate: true,
  rotate: 90,
  duration: 1000,
  animationEnd: () => {
    console.info('translateMarker animationEnd');
  },
  success: () => {
    console.info('translateMarker success');
  },
  fail: (err) => {
    console.error('translateMarker fail, err:', err);
  },
  complete: (res) => {
    console.info('translateMarker complete, res:', res);
  }
});

[h2]MapContext.toScreenLocation

MapContext.toScreenLocation(Object object)

Obtains the screen coordinates corresponding to the longitude and latitude. The coordinate origin is the upper left corner of the map.

Since: 1.0.18

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
latitude number Yes Latitude.
longitude number Yes Longitude.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
x number X coordinate. In versions earlier than ASCF 2.0.1, the unit is px. In ASCF 2.0.1 and later versions, the unit is vp.
y number Y coordinate. In versions earlier than ASCF 2.0.1, the unit is px. In ASCF 2.0.1 and later versions, the unit is vp.

Error codes

Error Code Error Message
101

1. projection is not exist.

2. map component is not exist.

70005001 toScreenLocation error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.toScreenLocation({
  longitude: 78.232323,
  latitude: 23.121212,
  success: (res) => {
    console.info('toScreenLocation success, res:', res);
  },
  fail: (err) => {
    console.error('toScreenLocation fail, err:', err);
  },
  complete: (res) => {
    console.info('toScreenLocation complete, res:', res);
  }
});

[h2]MapContext.setLocMarkerIcon

MapContext.setLocMarkerIcon(Object object)

Sets the location point icon. The icon path can be a network path, local path, or code package path.

Since: 1.0.18

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
iconPath string Yes Icon path, which can be a network path, local path, or code package path.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101 map component is not exist.
102 setLocMarkerIcon fail, iconPath cannot be empty.
70005201 setLocMarkerIcon error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.setLocMarkerIcon({
  iconPath: '/path/icon.png', // Replace the example with the actual image resource address.
  success: () => {
    console.info('setLocMarkerIcon success');
  },
  fail: (err) => {
    console.error('setLocMarkerIcon fail, err:', err);
  },
  complete: (res) => {
    console.info('setLocMarkerIcon complete, res:', res);
  }
});

[h2]MapContext.moveAlong

MapContext.moveAlong(Object object)

Moves the marker along a specified path. It is used in scenarios such as track playback.

Since: 1.0.18

Parameters

The input parameter is an object containing the following fields.

Parameter Type Default Value Mandatory Description
markerId number - Yes Marker ID.
path Array - Yes Coordinates of the path, in the format of {longitude, latitude}.
autoRotate boolean true No Whether the rotation angle of the marker automatically changes based on the path direction.
isMapMoving boolean false No Whether the map moves with the animation.
color string #0A59F7CC No Track color.
width number 10 No Track width.
duration number - Yes Smooth movement time, in milliseconds. The minimum value is 100. If the value is less than 100, the value 5000 is used.
success function - No Callback triggered when the API call is successful.
fail function - No Callback triggered when the API call fails.
complete function - No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101

1.map component is not exist.

2. markerMap is not exist.

102

1. path is empty or path attribute value is incorrect.

2. marker is not exist.

70005101 moveAlong error.

Example:

let mapContext = has.createMapContext('mapId');
let path = [];
path.push({ latitude: 31.99685233070878, longitude: 118.75846023442728 });
path.push({ latitude: 31.993617206525155, longitude: 118.76150529647698 });
mapContext.moveAlong({
  markerId: 1000,
  path: path, // Coordinate array.
  autoRotate: true,
  isMapMoving: true,
  color: '#0A59F7CC',
  width: 10,
  duration: 3000,
  success: () => {
    console.info('moveAlong success');
  },
  fail: (err) => {
    console.error('moveAlong fail, err:', err);
  },
  complete: (res) => {
    console.info('moveAlong complete, res:', res);
  }
});

[h2]MapContext.setCenterOffset

MapContext.setCenterOffset(Object object)

Sets the offset of the map center. The offset increases as the center moves rightward and downward. The screen ratio ranges from 0.25 to 0.75, and the default offset is [0.5, 0.5].

Since: 1.0.18

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
offset Array Yes Offset, which is a two-element array.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101

1. map center point is null

2. projection is null.

3. map component is not exist.

102 offset array length must be 2.
70005301 1. setCenterOffset error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.setCenterOffset({
  offset: [0.25, 0.25],
  success: () => {
    console.info('setCenterOffset success');
  },
  fail: (err) => {
    console.error('setCenterOffset fail, err:', err);
  },
  complete: (res) => {
    console.info('setCenterOffset complete, res:', res);
  }
});

[h2]MapContext.addMarkers

MapContext.addMarkers(Object object)

Adds a marker.

Since: 1.0.18

Parameters

The input parameter is an object containing the following fields.

Parameter Type Default Value Mandatory Description
markers Array - Yes Same as the marker attribute of the map component.
clear boolean false No Whether to clear all markers on the map.
success function - No Callback triggered when the API call is successful.
fail function - No Callback triggered when the API call fails.
complete function - No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101 map component is not exist.
102 marker cannot be empty.
70005401 addMarkers error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.addMarkers({
  markers: xxx, // Marker array.
  success: () => {
    console.info('addMarkers success');
  },
  fail: (err) => {
    console.error('addMarkers fail, err:', err);
  },
  complete: (res) => {
    console.info('addMarkers complete, res:', res);
  }
});

[h2]MapContext.removeMarkers

MapContext.removeMarkers(Object object)

Removes a marker.

Since: 1.0.18

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
markerIds Array Yes Marker IDs.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101

1. removeMarkers markers empty.

2. map component is not exist.

102 removeMarkers markerIds err, ids are not in markers.
70005501 removeMarkers error.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.removeMarkers({
  markerIds: [1000], // Marker ID array.
  success: () => {
    console.info('removeMarkers success');
  },
  fail: (err) => {
    console.error('removeMarkers fail, err:', err);
  },
  complete: (res) => {
    console.info('removeMarkers complete, res:', res);
  }
});

[h2]MapContext.addGroundOverlay

MapContext.addGroundOverlay(Object object)

Adds an image layer. The image is zoomed in or out with the map.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Default Value Mandatory Description
id number - Yes Image layer ID.
src string - Yes Image path, which can be a network path, local path, or code package path.
bounds Bounds - Yes Longitude and latitude ranges covered by the image.
visible boolean true No Whether the image is visible.
zIndex number 1 No Image drawing level. A larger value indicates a higher priority.
opacity number 1 No

Image opacity.

0: completely transparent

1: completely opaque

success function - No Callback triggered when the API call is successful.
fail function - No Callback triggered when the API call fails.
complete function - No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101 map component is not exist.
70006501

1. addGroundOverlay error.

2. already have ground overlay.

3. ground overlay add failed.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.addGroundOverlay({
  id: 1,
  src: 'https://www.example.com/xxx.png', // Replace the example with the actual image resource address.
  bounds: {
    southwest: {
      latitude: 39.7032,
      longitude: 116.2978
    },
    northeast: {
      latitude: 40.1032,
      longitude: 116.6978
    }
  },
  visible: true,
  zIndex: 1,
  opacity: 1,
  success: () => {
    console.info('addGroundOverlay success');
  },
  fail: (err) => {
    console.error('addGroundOverlay fail:', err);
  },
  complete: (res) => {
    console.info('addGroundOverlay complete:', res);
  }
});

[h2]MapContext.updateGroundOverlay

MapContext.updateGroundOverlay(Object object)

Updates an image layer.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
id number Yes Image layer ID.
src string Yes Image path, which can be a network path, local path, or code package path.
bounds Bounds Yes Longitude and latitude ranges covered by the image.
visible boolean No Whether the image is visible.
zIndex number No Image drawing level. A larger value indicates a higher priority.
opacity number No

Image opacity.

0: completely transparent

1: completely opaque

success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101

1. map component is not exist.

2. applicationContext is undefined.

3. context is undefined.

102

1. southwest is undefined.

2. northeast is undefined.

3. src is invalid.

4. src is not image.

5. url is empty.

6. rawFilePath is invalid.

70006601

1. updateGroundOverlay error.

2. no ground overlay.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.updateGroundOverlay({
  id: 1,
  src: 'https://www.example.com/xxx.png', // Replace the example with the actual image resource address.
  bounds: {
    southwest: {
      latitude: 39.7032,
      longitude: 116.2978
    },
    northeast: {
      latitude: 40.1032,
      longitude: 116.6978
    }
  },
  visible: true,
  zIndex: 1,
  opacity: 1,
  success: () => {
    console.info('updateGroundOverlay success');
  },
  fail: (err) => {
    console.error('updateGroundOverlay fail:', err);
  },
  complete: (res) => {
    console.info('updateGroundOverlay complete:', res);
  }
});

[h2]MapContext.removeGroundOverlay

MapContext.removeGroundOverlay(Object object)

Removes an image layer.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
id number Yes Image layer ID.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101 map component is not exist.
70006701

1. removeGroundOverlay error.

2. ground overlay not found.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.removeGroundOverlay({
  id: 1,
  success: () => {
    console.info('removeGroundOverlay success');
  },
  fail: (err) => {
    console.error('removeGroundOverlay fail:', err);
  },
  complete: (res) => {
    console.info('removeGroundOverlay complete:', res);
  }
});

[h2]MapContext.addArc

MapContext.addArc(Object object)

Adds an arc. Either a waypoint or an angle must be set. If both a waypoint and an angle are set, the angle is used. The angle is defined as the angle between the tangent line at the start point and the line from the start point to the end point, measured counterclockwise.

An arc cannot be drawn correctly in the following cases:

  • Neither a waypoint nor an angle is set.

  • The angle is an integer multiple of 180.

  • When no angle is set, two of the start, end, and pass points are the same.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Default Value Mandatory Description
id number - Yes Arc ID.
start LatLng - Yes Start point.
end LatLng - Yes End point.
pass LatLng - No Waypoint.
angle number 0 No Angle, in degrees.
width number 5 No Line width.
color string #000000 No Line color.
success function - No Callback triggered when the API call is successful.
fail function - No Callback triggered when the API call fails.
complete function - No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101 map component is not exist.
102

1. latLng is undefined.

2. latitude is undefined.

3. longitude is undefined.

70006801 arc add failed.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.addArc({
  id: 1,
  start: {
    latitude: 39.7032,
    longitude: 116.2978
  },
  end: {
    latitude: 40.1032,
    longitude: 116.6978
  },
  pass: {
    latitude: 40.1032,
    longitude: 116.2978
  },
  angle: 90,
  width: 5,
  color: '#000000',
  success: () => {
    console.info('addArc success');
  },
  fail: (err) => {
    console.error('addArc fail:', err);
  },
  complete: (res) => {
    console.info('addArc complete:', res);
  }
});

[h2]MapContext.removeArc

MapContext.removeArc(Object object)

Removes an arc.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
id number Yes Arc ID.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
70006901 arc not found.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.removeArc({
  id: 1,
  success: () => {
    console.info('removeArc success');
  },
  fail: (err) => {
    console.error('removeArc fail:', err);
  },
  complete: (res) => {
    console.info('removeArc complete:', res);
  }
});

[h2]MapContext.setBoundary

MapContext.setBoundary(Object object)

Set the display boundary range of the map. This API also limits the minimum integer zoom level of the map.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
southwest LatLng Yes Longitude and latitude of the southwest corner.
northeast LatLng Yes Longitude and latitude of the northeast corner.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error codes

Error Code Error Message
101 map component is not exist.
70007001

1. setBoundary error.

2. southwest and northeast cannot be the same.

3. zoom is undefined.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.setBoundary({
  southwest: {
    latitude: 39.7032,
    longitude: 116.2978
  },
  northeast: {
    latitude: 40.1032,
    longitude: 116.6978
  },
  success: () => {
    console.info('setBoundary success');
  },
  fail: (err) => {
    console.error('setBoundary fail:', err);
  },
  complete: (res) => {
    console.info('setBoundary complete:', res);
  }
});

[h2]MapContext.fromScreenLocation

MapContext.fromScreenLocation(Object object)

Obtains the longitude and latitude of a point on the screen. The coordinate origin is the upper left corner of the map.

Since: 2.0.2

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
x number Yes X coordinate.
y number Yes Y coordinate.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
latitude number Latitude.
longitude number Longitude.

Error codes

Error Code Error Message
101 map component is not exist.
70007101

1. fromScreenLocation error.

2. projection is undefined.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.fromScreenLocation({
  x: 100,
  y: 100,
  success: (res) => {
    console.info('fromScreenLocation success:', res);
  },
  fail: (err) => {
    console.error('fromScreenLocation fail:', err);
  },
  complete: (res) => {
    console.info('fromScreenLocation complete:', res);
  }
});

[h2]Bounds

Longitude and latitude ranges.

Since: 2.0.2

Parameter Type Mandatory Description
southwest LatLng Yes Longitude and latitude of the southwest corner.
northeast LatLng Yes Longitude and latitude of the northeast corner.

[h2]LatLng

Longitude and latitude.

Since: 2.0.2

Parameter Type Mandatory Description
latitude number Yes Latitude.
longitude number Yes Longitude.

[h2]MapContext.eraseLines

MapContext.eraseLines(Object object)

Erases or grays out a line that has been added to the map.

Since: 2.0.2

Parameters

Parameter Type Mandatory Description
lines Object[] Yes Array of line objects to be erased.

Object parameters

Parameter Type Default Value Mandatory Description
id number - Yes Line ID.
index number - Yes Index of the end line to be erased. The erasing range is from line 0 to line index (including both ends). For example, if index is set to 0, line 0 (points[0]→points[1]) is erased.
clear boolean true No The value true indicates that the line is erased, and the value false indicates that the line is grayed out.

Example:

let mapContext = has.createMapContext('mapId');
mapContext.eraseLines({
  lines: [{
    id: 1,
    index: 0,
    clear: true
  }],
  success: () => {
    console.info('eraseLines success');
  },
  fail: (err) => {
    console.error('eraseLines fail:', err);
  },
  complete: (res) => {
    console.info('eraseLines complete:', res);
  }
});