Skip to content

Commit a53ae1c

Browse files
committed
【test】>12走线性offset
1 parent 1a32a4d commit a53ae1c

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

packages/core/src/services/coordinate/CoordinateSystemService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export default class CoordinateSystemService
157157

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

packages/core/src/shaders/projection.glsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ float project_scale(float meters) {
5151
vec4 project_offset(vec4 offset) {
5252
float dy = offset.y;
5353
dy = clamp(dy, -1., 1.);
54-
vec3 pixels_per_unit = u_PixelsPerDegree;
55-
return vec4(offset.xyz, offset.w);
54+
vec3 pixels_per_unit = u_PixelsPerDegree + u_PixelsPerDegree2 * dy;
55+
return vec4(offset.xyz * pixels_per_unit, offset.w);
5656
}
5757

5858
vec3 project_normal(vec3 normal) {
@@ -105,9 +105,9 @@ vec4 project_position(vec4 position) {
105105

106106
if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET
107107
|| u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) {
108-
//float X = position.x - u_ViewportCenter.x;
109-
//float Y = position.y - u_ViewportCenter.y;
110-
return project_offset(vec4(position.x, position.y, position.z, position.w));
108+
float X = position.x - u_ViewportCenter.x;
109+
float Y = position.y - u_ViewportCenter.y;
110+
return project_offset(vec4(X, Y, position.z, position.w));
111111
}
112112
if (u_CoordinateSystem < COORDINATE_SYSTEM_LNGLAT + 0.01 && u_CoordinateSystem >COORDINATE_SYSTEM_LNGLAT - 0.01) {
113113
if (u_isMultiCoor) {

packages/layers/src/plugins/DataMappingPlugin.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ export default class DataMappingPlugin implements ILayerPlugin {
201201

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

205206
this.adjustData2MapboxCoordinates(mappedData);
207+
}
206208
return mappedData;
207209
}
208210

@@ -256,12 +258,12 @@ export default class DataMappingPlugin implements ILayerPlugin {
256258
}
257259
}
258260
private project(coord: [number, number], map: Map, TILESIZE: number) {
259-
if (map.getZoom() <= 12 && this.getIsMultiCoor()) {
261+
// if (map.getZoom() <= 12 && this.getIsMultiCoor()) {
260262
return transformOffset(coord, map, TILESIZE);
261-
} else {
262-
const { lng, lat } = map.getCenter();
263-
return transformOffset(coord, map, undefined, [lng, lat]);
264-
}
263+
// } else {
264+
// const { lng, lat } = map.getCenter();
265+
// return transformOffset(coord, map, undefined, [lng, lat]);
266+
// }
265267
}
266268

267269
private getIsMultiCoor() {

packages/layers/src/plugins/ShaderUniformPlugin.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ export default class ShaderUniformPlugin implements ILayerPlugin {
3939
private resetLayerEncodeData(layer: ILayer) {
4040
const map = this.mapService.map;
4141
if (!map || !this.getIsMultiCoor()) return;
42+
this.mapZoom = map.getZoom();
4243
const callback = async () => {
43-
await layer.hooks.init.promise();
44+
const zoom = map.getZoom();
45+
if (zoom <= 12 && this.mapZoom > 12) {
46+
await layer.hooks.init.promise();
47+
this.mapZoom = zoom;
48+
}
49+
if (zoom > 12 && this.mapZoom <= 12) {
50+
await layer.hooks.init.promise();
51+
52+
console.log('beforeRenderData')
53+
this.mapZoom = zoom;
54+
}
4455
};
45-
map.off('move', callback);
46-
map.on('move', callback);
56+
57+
map.off('zoom', callback);
58+
map.on('zoom', callback);
4759
}
4860

4961
public apply(layer: ILayer) {

0 commit comments

Comments
 (0)