Appearance
地图方法
了解 RobotMap 提供的 API 方法。
使用示例
通过 onMapReady 回调获得 MapApi 实例,该实例包含所有可调用的地图方法。这些方法让你可以主动控制地图行为、查询数据和执行各种操作。
tsx
import { MapApi } from '@ray-js/robot-map'
function MapPage() {
const mapApi = useRef<MapApi>(null)
const handleMapReady = (mapApi: MapApi) => {
mapApi.current = mapApi
}
const handleResetMapView = () => {
mapApi.current?.resetPanZoom()
}
const handleGetCleanZones = async () => {
const zones = await mapApi.current?.getCleanZones()
}
return (
<RobotMap
onMapReady={handleMapReady}
// ... 其他属性
/>
)
}TIP
注意所有地图方法都是异步的Promise,需要使用 await 或 then 来获取结果。
resetPanZoom()
重置地图的平移和缩放状态到初始位置。
类型:
ts
function resetPanZoom(): Promise<void>返回值: Promise<void>
getForbiddenSweepZones()
获取当前地图上所有禁扫区域数据。
类型:
ts
function getForbiddenSweepZones(): Promise<ZoneParam[]>返回值: Promise<ZoneParam[]>
getForbiddenMopZones()
获取当前地图上所有禁拖区域数据。
类型:
ts
function getForbiddenMopZones(): Promise<ZoneParam[]>返回值: Promise<ZoneParam[]>
getCleanZones()
获取当前地图上所有清扫区域数据。
类型:
ts
function getCleanZones(): Promise<ZoneParam[]>返回值: Promise<ZoneParam[]>
getVirtualWalls()
获取当前地图上所有虚拟墙数据。
类型:
ts
function getVirtualWalls(): Promise<VirtualWallParam[]>返回值: Promise<VirtualWallParam[]>
getSpots()
获取当前地图上所有定点清扫数据。
类型:
ts
function getSpots(): Promise<SpotParam[]>返回值: Promise<SpotParam[]>
getEffectiveDividerPoints()
获取分割线有效端点。
类型:
ts
function getEffectiveDividerPoints(): Promise<Point[] | null>返回值: Promise<Point[] | null> | null
getDividerEndPoints()
获取分割线端点。
类型:
ts
function getDividerEndPoints(): Promise<Point[] | null>返回值: Point[] | null
getViewportCenterPoint()
获取当前视口中心点坐标。
类型:
ts
function getViewportCenterPoint(): Promise<Point | null>返回值: Promise<Point[]> | null
getMapCenterPoint()
获取地图中心点坐标。
类型:
ts
function getMapCenterPoint(): Promise<Point | null>返回值: Promise<Point[]> | null
getWallPointsByViewportCenter()
基于视口中心生成虚拟墙端点坐标。
类型:
ts
function getWallPointsByViewportCenter(options?: {
width?: number
direction?: Direction
offsetX?: number
offsetY?: number
}): Promise<Point[]>参数:
options- 配置选项options.width:number- 虚拟墙长度,单位米,默认使用配置中的最小宽度options.direction:Direction- 虚拟墙方向,'horizontal' 或 'vertical',默认为 'horizontal'options.offsetX:number- X方向像素偏移,支持负数,默认为 0options.offsetY:number- Y方向像素偏移,支持负数,默认为 0
返回值: Promise<Point[]>
getForbiddenSweepZonePointsByViewportCenter()
基于视口中心生成禁扫区域顶点坐标。
类型:
ts
function getForbiddenSweepZonePointsByViewportCenter(options?: {
size?: number
offsetX?: number
offsetY?: number
}): Promise<Point[]>参数:
options- 配置选项options.size:number- 区域大小,单位米,默认使用配置中的最小尺寸options.offsetX:number- X方向像素偏移,支持负数,默认为 0options.offsetY:number- Y方向像素偏移,支持负数,默认为 0
返回值: Promise<Point[]>
getForbiddenMopZonePointsByViewportCenter()
基于视口中心生成禁拖区域顶点坐标。
类型:
ts
function getForbiddenMopZonePointsByViewportCenter(options?: {
size?: number
offsetX?: number
offsetY?: number
}): Promise<Point[]>参数:
options- 配置选项options.size:number- 区域大小,单位米,默认使用配置中的最小尺寸options.offsetX:number- X方向像素偏移,支持负数,默认为 0options.offsetY:number- Y方向像素偏移,支持负数,默认为 0
返回值: Promise<Point[]>
getCleanZonePointsByViewportCenter()
类型:
ts
function getCleanZonePointsByViewportCenter(options?: {
size?: number
offsetX?: number
offsetY?: number
}): Promise<Point[]>参数:
options- 配置选项options.size:number- 区域大小,单位米,默认使用配置中的最小尺寸options.offsetX:number- X方向像素偏移,支持负数,默认为 0options.offsetY:number- Y方向像素偏移,支持负数,默认为 0
返回值: Promise<Point[]>
getSpotPointByViewportCenter()
基于视口中心生成定点清扫的点坐标。
类型:
ts
function getSpotPointByViewportCenter(options?: {
offsetX?: number
offsetY?: number
}): Promise<Point>参数:
options- 配置选项options.size:number- 区域大小,单位米,默认使用配置中的最小尺寸options.offsetX:number- X方向像素偏移,支持负数,默认为 0options.offsetY:number- Y方向像素偏移,支持负数,默认为 0
返回值: Promise<Point[]>
snapshot()
当前地图截图。
类型:
ts
function snapshot(): Promise<string>返回值: Promise<string>
snapshotByData()
根据指定的地图数据进行截图。
TIP
静态配置会沿用当前地图的配置。
类型:
ts
function snapshotByData(
data: {
map: string
path?: string
roomProperties?: RoomProperty[]
customElements?: CustomElementParam[]
forbiddenSweepZones?: ZoneParam[]
forbiddenMopZones?: ZoneParam[]
virtualWalls?: VirtualWallParam[]
detectedObjects?: DetectedObjectParam[]
},
runtime?: DeepPartialRuntimeConfig,
): Promise<string>参数:
data- 地图数据对象data.map:string- 地图字符串数据data.path:string- 可选的路径数据data.roomProperties:RoomProperty[]- 可选的房间属性数据data.customElements:CustomElementParam[]- 可选的自定义元素数据data.forbiddenSweepZones:ZoneParam[]- 可选的禁扫区域数据data.forbiddenMopZones:ZoneParam[]- 可选的禁拖区域数据data.virtualWalls:VirtualWallParam[]- 可选的虚拟墙数据data.detectedObjects:DetectedObjectParam[]- 可选的检测物体数据runtime- 可选的运行时配置
返回值: Promise<string>