{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671508873767,"data":{"id":71713116,"title":"6.6.1纹理锚点配置方法","slug":"tlx421","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"
在调用接口com.autonavi.gbl.map.MapView.addLayerTexture添加纹理时,其参数值com.autonavi.gbl.map.layer.model.LayerTexture.anchorType共有以下几个锚点类型:
参数 | 配置值 | 图片上锚点位置 | 纹理相对扎点飘向 |
LayerIconAnchorLeftTop | 0 | 左上角 | 右下飘 |
LayerIconAnchorRightTop | 1 | 右上角 | 左下飘 |
LayerIconAnchorLeftBottom | 2 | 左下角 | 右上飘 |
LayerIconAnchorRightBottom | 3 | 右下角 | 左上漂 |
LayerIconAnchorCenter | 4 | 居中(默认值) | 居中飘 |
LayerIconAnchorBottom | 5 | 中下 | 中上飘 |
LayerIconAnchorCenterTop | 6 | 中上 | 中下飘 |
LayerIconAnchorCenterLeft | 7 | 中左 | 中右飘 |
LayerIconAnchorCenterRight | 8 | 中右 | 中左飘 |
LayerIconAnchorRandomPosition | 9 | 任意比例锚点(设置x_ratio、y_ratio) | |
LayerIconAnchorLeftTopOffset | 10 | 左上角偏移固定offset | 指定边距偏移锚点--用于动态纹理宽高不确定,但锚点与顶点offset是固定的场景 |
LayerIconAnchorRightTopOffset | 11 | 右上角偏移固定offset | |
LayerIconAnchorLeftBottomOffset | 12 | 左下角偏移固定offset | |
LayerIconAnchorRightBottomOffset | 13 | 右下角偏移固定offset |
需要根据纹理使用的图片选择合适的锚点类型。
如果纹理使用的图片不规则或者带有指向性(比如下面的电子眼),则需要通过自定义锚点类型,并且配置x_ratio和y_ratio这两个锚点值,具体获取方法:
1,根据图片建立坐标系xy,图片的左上角作为x和y的0.0值,图片的右下角作为x和y的1.0值
2,寻找图片上显示在底图扎点的位置
3,扎点所在xy坐标系的值,那么这个就是自定义锚点的xy比例值
由上图可以预估x和y的值大概是(0.0, 0.7),这里没有获取到精确值的办法,只能预估看效果再重复调整直到找到最优xy值。
所以该电子眼在样式配置文件(style.json)中的marker_info就是:
"marker_arc_info":\n{\n "anchor":9,\n "x_ratio":0.0,\n "y_ratio":0.7\n}
再举几个例子来加深纹理锚点的坐标的建立和锚点值的获取:
当锚点位置是固定的,但图片大小不固定,可以使用边距偏移值设置锚点:
右飘电子眼对应的锚点配置如下:
"marker_info_guide_camera_right": {\n "anchor":12,\n "x_offset":10,\n "y_offset":21\n }
下面列出各锚点类型如果采用自定义锚点,x_ratio和y_ratio应该配置的值:
锚点类型 | 说明 | 配置值 | 图示(绿色圈位置) | 对应的自定义xy比例值 |
LayerIconAnchorLeftTop | 左上角 | 0 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":0.0, \t"y_ratio":0.0 } | |
LayerIconAnchorRightTop | 右上角 | 1 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":1.0, \t"y_ratio":0.0 } | |
LayerIconAnchorLeftBottom | 左下角 | 2 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":0.0, \t"y_ratio":1.0 } | |
LayerIconAnchorRightBottom | 右下角 | 3 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":1.0, \t"y_ratio":1.0 } | |
LayerIconAnchorCenter | 居中 | 4 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":0.5, \t"y_ratio":0.5 } | |
LayerIconAnchorBottom | 中下 | 5 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":0.5, \t"y_ratio":1.0 } | |
LayerIconAnchorCenterTop | 中上 | 6 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":0.5, \t"y_ratio":0.0 } | |
LayerIconAnchorCenterLeft | 中左 | 7 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":0.0, \t"y_ratio":0.5 } | |
LayerIconAnchorCenterRight | 中右 | 8 | "ters_marker_info": { \t"anchor":9, \t"x_ratio":1.0, \t"y_ratio":0.5 } |