Appearance
适配器 API(OL · MapLibre)
两个适配器实现同一 MapAdapter 契约(来自 editor-core),把各自的交互归一成引擎命令。引擎/命令 API 见 editor-core API。
MapAdapter 契约
ts
interface MapAdapter {
readonly crs: string;
render(snapshot: EditSnapshot): void; // 核心状态 → 地图渲染
bindInteractions(engine: EditEngine): () => void; // 交互 → 命令,返回解绑
snapCandidates(near: Position, tolPx: number): SnapTarget[];
pixelToCoord(px: [number, number]): Position;
resolutionAt(coord: Position): number; // 地图单位/像素,容差换算
}EditSession.attach(adapter) 会调用 bindInteractions 并订阅 render,返回解绑函数。
OlEditorAdapter(@geoverse/editor-ol)
构造:new OlEditorAdapter(map: ol/Map, options?: OlEditorAdapterOptions)
| 选项 | 类型 | 说明 |
|---|---|---|
crs | string | 工作 CRS,默认取地图视图投影 |
zIndex | number | 编辑图层 z-index,默认 50 |
onSelect | (id: FeatureId | null, additive: boolean) => void | select 模式单击回调(shift 为 additive) |
| 方法 | 签名 | 说明 |
|---|---|---|
setMode | (mode: OlEditorMode) => void | 切换工具模式 |
setSelection | (ids: FeatureId[]) => void | 高亮选择集并刷新顶点句柄 |
setIssues | (issues: ValidationIssue[]) => void | 喂入校验问题以红/橙标记 |
render / bindInteractions / snapCandidates / pixelToCoord / resolutionAt / dispose | 见 MapAdapter | dispose() 移除编辑与手柄图层 |
ts
type OlEditorMode =
| 'select'
| 'move'
| 'transform'
| 'modify'
| 'add-vertex'
| 'delete-vertex'
| 'split'
| 'split-polygon'
| 'merge'
| 'draw-point'
| 'draw-line'
| 'draw-polygon';转出命令(便于直接构造):AddFeaturesCommand、TranslateCommand、RotateCommand、ScaleCommand、MirrorCommand、OffsetCommand、SplitMultiPointCommand、SplitPolygonByLineCommand、MergePointsCommand、MergePolygonsCommand。
LibreEditorAdapter(@geoverse/editor-libre)
构造:new LibreEditorAdapter(map: maplibre/Map, options?: LibreEditorAdapterOptions)
| 选项 | 类型 | 说明 |
|---|---|---|
crs | string | 固定 'EPSG:4326'(MapLibre GeoJSON 即 lng/lat),保留以满足契约 |
onSelect | (id: FeatureId | null, additive: boolean) => void | select 模式单击回调 |
方法与 OlEditorAdapter 一致(setMode / setSelection / setIssues / render / bindInteractions / snapCandidates / pixelToCoord / resolutionAt / dispose)。LibreEditorMode 与 OlEditorMode 同集合。
纯几何助手(自绘渲染用,无 maplibre 依赖):
| 函数 | 来源 | 签名 |
|---|---|---|
collectVertexHandles | editor-core(libre 转出) | (features: EditableFeature[]) => FeatureCollection<Point>(顶点句柄,多边形跳过闭合点;properties 携带 VertexHandleRef) |
moveVertex | editor-libre | (geometry, ref: { ringIndex; index }, to: Position) => Geometry |
toRenderCollection | editor-libre | (features, severityById: Map<FeatureId, 'error' | 'warning'>) => FeatureCollection |
顶点句柄抽取已下沉 editor-core(
collectVertexHandles),OL/MapLibre 两端共用;旧collectVertices已移除。
转出命令同 OL 适配器。
