Appearance
自定义渲染
CustomRenderer
com.sfmap.api.maps.CustomRenderer
自定义 OpenGL ES 渲染回调接口(基于 MapLibre CustomLayerHost)。实现此接口后,通过 MapController.setCustomRenderer(CustomRenderer) 或 MapController.addCustomRenderer(CustomRenderer) 注册,回调在 MapLibre 渲染线程、GL context active 时触发。业务可在 onRender(CustomRenderParams) 中直接发起 GLES2/3 draw call。
资源生命周期:onInitialize() 获取的 GL 资源必须在 onDeinitialize() 释放;GL context 丢失时 onContextLost() 被调用(不经过 onDeinitialize()),随后会再次 onInitialize() 重建。
| 方法 | 说明 |
|---|---|
void onInitialize() | GL context 已 active,首帧前调用。用于编译 shader、创建 buffer 等 GL 资源。 |
void onRender(CustomRenderParams params) | 每帧回调,直接发 GLES2/3 draw call。params 携带当前相机与投影参数。 |
void onContextLost() | GL context 丢失,释放所有 GL 资源;随后会再次调用 onInitialize() 重建。 |
void onDeinitialize() | layer 移除/销毁时调用,释放所有资源。可能在未经 onInitialize() 的情况下被调用。 |
ExtralBaseDraw
com.sfmap.api.maps.ExtralBaseDraw
自绘制图层基类(抽象)。新 SDK 中不再走 OpenGL 固定管线,而是作为"便捷覆盖物构造器":子类持有一组图形配置,通过 addToMap(MapController) 转成底层 overlay(Polyline/Polygon/Circle/Arc/Text/GroundOverlay)真正渲染。onDraw() 语义为"提交/刷新本次绘制配置到底层 overlay":首次调用创建底层 overlay 并 addToMap;后续调用刷新已变字段。通过 MapController.addExtralDraw 添加。
| 方法 | 说明 |
|---|---|
abstract void onDraw() | 每帧绘制回调。首次调用创建底层 overlay 并 addToMap;后续调用刷新已变字段到底层 overlay。 |
void addToMap(MapController controller) | 添加到地图(显式入口,等价于 onDraw 首次)。注入 MapController 后调用 onDraw()。 |
void remove() | 从地图移除底层 overlay。 |
boolean isAdded() | 是否已添加到地图(底层 overlay 是否存在)。 |
void setVisible(boolean visible) | 设置可见性。已添加时刷新到 overlay。 |
boolean isVisible() | 获取可见性。 |
void setZIndex(float zIndex) | 设置 Z 轴层级。已添加时同步到 overlay。 |
float getZIndex() | 获取 Z 轴层级。 |
ExtralDrawPolyline
com.sfmap.api.maps.ExtralDrawPolyline extends ExtralBaseDraw
自定义渲染:Polyline 绘制辅助类。内部转为 PolylineImpl(LineLayer 渲染)。设置字段后调用 onDraw() 或 addToMap(MapController) 提交到地图。
构造方法:
| 方法 | 说明 |
|---|---|
ExtralDrawPolyline(MapView mapView) | 兼容老 SDK 构造签名,内部忽略 mapView,实际 controller 由 addToMap 注入。 |
| 方法 | 说明 |
|---|---|
void onDraw() | 提交/刷新折线配置到底层 PolylineImpl:首次创建并 addToMap,后续刷新 points/color/width/dottedLine/geodesic/transparency/visible/zIndex。 |
void setPoints(List<LatLng> points) | 设置折线顶点列表。已添加时刷新到 overlay。 |
void setColor(int color) | 设置线颜色。已添加时刷新到 overlay。 |
void setWidth(float width) | 设置线宽。已添加时刷新到 overlay。 |
void setDottedLine(boolean dottedLine) | 是否虚线。已添加时刷新到 overlay。 |
void setGeodesic(boolean geodesic) | 是否大地线(测地线)。已添加时刷新到 overlay。 |
void setTransparency(float transparency) | 设置透明度。已添加时刷新到 overlay。 |
ExtralDrawPolygon
com.sfmap.api.maps.ExtralDrawPolygon extends ExtralBaseDraw
自定义渲染:Polygon 绘制辅助类。内部转为 PolygonImpl(FillLayer + LineLayer 渲染)。设置字段后调用 onDraw() 或 addToMap(MapController) 提交到地图。
构造方法:
| 方法 | 说明 |
|---|---|
ExtralDrawPolygon(MapView mapView) | 兼容老 SDK 构造签名,内部忽略 mapView,实际 controller 由 addToMap 注入。 |
| 方法 | 说明 |
|---|---|
void onDraw() | 提交/刷新多边形配置到底层 PolygonImpl:首次创建并 addToMap,后续刷新 points/holes/fillColor/strokeColor/strokeWidth/visible/zIndex。 |
void setPoints(List<LatLng> points) | 设置多边形外边界顶点列表。已添加时刷新到 overlay。 |
void setHoles(List<List<LatLng>> holes) | 设置多边形镂空洞列表。已添加时刷新到 overlay。 |
void setFillColor(int fillColor) | 设置填充颜色。已添加时刷新到 overlay。 |
void setStrokeColor(int strokeColor) | 设置描边颜色。已添加时刷新到 overlay。 |
void setStrokeWidth(float strokeWidth) | 设置描边宽度。已添加时刷新到 overlay。 |
ExtralDrawCircle
com.sfmap.api.maps.ExtralDrawCircle extends ExtralBaseDraw
自定义渲染:Circle 绘制辅助类。内部转为 CircleImpl(FillLayer + LineLayer 渲染)。设置字段后调用 onDraw() 或 addToMap(MapController) 提交到地图。
构造方法:
| 方法 | 说明 |
|---|---|
ExtralDrawCircle(MapView mapView) | 兼容老 SDK 构造签名,内部忽略 mapView,实际 controller 由 addToMap 注入。 |
| 方法 | 说明 |
|---|---|
void onDraw() | 提交/刷新圆形配置到底层 CircleImpl:首次创建并 addToMap,后续刷新 center/radius/strokeWidth/strokeColor/fillColor/visible/zIndex。center 为 null 时不绘制。 |
void setCenter(LatLng center) | 设置圆心经纬度。已添加时刷新到 overlay。 |
void setRadius(double radius) | 设置半径(米)。已添加时刷新到 overlay。 |
void setFillColor(int fillColor) | 设置填充颜色。已添加时刷新到 overlay。 |
void setStrokeColor(int strokeColor) | 设置描边颜色。已添加时刷新到 overlay。 |
void setStrokeWidth(float strokeWidth) | 设置描边宽度。已添加时刷新到 overlay。 |
ExtralDrawArc
com.sfmap.api.maps.ExtralDrawArc extends ExtralBaseDraw
自定义渲染:Arc 绘制辅助类。内部转为 GenericOverlayImpl(ARC 类型,LineLayer 渲染)。由三点(起点/途经点/终点)定圆采样 64 段生成弧线点序列。设置字段后调用 onDraw() 或 addToMap(MapController) 提交到地图。
构造方法:
| 方法 | 说明 |
|---|---|
ExtralDrawArc(MapView mapView) | 兼容老 SDK 构造签名,内部忽略 mapView,实际 controller 由 addToMap 注入。 |
| 方法 | 说明 |
|---|---|
void onDraw() | 由三点定圆采样弧线点序列(经 mapController.buildArcPoints),首次创建 GenericOverlayImpl(ARC) 并 addToMap,后续刷新 points/color/width/visible/zIndex。start 或 end 为 null 时不绘制。 |
void setPoints(LatLng start, LatLng passed, LatLng end) | 设置圆弧三点:起点、途经点、终点。已添加时刷新到 overlay。 |
void setStrokeColor(int strokeColor) | 设置弧线颜色。已添加时刷新到 overlay。 |
void setWidth(float width) | 设置弧线宽度。已添加时刷新到 overlay。 |
ExtralDrawText
com.sfmap.api.maps.ExtralDrawText extends ExtralBaseDraw
自定义渲染:Text 绘制辅助类。内部转为 GenericOverlayImpl(TEXT 类型,SymbolLayer 渲染)。设置字段后调用 onDraw() 或 addToMap(MapController) 提交到地图。
构造方法:
| 方法 | 说明 |
|---|---|
ExtralDrawText(MapView mapView) | 兼容老 SDK 构造签名,内部忽略 mapView,实际 controller 由 addToMap 注入。 |
| 方法 | 说明 |
|---|---|
void onDraw() | 提交/刷新文本配置到底层 GenericOverlayImpl(TEXT):首次创建并 addToMap,后续刷新 text/position/textColor/fontSize/rotation/backgroundColor/align/visible/zIndex。position 或 text 为 null 时不绘制。 |
void setText(String text) | 设置文本内容。已添加时刷新到 overlay。 |
void setPosition(LatLng position) | 设置文本地理坐标。已添加时刷新到 overlay。 |
void setTextColor(int textColor) | 设置文字颜色。已添加时刷新到 overlay。 |
void setFontSize(float fontSize) | 设置字号。已添加时刷新到 overlay。 |
void setRotation(float rotation) | 设置旋转角度。已添加时刷新到 overlay。 |
void setBackgroundColor(int backgroundColor) | 设置背景色。已添加时刷新到 overlay。 |
void setAlign(int align) | 设置对齐方式(见 TextOptions.ALIGN_CENTER 等)。已添加时刷新到 overlay。 |
ExtralDrawBitmap
com.sfmap.api.maps.ExtralDrawBitmap extends ExtralBaseDraw
自定义渲染:Bitmap 绘制辅助类。内部转为 GroundOverlayImpl(ImageSource + RasterLayer 渲染)。设置字段后调用 onDraw() 或 addToMap(MapController) 提交到地图。位置可用 setPosition(LatLng) + setDimensions(float, float)(经纬度+米),或 setBounds(LatLngBounds) 直接指定边界。
构造方法:
| 方法 | 说明 |
|---|---|
ExtralDrawBitmap(MapView mapView) | 兼容老 SDK 构造签名,内部忽略 mapView,实际 controller 由 addToMap 注入。 |
| 方法 | 说明 |
|---|---|
void onDraw() | 提交/刷新位图配置到底层 GroundOverlayImpl:首次创建并 addToMap,后续刷新 bitmap/position/dimensions/bounds/bearing/transparency/visible/zIndex。bitmap 为 null 时不绘制。bounds 优先于 position+dimensions。 |
void setBitmap(Bitmap bitmap) | 设置位图。已添加时刷新到 overlay。 |
void setPosition(LatLng position) | 设置锚点经纬度(配合 setDimensions 使用)。已添加时刷新到 overlay。 |
void setDimensions(float width, float height) | 设置宽高(米,配合 setPosition 使用)。已添加时刷新到 overlay。 |
void setBounds(LatLngBounds bounds) | 设置地理边界(优先于 position+dimensions)。已添加时刷新到 overlay。 |
void setBearing(float bearing) | 设置旋转方位角。已添加时刷新到 overlay。 |
void setTransparency(float transparency) | 设置透明度。已添加时刷新到 overlay。 |
void setAnchor(float anchorU, float anchorV) | 设置锚点比例。当前 GroundOverlay 无锚点 API,保留字段暂不生效。 |
