Skip to content

Commit

Permalink
fix: 无地图与 MapLibre 模式移动 Marker 出错 (#2509)
Browse files Browse the repository at this point in the history
* fix: marker 拖动报错

* chore: add changeset
  • Loading branch information
lvisei authored May 29, 2024
1 parent 9060f49 commit aca779d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-singers-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/l7-component': patch
---

fix: 无地图与 MapLibre 模式移动 Marker 出错
5 changes: 4 additions & 1 deletion examples/demos/components/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const marker: TestCase = async (options) => {
continue;
}

const markerIns = new Marker().setLnglat({ lng: nodes[i].x * 1, lat: nodes[i].y });
const markerIns = new Marker({ draggable: true }).setLnglat({
lng: Number(nodes[i].x * 1),
lat: Number(nodes[i].y),
});
scene.addMarker(markerIns);
}

Expand Down
1 change: 1 addition & 0 deletions packages/component/src/control/mouseLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class MouseLocation extends Control<IMouseLocationControlOption>
}
protected onMouseMove = (e: any) => {
let position: Position = this.location;
// 适配不同底图,事件返回的数据名称不一致
const lngLat: ILngLat | undefined = e.lngLat || e.lnglat;
const { transform } = this.controlOption;
if (lngLat) {
Expand Down
6 changes: 4 additions & 2 deletions packages/component/src/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,16 @@ export default class Marker extends EventEmitter {
};

private onMarkerDragMove = (e: any) => {
// 适配不同底图,事件返回的数据名称不一致
const lngLat: ILngLat = e.lngLat || e.lnglat;
const { lng: preLng, lat: preLat } = this.preLngLat;
const { lng: curLng, lat: curLat } = e.lnglat;
const { lng: curLng, lat: curLat } = lngLat;
const newLngLat = {
lng: this.lngLat.lng + curLng - preLng,
lat: this.lngLat.lat + curLat - preLat,
};
this.setLnglat(newLngLat);
this.preLngLat = e.lnglat;
this.preLngLat = lngLat;
this.emit('dragging', newLngLat);
};

Expand Down

0 comments on commit aca779d

Please sign in to comment.