目录

Map

has.createMapContext

has.createMapContext(string mapId): MapContext

Creates a map context object MapContext.

Since: 1.0.0

Parameters

Name

Type

Default Value

Mandatory

Description

mapId

string

-

Yes

ID of the map component.

Return value

A 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

Note: If network resources are used when this API is called, configure the server domain names in AppGallery Connect.

Parameters

The input parameter is an object. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

iconPath

string

-

No

Icon path, which can be a network path, local path, or code package path.

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Return value of success

Name

Type

Description

longitude

number

Longitude.

latitude

number

Latitude.

Example

let mapContext = has.createMapContext('mapid');
mapContext.getCenterLocation({
  iconPath: '/path/icon.png',
  success: res => {
    console.log('getCenterLocation success, res = ' + JSON.stringify(res));
  },
  fail: () => {
    console.log('getCenterLocation fail');
  }
});

[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. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Return value of success

Name

Type

Description

southwest

Object

Longitude and latitude of the southwest corner.

northeast

Object

Longitude and latitude of the northeast corner.

Return value of southwest

Name

Type

Description

longitude

number

Longitude.

latitude

number

Latitude.

Return value of northeast

Name

Type

Description

longitude

number

Longitude.

latitude

number

Latitude.

Example

let mapContext = has.createMapContext('mapid');
mapContext.getRegion({
  success: res => {
    console.log('getRegion success, res = ' + JSON.stringify(res));
  },
  fail: () => {
    console.log('getRegion fail');
  }
});

[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. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Return value of success

Name

Type

Description

rotate

number

Rotation angle.

Example

let mapContext = has.createMapContext('mapid');
mapContext.getRotate({
  success: res => {
    console.log('getRotate success, rotate = ' + res.rotate);
  },
  fail: () => {
    console.log('getRotate fail');
  }
});

[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. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Return value of success

Name

Type

Description

scale

number

Zoom level.

Example

let mapContext = has.createMapContext('mapid');
mapContext.getScale({
  success: res => {
    console.log('getScale success, scale = ' + res.scale);
  },
  fail: () => {
    console.log('getScale fail');
  }
});

[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. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Return value of success

Name

Type

Description

skew

number

Tilt angle.

Example

let mapContext = has.createMapContext('mapid');
mapContext.getSkew({
  success: res => {
    console.log('getSkew success, skew = ' + res.skew);
  },
  fail: () => {
    console.log('getSkew fail');
  }
});

[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. The following table describes the fields in the object.

Name

Type

Default Value

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 to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Attributes in points

Name

Type

Default Value

Mandatory

Description

longitude

number

-

Yes

Longitude.

latitude

number

-

Yes

Latitude.

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.log('includePoints success');
  },
  fail: () => {
    console.log('includePoints fail');
  }
});

[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

Parameters

The input parameter is an object. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

longitude

number

-

No

Longitude.

latitude

number

-

No

Latitude.

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Example

let mapContext = has.createMapContext('mapid');
mapContext.moveToLocation({
  longitude: 114.2342423,
  latitude: 34.232424232,
  success: () => {
    console.log('moveToLocation success');
  },
  fail: () => {
    console.log('moveToLocation fail');
  }
});

[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. The following table describes the fields in the object.

Name

Type

Default Value

Mandatory

Description

markerId

number

-

Yes

Marker ID, which specifies a unique marker.

destination

Object

-

Yes

Destination point to which the marker is moved.

autoRotate

boolean

-

Yes

Indicates whether to automatically rotate the marker during its movement.

rotate

number

0

No

Rotation angle of the marker.

duration

number

1000

No

Duration of the animation.

animationEnd

function

-

No

Callback function triggered when the animation ends.

success

function

-

No

Callback to be invoked when the API call is successful.

fail

function

-

No

Callback to be invoked when the API call fails.

complete

function

-

No

Callback to be invoked when the API call is complete, regardless of success or failure.

Attributes in destination

Name

Type

Default Value

Mandatory

Description

longitude

number

-

Yes

Longitude.

latitude

number

-

Yes

Latitude.

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.log('translateMarker animationEnd');
  },
  success: () => {
    console.log('translateMarker success');
  },
  fail: () => {
    console.log('translateMarker fail');
  }
});