Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Mapbox/Maplibre 20 层级以上数据偏移问题 #2416

Merged
merged 26 commits into from
Apr 30, 2024
Merged

Conversation

lvisei
Copy link
Member

@lvisei lvisei commented Apr 19, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复

🔗 相关背景

分别用 Mapbox 和 L7 的图层 API 绘制线数据,大于 20 级时,绘制的数据出现明显偏移现象。

image

const scene = new Scene({
  id: "map",
  renderer: options.renderer,
  map: new Mapbox({
    style:
      "https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json",
    center: [121.434765, 31.256735],
    zoom: 14.83,
    maxZoom: 23.9,
  }),
});
const geoData = {
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      properties: {},
      geometry: {
        type: "LineString",
        coordinates: [
          [120.10121458655186, 30.269329295915544],
          [120.10122467185921, 30.2693341645727],
          [120.10123176240315, 30.269323019911795],
        ],
      },
    },
  ],
};

const source = new Source(geoData);
const layer = new LineLayer({ blend: "normal", autoFit: true })
  .source(source)
  .size(2)
  .shape("line")
  .color("#f00")
  .style({
    opacity: 1,
  });

scene.on("loaded", () => {
  scene.addLayer(layer);
});

if (scene.getType() === "mapbox") {
  const baseMap = scene.map;
  baseMap.on("load", () => {
    baseMap.addSource("route", {
      type: "geojson",
      data: geoData,
    });
    baseMap.addLayer({
      id: "route",
      type: "line",
      source: "route",
      layout: {
        "line-join": "round",
        "line-cap": "round",
      },
      paint: {
        "line-color": "#0083FE",
        "line-width": 2,
      },
    });
  });
}

偏移的原因出现在:经纬度数据传入 shader 自动转成 32 浮点数,精度丢失。

💡 解决方案

经纬度数据拆为双 32 浮点数,shader 中投影将低位经纬度数据传入,升级之后的project_position 逻辑

vec4 project_position(vec4 position, vec2 position64xyLow) {
  if (u_CoordinateSystem < COORDINATE_SYSTEM_LNGLAT + 0.01 && u_CoordinateSystem >COORDINATE_SYSTEM_LNGLAT - 0.01) {
    return vec4(
      project_mercator_(position.xy) * WORLD_SCALE * u_ZoomScale,
      project_size(position.z),
      position_world.w
    );
  }

  if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
    // Subtract high part of 64 bit value. Convert remainder to float32, preserving precision.
    float X = position.x - u_ViewportCenter.x;
    float Y = position.y - u_ViewportCenter.y;
    return project_offset(vec4(X + position64xyLow.x, Y + position64xyLow.y, position.z, position.w));
  }

  return position;
}

vec4 project_position(vec4 position) {
  return project_position(position, ZERO_64_XY_LOW);
}

再完成 shader 里的修改后,用 Mapbox 和 L7 的图层 API 绘制线图层效果一致,Mapbox 的图层在下面。

image

事项

  • 解决 shader 全局属性超过 16 个情况,重构 shader 属性索引定义逻辑,完成所有图层迁移
  • 完成需要高精度的图层迁移

高精度图层迁移

  • PointLayer
    • fill
    • billboard_point
    • extrude
    • fillImage
    • image
    • normal
    • radar
    • text
    • earthExtrude
    • earthFill
  • LineLayer
    • line
    • simple_line
    • arc
    • arc3d
    • flow
    • great_circle
    • wall
  • PolygonLayer
    • extrude
    • extrusion
    • fill
    • ocean
    • water
  • HeatmapLayer
    • heatmap
    • grid
    • grid3d
    • hexagon
  • GeometryLayer
  • CityBuildingLayer
  • ImageLayer
  • RaterLayer
    • raster
    • rasterRgb
    • rasterTerrainRgb
  • wind

其他问题修复

  • 修复点图层部分 shape 中心点计算有误
  • 修复立体面图层光照计算有误

@lvisei
Copy link
Member Author

lvisei commented Apr 25, 2024

其他问题记录

  1. regl 与 device 抗锯齿不一致
devise regl

image

image

@lvisei lvisei changed the base branch from fix/data-shake to beta April 25, 2024 14:54
@lvisei
Copy link
Member Author

lvisei commented Apr 25, 2024

/update-snapshots

github-actions bot and others added 2 commits April 25, 2024 23:40
Co-authored-by: lvisei <26923747+lvisei@users.noreply.github.com>
@lvisei
Copy link
Member Author

lvisei commented Apr 25, 2024

/update-snapshots

Co-authored-by: lvisei <26923747+lvisei@users.noreply.github.com>
@lvisei lvisei changed the title [WIP]fix: Mapbox/Maplibre 20 层级以上数据偏移问题 fix: Mapbox/Maplibre 20 层级以上数据偏移问题 Apr 26, 2024
@lvisei lvisei merged commit 0913661 into beta Apr 30, 2024
8 checks passed
@lvisei lvisei deleted the fix/mapbox-shake branch April 30, 2024 07:07
This was referenced May 6, 2024
lvisei added a commit that referenced this pull request Jun 11, 2024
* refactor: 重构高德地图 V2 以视口进行同步 (#2387)

* refactor: amap next

* fix: getMinZoom

* refactor: base map

* fix: source update 事件访问图层初始化未完成

* fix: 新版高德大于 21  级别抖动问题

* fix: Mapbox/Maplibre 20 层级以上数据偏移问题 (#2416)

* fix: fix line data offset in mapbox

* refactor: 完成点线面图层属性索引重构

* refactor: 完成 citybuliding\earth\geometry\heatmap 图层属性索引重构

* refactor: 完成 image/ raster/wind 图层属性索引重构

* refactor: 标记最大索引

* fix: line layer data shake

* refactor: 自定义开启双精度属性

* fix: map type

* fix: amap support three

* refactor: 移除不必要的剔除逻辑

* fix: 修复面图层光照计算

* fix: type EventEmitter

* fix: mapbox 下部分面数据图层绘制异常 (#2453)

* fix: mapbox 下部分面数据图层绘制异常

* fix: 3d extrude polygon layer

* fix: 修复 WebGPU 模式渲染问题 (#2450)

* fix: mapbox 线图层的贴图变形 (#2474)

* fix: mapbox 线图层的贴图变形

* fix: 修复热力蜂窝图层渲染空白 (#2500)

* fix: 修复热力蜂窝图层渲染空白

* fix: 无地图与 MapLibre 模式移动 Marker 出错 (#2509)

* fix: marker 拖动报错

* fix: 在 WebGL2 拾取事件冒泡延迟问题 (#2511)

* fix: 在 WebGL2 拾取事件冒泡延迟问题

* fix: 天地图 setCenter 方法缺失 (#2513)

* fix: 天地图 setCenter 方法缺失

* fix: 修复在 Map 上使用组件事件穿透到图层上的问题 (#2518)

* fix: 修复在 Map 上使用组件事件穿透到图层上的问题

* fix: 解决 GeometryLayer 在不同底图上的渲染不一致情况 (#2523)

* fix: 解决 GeometryLayer 在不同底图上的渲染不一致情况

* fix: 统一地形高度

* refactor: 升级新版一方地图交互事件机制,解决抖动问题 (#2521)

* refactor: 升级新版地图交互事件机制

* refactor: 默认升级 MapNext 至 maplibre-gl-js@4.3.2

* fix: 顶点着色器与片元着色器 varying 变量顺序不一致 (#2527)

* fix: 修复 bindings 缓存在 WebGPU 的问题 (#2526)

* fix: 修复 bindings 缓存在 WebGPU 的问题

---------

Co-authored-by: lvisei <26923747+lvisei@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants