Skip to content

fix: 天地图Marker和Popup的bug #2315

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e110819
fix: fillImage中uniform没对齐的bug
Dec 6, 2023
5827d9a
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 6, 2023
914fb02
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 8, 2023
5cdc2b2
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 8, 2023
3f5576d
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 11, 2023
d19d397
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 12, 2023
3e87a2a
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 15, 2023
4712a19
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 18, 2023
14ed74d
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 20, 2023
1efd70a
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 20, 2023
0467e50
Merge branch 'master' of https://github.com/antvis/L7 into master
Dec 22, 2023
b0f03a5
Merge branch 'master' of https://github.com/antvis/L7 into master
Jan 22, 2024
787dc63
Merge branch 'master' of https://github.com/antvis/L7 into master
Jan 26, 2024
663da62
Merge branch 'master' of https://github.com/antvis/L7 into master
Feb 1, 2024
0f735fa
Merge branch 'master' of https://github.com/antvis/L7 into master
Feb 20, 2024
9cfe451
Merge branch 'master' of https://github.com/antvis/L7 into master
Feb 23, 2024
fa004e4
feat: 将天地图的Marker和Popup的zoom事件下放到天地图的mapService中
Feb 23, 2024
4a29752
feat: 将marker和popup中与天地图相关的方法提取到天地图的mapService
Mar 5, 2024
72d9191
fix: amap的marker和popup报错的bug
Mar 6, 2024
b642fe1
Merge branch 'master' of https://github.com/antvis/L7 into master
Mar 14, 2024
d1c9040
Merge branch 'master' into fix-tdtMarkerAndPopUp
Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/component/src/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export default class Marker extends EventEmitter {
// this.sceneSerive.getSceneContainer().appendChild(element as HTMLElement);
this.mapsService.getMarkerContainer().appendChild(element as HTMLElement);
this.registerMarkerEvent(element as HTMLElement);
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
// this.mapsService.on('zoomchange', this.updatePositionWhenZoom);
this.mapsService.on('camerachange', this.update); // 注册高德1.x 的地图事件监听
this.update();
this.updateDraggable();
this.added = true;
// @ts-ignore
this.mapsService.addZoomListenerWhenAddMarkerOrPopup(this);
this.emit('added');
return this;
}
Expand All @@ -76,8 +76,9 @@ export default class Marker extends EventEmitter {
this.mapsService.off('click', this.onMapClick);
this.mapsService.off('move', this.update);
this.mapsService.off('moveend', this.update);
// this.mapsService.off('zoomchange', this.update);
this.mapsService.off('camerachange', this.update);
// @ts-ignore
this.mapsService.removeZoomListenerWhenRemoveMarkerOrPopup(this);
}
this.unRegisterMarkerEvent();
this.removeAllListeners();
Expand Down Expand Up @@ -219,7 +220,7 @@ export default class Marker extends EventEmitter {
DOM.setTransform(element as HTMLElement, `${anchorTranslate[anchor]}`);
}
//天地图在开始缩放时触发 更新目标位置时添加过渡效果
private updatePositionWhenZoom(ev: { map: any; center: any; zoom: any; }) {
public updatePositionWhenZoom(ev: { map: any; center: any; zoom: any; }) {
if (!this.mapsService) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法在非天地图场景,还是会报错吧,可以尝试补充一下单元测试

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

又更新了一版

return;
}
Expand Down Expand Up @@ -375,7 +376,7 @@ export default class Marker extends EventEmitter {
) {
element.style.display = 'none';
}

element.style.left = pos.x + offsets[0] + 'px';
element.style.top = pos.y - offsets[1] + 'px';
console.log(element.style.left);
Expand Down
16 changes: 9 additions & 7 deletions packages/component/src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ export default class Popup<O extends IPopupOption = IPopupOption>
this.mapsService = scene.get<IMapService>(TYPES.IMapService);
this.sceneService = scene.get<ISceneService>(TYPES.ISceneService);
this.layerService = scene.get<ILayerService>(TYPES.ILayerService);
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
// this.mapsService.on('zoomchange', this.updateWhenZoom);
this.mapsService.on('camerachange', this.update);
this.mapsService.on('viewchange', this.update);
this.scene = scene;
Expand All @@ -131,6 +129,8 @@ export default class Popup<O extends IPopupOption = IPopupOption>
if (title) {
this.setTitle(title);
}
// @ts-ignore
this.mapsService.addZoomListenerWhenAddMarkerOrPopup(this);
this.emit('open');
return this;
}
Expand All @@ -154,12 +154,12 @@ export default class Popup<O extends IPopupOption = IPopupOption>
// TODO: mapbox AMap 事件同步
this.mapsService.off('camerachange', this.update);
this.mapsService.off('viewchange', this.update);
//天地图的缩放事件
// this.mapsService.off('zoomchange', this.updateWhenZoom);
this.updateCloseOnClick(true);
this.updateCloseOnEsc(true);
this.updateFollowCursor(true);
// @ts-ignore
this.mapsService.removeZoomListenerWhenRemoveMarkerOrPopup(this);
// @ts-ignore
delete this.mapsService;
}
this.emit('close');
Expand Down Expand Up @@ -334,13 +334,15 @@ export default class Popup<O extends IPopupOption = IPopupOption>
}
if (this.mapsService) {
// 防止事件重复监听
// this.mapsService.off('zoonanim', this.updateWhenZoom);
this.mapsService.off('camerachange', this.update);
this.mapsService.off('viewchange', this.update);
// @ts-ignore
this.mapsService.removeZoomListenerWhenRemoveMarkerOrPopup(this);

// this.mapsService.on('zoonanim', this.updateWhenZoom);
this.mapsService.on('camerachange', this.update);
this.mapsService.on('viewchange', this.update);
// @ts-ignore
this.mapsService.addZoomListenerWhenAddMarkerOrPopup(this);
}
this.update();
if (this.popupOption.autoPan) {
Expand Down Expand Up @@ -587,7 +589,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>
this.container.style.removeProperty('width');
}
}
protected updateWhenZoom = (ev:any) => {
protected updatePositionWhenZoom = (ev:any) => {
this.updatePosition(ev,true);
}
protected update = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/map/IMapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export interface IMapService<RawMap = {}> {
getMarkerContainer(): HTMLElement;
getOverlayContainer(): HTMLElement | undefined;
// MapEvent // 定义事件类型

on(type: string, handler: (...args: any[]) => void): void;
off(type: string, handler: (...args: any[]) => void): void;
once(type: string, handler: (...args: any[]) => void): void;
Expand Down Expand Up @@ -124,6 +123,7 @@ export interface IMapService<RawMap = {}> {
getCustomCoordCenter?(): [number, number];
exportMap(type: 'jpg' | 'png'): string;


// 地球模式下的地图方法/属性
rotateY?(
option:
Expand Down
7 changes: 7 additions & 0 deletions packages/maps/src/tdtmap/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export default class TdtMapService extends BaseMapService<any> {
return;
}

public addZoomListenerWhenAddMarkerOrPopup(object:any): void {
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
this.on('zoomchange', object.updatePositionWhenZoom);
}
public removeZoomListenerWhenRemoveMarkerOrPopup(object:any): void {
this.off('zoomchange', object.updatePositionWhenZoom);
}
public getMarkerContainer(): HTMLElement {
return this.markerContainer;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/maps/src/utils/BaseMapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default abstract class BaseMapService<T>
this.markerContainer = DOM.create('div', 'l7-marker-container', container);
this.markerContainer.setAttribute('tabindex', '-1');
}
//需要子类实现 目前只有天地图实现
public addZoomListenerWhenAddMarkerOrPopup(object:any): void {}
//需要子类实现 目前只有天地图实现
public removeZoomListenerWhenRemoveMarkerOrPopup(object:any): void {}

public getMarkerContainer(): HTMLElement {
return this.markerContainer;
Expand Down