Skip to content

Commit

Permalink
【test】>12走线性offset
Browse files Browse the repository at this point in the history
  • Loading branch information
songyumeng committed Apr 13, 2024
1 parent 1a32a4d commit a53ae1c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class CoordinateSystemService

// 经纬度投影到 Web 墨卡托坐标系
const positionPixels = this.cameraService.projectFlat(
[center[0], center[1]],
[Math.fround(center[0]), Math.fround(center[1])],
Math.pow(2, zoom),
);

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/shaders/projection.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ float project_scale(float meters) {
vec4 project_offset(vec4 offset) {
float dy = offset.y;
dy = clamp(dy, -1., 1.);
vec3 pixels_per_unit = u_PixelsPerDegree;
return vec4(offset.xyz, offset.w);
vec3 pixels_per_unit = u_PixelsPerDegree + u_PixelsPerDegree2 * dy;
return vec4(offset.xyz * pixels_per_unit, offset.w);
}

vec3 project_normal(vec3 normal) {
Expand Down Expand Up @@ -105,9 +105,9 @@ vec4 project_position(vec4 position) {

if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET
|| u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) {
//float X = position.x - u_ViewportCenter.x;
//float Y = position.y - u_ViewportCenter.y;
return project_offset(vec4(position.x, position.y, position.z, position.w));
float X = position.x - u_ViewportCenter.x;
float Y = position.y - u_ViewportCenter.y;
return project_offset(vec4(X, Y, position.z, position.w));
}
if (u_CoordinateSystem < COORDINATE_SYSTEM_LNGLAT + 0.01 && u_CoordinateSystem >COORDINATE_SYSTEM_LNGLAT - 0.01) {
if (u_isMultiCoor) {
Expand Down
12 changes: 7 additions & 5 deletions packages/layers/src/plugins/DataMappingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ export default class DataMappingPlugin implements ILayerPlugin {

// 调整数据兼容 SimpleCoordinates
this.adjustData2SimpleCoordinates(mappedData);
if (this.mapService.map.getZoom() < 12) {

this.adjustData2MapboxCoordinates(mappedData);
}
return mappedData;
}

Expand Down Expand Up @@ -256,12 +258,12 @@ export default class DataMappingPlugin implements ILayerPlugin {
}
}
private project(coord: [number, number], map: Map, TILESIZE: number) {
if (map.getZoom() <= 12 && this.getIsMultiCoor()) {
// if (map.getZoom() <= 12 && this.getIsMultiCoor()) {
return transformOffset(coord, map, TILESIZE);
} else {
const { lng, lat } = map.getCenter();
return transformOffset(coord, map, undefined, [lng, lat]);
}
// } else {
// const { lng, lat } = map.getCenter();
// return transformOffset(coord, map, undefined, [lng, lat]);
// }
}

private getIsMultiCoor() {
Expand Down
18 changes: 15 additions & 3 deletions packages/layers/src/plugins/ShaderUniformPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,23 @@ export default class ShaderUniformPlugin implements ILayerPlugin {
private resetLayerEncodeData(layer: ILayer) {
const map = this.mapService.map;
if (!map || !this.getIsMultiCoor()) return;
this.mapZoom = map.getZoom();
const callback = async () => {
await layer.hooks.init.promise();
const zoom = map.getZoom();
if (zoom <= 12 && this.mapZoom > 12) {
await layer.hooks.init.promise();
this.mapZoom = zoom;
}
if (zoom > 12 && this.mapZoom <= 12) {
await layer.hooks.init.promise();

console.log('beforeRenderData')
this.mapZoom = zoom;
}
};
map.off('move', callback);
map.on('move', callback);

map.off('zoom', callback);
map.on('zoom', callback);
}

public apply(layer: ILayer) {
Expand Down

0 comments on commit a53ae1c

Please sign in to comment.