has.createMapContext(string mapId): MapContext
创建map上下文MapContext对象。
起始版本: 1.0.0
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| mapId | string | 是 | map组件的id。 |
返回值:
返回MapContext对象。
示例:
let mapContext = has.createMapContext('mapId'); MapContext.getCenterLocation(Object object)
获取当前地图中心的经纬度。返回的是gcj02坐标系坐标。
起始版本: 1.0.0
注意事项: 在调用此接口时如果使用网络资源,需要先完成配置服务器域名。
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| iconPath | string | 否 | 图标路径,支持网络路径、本地路径、代码包路径。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| longitude | number | 经度。 |
| latitude | number | 纬度。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | fail to get center position. |
| 70000301 | 1. getCenterLocation error. 2. iconPath is not exist. |
示例:
let mapContext = has.createMapContext('mapId');
mapContext.getCenterLocation({
iconPath: '/path/icon.png', // 此处仅为样例,请开发者更换为可用图片资源地址
success: (res) => {
console.info('getCenterLocation success, res:', res);
},
fail: (err) => {
console.error('getCenterLocation fail, err:', err);
},
complete: (res) => {
console.info('getCenterLocation complete, res:', res);
}
}); MapContext.getRegion(Object object)
获取当前地图的视野范围。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| southwest | Object | 西南角经纬度。 |
| northeast | Object | 东北角经纬度。 |
southwest返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| longitude | number | 经度。 |
| latitude | number | 纬度。 |
northeast返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| longitude | number | 经度。 |
| latitude | number | 纬度。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | 1. map component is not exist. 2. fail to get center position. |
| 70000401 | 1. fail to get current region. 2. getRegion error. |
示例:
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);
}
}); MapContext.getRotate(Object object)
获取当前地图的旋转角。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| rotate | number | 旋转角。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | 1. map component is not exist. 2. fail to get center position. |
| 70000501 | 1. fail to get rotate. 2. getRotate error. |
示例:
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);
}
}); MapContext.getScale(Object object)
获取当前地图的缩放级别。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| scale | number | 缩放值。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | 1. map component is not exist. 2. fail to get center position. |
| 70000601 | 1. fail to get scale. 2. getScale error. |
示例:
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);
}
}); MapContext.getSkew(Object object)
获取当前地图的倾斜角。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| skew | number | 倾斜角。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | 1. map component is not exist. 2. fail to get center position. |
| 70000701 | 1. fail to get skew 2. getSkew error. |
示例:
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);
}
}); MapContext.includePoints(Object object)
缩放视野使所有输入的坐标点都在可视范围内。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| points | Array<Object> | 是 | 要显示在可视区域内的坐标点列表。 |
| padding | Array<number> | 否 | 坐标点形成的矩形边缘到地图边缘的距离,单位:px。格式为[上,右,下,左]。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
points属性:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| longitude | number | 是 | 经度。 |
| latitude | number | 是 | 纬度。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 102 | padding is invalid, length must be 4. |
| 70000801 | 1. includePoints error. |
示例:
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);
}
}); MapContext.moveToLocation(Object object)
将地图中心移至当前定位点,此时需设置地图组件show-location为true。
起始版本: 1.0.0
需要权限:
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| longitude | number | 否 | 经度。 |
| latitude | number | 否 | 纬度。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 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. |
示例:
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);
}
}); MapContext.translateMarker(Object object)
平移marker,带动画。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| markerId | number | - | 是 | 指定marker。 |
| destination | Object | - | 是 | 指定marker移动到的目标点。 |
| autoRotate | boolean | - | 是 | 移动过程中是否自动旋转marker。 |
| rotate | number | 0 | 否 | marker的旋转角度。 |
| duration | number | 1000 | 否 | 动画持续时长。 |
| animationEnd | function | - | 否 | 动画结束回调函数。 |
| success | function | - | 否 | 接口调用成功的回调函数。 |
| fail | function | - | 否 | 接口调用失败的回调函数。 |
| complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
destination属性:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| longitude | number | 是 | 经度。 |
| latitude | number | 是 | 纬度。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 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. |
示例:
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);
}
}); MapContext.toScreenLocation(Object object)
获取经纬度对应的屏幕坐标。坐标原点为地图左上角。
起始版本: 1.0.18
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| latitude | number | 是 | 纬度。 |
| longitude | number | 是 | 经度。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| x | number | x坐标值。在ASCF运行时2.0.1版本之前,单位:px;2.0.1及以上版本,单位:vp。 |
| y | number | y坐标值。在ASCF运行时2.0.1版本之前,单位:px;2.0.1及以上版本,单位:vp。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | 1. projection is not exist. 2. map component is not exist. |
| 70005001 | toScreenLocation error. |
示例:
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);
}
}); MapContext.setLocMarkerIcon(Object object)
设置定位点图标。支持网络路径、本地路径、代码包路径。
起始版本: 1.0.18
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| iconPath | string | 是 | 图标路径,支持网络路径、本地路径、代码包路径。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 102 | setLocMarkerIcon fail, iconPath cannot be empty. |
| 70005201 | setLocMarkerIcon error. |
示例:
let mapContext = has.createMapContext('mapId');
mapContext.setLocMarkerIcon({
iconPath: '/path/icon.png', // 此处仅为样例,请开发者更换为可用图片资源地址
success: () => {
console.info('setLocMarkerIcon success');
},
fail: (err) => {
console.error('setLocMarkerIcon fail, err:', err);
},
complete: (res) => {
console.info('setLocMarkerIcon complete, res:', res);
}
}); MapContext.moveAlong(Object object)
沿指定路径移动marker。用于轨迹回放等场景。
起始版本: 1.0.18
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| markerId | number | - | 是 | 指定marker。 |
| path | Array | - | 是 | 移动路径的坐标串,坐标点格式 {longitude, latitude}。 |
| autoRotate | boolean | true | 否 | 根据路径方向自动改变marker的旋转角度。 |
| isMapMoving | boolean | false | 否 | 是否跟随动画移动。 |
| color | string | #0A59F7CC | 否 | 轨迹颜色。 |
| width | number | 10 | 否 | 轨迹宽度。 |
| duration | number | - | 是 | 平滑移动的时间,单位:ms。最小值为100,当取值小于100时,则设值为5000。 |
| success | function | - | 否 | 接口调用成功的回调函数。 |
| fail | function | - | 否 | 接口调用失败的回调函数。 |
| complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 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. |
示例:
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, // 坐标数组
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);
}
}); MapContext.setCenterOffset(Object object)
设置地图中心点偏移。向后向下为增长,屏幕比例范围(0.25~0.75),默认偏移为[0.5, 0.5]。
起始版本: 1.0.18
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| offset | Array | 是 | 偏移量,两位数组。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 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. |
示例:
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);
}
}); MapContext.addMarkers(Object object)
添加marker。
起始版本: 1.0.18
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| markers | Array | - | 是 | 同传入map组件的marker属性。 |
| clear | boolean | false | 否 | 是否先清空地图上所有marker。 |
| success | function | - | 否 | 接口调用成功的回调函数。 |
| fail | function | - | 否 | 接口调用失败的回调函数。 |
| complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 102 | marker cannot be empty. |
| 70005401 | addMarkers error. |
示例:
let mapContext = has.createMapContext('mapId');
mapContext.addMarkers({
markers: xxx, // marker数组
success: () => {
console.info('addMarkers success');
},
fail: (err) => {
console.error('addMarkers fail, err:', err);
},
complete: (res) => {
console.info('addMarkers complete, res:', res);
}
}); MapContext.removeMarkers(Object object)
移除marker。
起始版本: 1.0.18
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| markerIds | Array | 是 | marker的id集合。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | 1. removeMarkers markers empty. 2. map component is not exist. |
| 102 | removeMarkers markerIds err, ids are not in markers. |
| 70005501 | removeMarkers error. |
示例:
let mapContext = has.createMapContext('mapId');
mapContext.removeMarkers({
markerIds: [1000], // makerId数组
success: () => {
console.info('removeMarkers success');
},
fail: (err) => {
console.error('removeMarkers fail, err:', err);
},
complete: (res) => {
console.info('removeMarkers complete, res:', res);
}
}); MapContext.addGroundOverlay(Object object)
添加图片图层,图片会随着地图缩放而缩放。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| id | number | - | 是 | 图片图层id。 |
| src | string | - | 是 | 图片路径,支持网络路径、本地路径、代码包路径。 |
| bounds | Bounds | - | 是 | 图片覆盖的经纬度范围。 |
| visible | boolean | true | 否 | 是否可见。 |
| zIndex | number | 1 | 否 | 图片绘制层级,值越大优先级越高。 |
| opacity | number | 1 | 否 | 图片透明度。 0:完全透明。 1:完全不透明。 |
| success | function | - | 否 | 接口调用成功的回调函数。 |
| fail | function | - | 否 | 接口调用失败的回调函数。 |
| complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 70006501 | 1. addGroundOverlay error. 2. already have ground overlay. 3. ground overlay add failed. |
示例:
let mapContext = has.createMapContext('mapId');
mapContext.addGroundOverlay({
id: 1,
src: 'https://www.example.com/xxx.png', // 此处仅为样例,请开发者更换为可用图片资源地址
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);
}
}); MapContext.updateGroundOverlay(Object object)
更新图片图层。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| id | number | 是 | 图片图层id。 |
| src | string | 是 | 图片路径,支持网络路径、本地路径、代码包路径。 |
| bounds | Bounds | 是 | 图片覆盖的经纬度范围。 |
| visible | boolean | 否 | 是否可见。 |
| zIndex | number | 否 | 图片绘制层级,值越大优先级越高。 |
| opacity | number | 否 | 图片透明度。 0:完全透明。 1:完全不透明。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 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. |
示例:
let mapContext = has.createMapContext('mapId');
mapContext.updateGroundOverlay({
id: 1,
src: 'https://www.example.com/xxx.png', // 此处仅为样例,请开发者更换为可用图片资源地址
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);
}
}); MapContext.removeGroundOverlay(Object object)
移除图片图层。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| id | number | 是 | 图片图层id。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 70006701 | 1. removeGroundOverlay error. 2. ground overlay not found. |
示例:
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);
}
}); MapContext.addArc(Object object)
添加弧线。途经点与夹角必须设置一个。同时设置途经点和夹角时,以夹角角度为准。夹角定义为起点到终点,与起点外切线逆时针旋转的角度。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| id | number | - | 是 | 弧线id。 |
| start | LatLng | - | 是 | 起始点。 |
| end | LatLng | - | 是 | 终点。 |
| pass | LatLng | - | 否 | 途经点。 |
| angle | number | 0 | 否 | 夹角角度,单位:度。 |
| width | number | 5 | 否 | 线宽。 |
| color | string | #000000 | 否 | 线的颜色。 |
| success | function | - | 否 | 接口调用成功的回调函数。 |
| fail | function | - | 否 | 接口调用失败的回调函数。 |
| complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 102 | 1. latLng is undefined. 2. latitude is undefined. 3. longitude is undefined. |
| 70006801 | arc add failed. |
示例:
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);
}
}); MapContext.removeArc(Object object)
删除弧线。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| id | number | 是 | 弧线id。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 70006901 | arc not found. |
示例:
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);
}
}); MapContext.setBoundary(Object object)
设置地图的显示边界范围。此接口同时会限制地图的最小缩放整数级别。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| southwest | LatLng | 是 | 西南角经纬度。 |
| northeast | LatLng | 是 | 东北角经纬度。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 70007001 | 1. setBoundary error. 2. southwest and northeast cannot be the same. 3. zoom is undefined. |
示例:
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);
}
}); MapContext.fromScreenLocation(Object object)
获取屏幕上的点对应的经纬度,坐标原点为地图左上角。
起始版本: 2.0.2
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| x | number | 是 | x坐标值。 |
| y | number | 是 | y坐标值。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
success返回值:
| 参数 | 类型 | 描述 |
|---|---|---|
| latitude | number | 纬度。 |
| longitude | number | 经度。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 101 | map component is not exist. |
| 70007101 | 1. fromScreenLocation error. 2. projection is undefined. |
示例:
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);
}
}); MapContext.eraseLines(Object object)
擦除或置灰已添加到地图中的线段。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| lines | Object[] | 是 | 要擦除的线段Object数组。 |
Object参数:
| 参数 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
| id | number | - | 是 | 线段的id。 |
| index | number | - | 是 | 要擦除的终止线段索引,擦除范围为第0条到第index条线段(包含两端),如:index = 0擦除第0条线段(points[0]→points[1])。 |
| clear | boolean | true | 否 | 为true时擦除,false时置灰。 |
示例:
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);
}
});