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

v2.21.1以上版本,地图设置为无底图模式时,获取经纬度的控件会显示(0,0) #2385

Closed
Dreammy23 opened this issue Apr 8, 2024 · 10 comments · Fixed by #2436
Assignees

Comments

@Dreammy23
Copy link
Contributor

问题描述

最新版本的经纬度控件在无底图模式下无法正确获取坐标

重现链接

No response

重现步骤

No response

预期行为

我期望看到坐标随鼠标移动正常展示

平台

No response

屏幕截图或视频(可选)

image

补充说明(可选)

No response

@antvis antvis deleted a comment from github-actions bot Apr 8, 2024
@lvisei
Copy link
Member

lvisei commented Apr 11, 2024

L7 研发环境调试正常

image

打包发布后,业务线上使用都会显示 (0,0)

可能是打包编译时,代码出现的问题?

@lvisei
Copy link
Member

lvisei commented Apr 11, 2024

编译前的代码,四年前写的没有动过

export class Event {
public type: string;
constructor(type: string, data: any = {}) {
merge(this, data);
this.type = type;
}
}

export default class MapMouseEvent extends Event {
/**
* `true` if `preventDefault` has been called.
* @private
*/
public type:
| 'mousedown'
| 'mouseup'
| 'click'
| 'dblclick'
| 'mousemove'
| 'mouseover'
| 'mouseenter'
| 'mouseleave'
| 'mouseout'
| 'contextmenu';
/**
* The `Map` object that fired the event.
*/
public target: Map | EarthMap;
/**
* The DOM event which caused the map event.
*/
public originalEvent: MouseEvent;
/**
* The pixel coordinates of the mouse cursor, relative to the map and measured from the top left corner.
*/
public point: Point;
/**
* The geographic location on the map of the mouse cursor.
*/
public lngLat: LngLat;
public defaultPrevented: boolean;
/**
* @private
*/
constructor(
type: string,
map: Map | EarthMap,
originalEvent: MouseEvent,
data: any = {},
) {
const point = DOM.mousePos(map.getCanvasContainer(), originalEvent);
const lngLat = map.unproject(point);
super(type, merge({ point, lngLat, originalEvent }, data));
this.defaultPrevented = false;
this.target = map;
}

@lvisei
Copy link
Member

lvisei commented Apr 11, 2024

看似无毒无害,简化复现一下

class A {
  public arg1: number
  constructor(arg1: number, arg2: number) {
    this.arg1 = arg1;
    this.arg2 = arg2;
  }
}


class B extends A {
  public arg2: number
  public arg3: number
  constructor(arg1: number, arg2: number, arg3: number) {
    super(arg1, arg2);
    this.arg3 = arg3;
  }
}

const b = new B(1, 2, 3)
console.log(b)

再简化一下转化为 JS 的

class A {
   arg1
  constructor(arg1, arg2) {
    this.arg1 = arg1;
    this.arg2 = arg2;
  }
}


class B extends A {
   arg2
   arg3
  constructor(arg1, arg2, arg3) {
    super(arg1, arg2);
    this.arg3 = arg3;
  }
}

const b = new B(1, 2, 3)
console.log(b)

执行结果是什么?

image

@lvisei
Copy link
Member

lvisei commented Apr 11, 2024

打包时,使用了 Babel 进行了编译,默认配置编译后的结果

babel repl

image

@lvisei
Copy link
Member

lvisei commented Apr 11, 2024

给 babel 如果加了 @babel/plugin-transform-typescript 插件,编译后的结果

babel repl

image

@lvisei
Copy link
Member

lvisei commented Apr 11, 2024

如果使用 typescript 编译

TS Playground

image

忽略编译错误,执行结果

image

@Dreammy23 Dreammy23 changed the title v2.21.1以上版本,地图设置为无底图模式时,获取经纬度的控件会现实(0,0) v2.21.1以上版本,地图设置为无底图模式时,获取经纬度的控件会显示(0,0) Apr 12, 2024
@antvis antvis deleted a comment from github-actions bot Apr 12, 2024
@spadek-w
Copy link

@lvisei 所以老哥最后如何改这个问题。加上pnpm add --save-dev @babel/plugin-transform-typescript ???

@lvisei
Copy link
Member

lvisei commented Apr 29, 2024

最后如何改这个问题。加上pnpm add --s

等今天修复了发个版本

@lvisei
Copy link
Member

lvisei commented Apr 29, 2024

等今天修复了发个版本

#2437

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants