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: 天地图Marker和Popup的bug #2315

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
74 changes: 16 additions & 58 deletions packages/component/src/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Marker extends EventEmitter {
...this.getDefault(),
...option,
};
bindAll(['update', 'onMove', 'onMapClick', 'updatePositionWhenZoom'], this);
bindAll(['update', 'onMove', 'onMapClick'], this);
this.init();
}

Expand All @@ -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.onAddMarkerOrPopup(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.onRemoveMarkerOrPopup(this);
}
this.unRegisterMarkerEvent();
this.removeAllListeners();
Expand Down Expand Up @@ -218,54 +219,6 @@ export default class Marker extends EventEmitter {
this.updatePosition();
DOM.setTransform(element as HTMLElement, `${anchorTranslate[anchor]}`);
}
//天地图在开始缩放时触发 更新目标位置时添加过渡效果
private updatePositionWhenZoom(ev: { map: any; center: any; zoom: any }) {
if (!this.mapsService) {
return;
}
const { element, offsets } = this.markerOption;
const { lng, lat } = this.lngLat;
if (element) {
element.style.display = 'block';
element.style.whiteSpace = 'nowrap';
const { containerHeight, containerWidth, bounds } =
this.getMarkerLayerContainerSize() || this.getCurrentContainerSize();
if (!bounds) {
return;
}
const map = ev.map;
const center = ev.center;
const zoom = ev.zoom;
const projectedCenter = map.DE(this.lngLat, zoom, center);
projectedCenter.x = Math.round(projectedCenter.x + offsets[0]);
projectedCenter.y = Math.round(projectedCenter.y - offsets[1]);
// 当前可视区域包含跨日界线
if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
if (projectedCenter.x > containerWidth) {
// 日界线右侧点左移
const newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
projectedCenter.x = newPos.x;
}
if (projectedCenter.x < 0) {
// 日界线左侧点右移
const newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
projectedCenter.x = newPos.x;
}
}
if (
projectedCenter.x > containerWidth ||
projectedCenter.x < 0 ||
projectedCenter.y > containerHeight ||
projectedCenter.y < 0
) {
element.style.display = 'none';
}
element.style.left = projectedCenter.x + 'px';
element.style.top = projectedCenter.y + 'px';
element.style.transition =
'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
private onMapClick(e: MouseEvent) {
const { element } = this.markerOption;
Expand Down Expand Up @@ -343,7 +296,8 @@ export default class Marker extends EventEmitter {
}
const { element, offsets } = this.markerOption;
const { lng, lat } = this.lngLat;
const pos = this.mapsService.lngLatToContainer([lng, lat]);
//@ts-ignore
const pos = this.mapsService.lngLatToContainer([lng, lat],true);
if (element) {
element.style.display = 'block';
element.style.whiteSpace = 'nowrap';
Expand All @@ -357,26 +311,30 @@ export default class Marker extends EventEmitter {
if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
if (pos.x > containerWidth) {
// 日界线右侧点左移
const newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
//@ts-ignore
const newPos = this.mapsService.lngLatToContainer([lng - 360, lat],true);
pos.x = newPos.x;
}
if (pos.x < 0) {
// 日界线左侧点右移
const newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
//@ts-ignore
const newPos = this.mapsService.lngLatToContainer([lng + 360, lat],true);
pos.x = newPos.x;
}
}
// 不在当前可视区域内隐藏点
// 不在当前可视区域内隐藏点 (天地图不处理 因为天地图平移的是父容器,为了避免平移时频繁更新位置,这里就不处理display了)
if (
this.mapsService.getType() !== 'tdtmap'
&& (
pos.x > containerWidth ||
pos.x < 0 ||
pos.y > containerHeight ||
pos.y < 0
pos.y < 0)
) {
element.style.display = 'none';
}

element.style.left = pos.x + offsets[0] + 'px';
element.style.left = pos.x + offsets[0] + 'px';
element.style.top = pos.y - offsets[1] + 'px';
}
}
Expand Down
49 changes: 14 additions & 35 deletions packages/component/src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ export default class Popup<O extends IPopupOption = IPopupOption>
this.mapsService = scene.mapService;
this.sceneService = scene.sceneService;
this.layerService = scene.layerService;
//天地图仅监听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 @@ -129,6 +127,8 @@ export default class Popup<O extends IPopupOption = IPopupOption>
if (title) {
this.setTitle(title);
}
// @ts-ignore
this.mapsService.onAddMarkerOrPopup(this);
this.emit('open');
return this;
}
Expand All @@ -152,12 +152,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.onAddMarkerOrPopup(this);
// @ts-ignore
delete this.mapsService;
}
this.emit('close');
Expand Down Expand Up @@ -332,13 +332,13 @@ 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);
// this.mapsService.onRemoveMarkerOrPopup(this);

// this.mapsService.on('zoonanim', this.updateWhenZoom);
this.mapsService.on('camerachange', this.update);
this.mapsService.on('viewchange', this.update);
// this.mapsService.onAddMarkerOrPopup(this);
}
this.update();
if (this.popupOption.autoPan) {
Expand Down Expand Up @@ -385,26 +385,12 @@ export default class Popup<O extends IPopupOption = IPopupOption>
return;
}
const { lng, lat } = this.lngLat;
const { x, y } = this.mapsService.lngLatToContainer([lng, lat]);
//@ts-ignore
const { x, y } = this.mapsService.lngLatToContainer([lng, lat],true);

this.setPopupPosition(x, y);
};
//zoom时计算PopUp的位置并更新
protected updateLngLatPositionWhenZoom = (ev: any) => {
if (!this.mapsService || this.popupOption.followCursor) {
return;
}
const map = ev.map;
const viewHalf = map.getSize();
viewHalf.x = viewHalf.x / 2;
viewHalf.y = viewHalf.y / 2;
const center = ev.center;
const zoom = ev.zoom;
const projectedCenter = map.DE(this.lngLat, zoom, center);
projectedCenter.x = Math.round(projectedCenter.x);
projectedCenter.y = Math.round(projectedCenter.y);
this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected getDefault(option: Partial<O>): O {
// tslint:disable-next-line:no-object-literal-type-assertion
Expand Down Expand Up @@ -528,8 +514,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>
}
this.hide();
};
//更新位置 支持zoom时更新
private updatePosition = (ev: any, zoom: Boolean = true) => {
private updatePosition = () => {
const hasPosition = !!this.lngLat;
const { className, style, maxWidth, anchor, stopPropagation } =
this.popupOption;
Expand Down Expand Up @@ -565,11 +550,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>

this.container.style.whiteSpace = 'nowrap';
}
if (zoom) {
this.updateLngLatPositionWhenZoom(ev);
} else {
this.updateLngLatPosition();
}
this.updateLngLatPosition();
DOM.setTransform(this.container, `${anchorTranslate[anchor]}`);
applyAnchorClass(this.container, anchor, 'popup');

Expand All @@ -581,12 +562,10 @@ export default class Popup<O extends IPopupOption = IPopupOption>
} else {
this.container.style.removeProperty('width');
}
};
protected updateWhenZoom = (ev: any) => {
this.updatePosition(ev, true);
};
}

protected update = () => {
this.updatePosition(null, false);
this.updatePosition();
};
/**
* 设置 Popup 相对于地图容器的 Position
Expand Down
5 changes: 4 additions & 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,10 @@ export interface IMapService<RawMap = {}> {
// lngLatToCoords?(lnglatArray: any): any;
getCustomCoordCenter?(): [number, number];
exportMap(type: 'jpg' | 'png'): string;
// 添加marker或popup时触发
onAddMarkerOrPopup(object:any): void;
// 添加marker或popup时触发
onRemoveMarkerOrPopup(object:any): void;

// 地球模式下的地图方法/属性
rotateY?(
Expand Down
Loading
Loading