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 draggable marker with popup #35

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,7 @@ including double-clicking to delete a point and a steering wheel with two button
([source code](https://github.com/mappable-world/mappable-default-ui-theme/tree/main/example/popups-on-map))
- [Adding a search control to the map](./search-control/vanilla/index.html)
([source code](https://github.com/mappable-world/mappable-default-ui-theme/tree/main/example/search-control))
- [Adding a route control to the map](./route-control/vanilla/index.html)
([source code](https://github.com/mappable-world/mappable-default-ui-theme/tree/main/example/route-control))
- [Adding a default ruler to the map](./default-ruler/vanilla/index.html)
([source code](https://github.com/mappable-world/mappable-default-ui-theme/tree/main/example/default-ruler))
16 changes: 12 additions & 4 deletions src/markers/MMapDefaultMarker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
this._marker = new mappable.MMapMarker(
{
...this._props,
onClick: this._onMarkerClick
onClick: this._onMarkerClick,
onDragMove: this._onMarkerDragMove
},
this._markerElement
);
Expand Down Expand Up @@ -216,6 +217,7 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
return new MMapPopupMarker({
...this._props,
...this._props.popup,
draggable: false,
show: this._props.popup.show ?? false,
offset: this._props.popup.offset ?? this._getPopupOffset(),
zIndex: 1000
Expand All @@ -242,13 +244,19 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
}

private _onMarkerClick: MMapDefaultMarkerProps['onClick'] = (...args) => {
if (!this._popup) {
return;
if (this._popup) {
this._popup.update({show: this._popup.isOpen});
}
this._popup.update({show: !this._popup.isOpen});
this._props.onClick?.(...args);
};

private _onMarkerDragMove: MMapDefaultMarkerProps['onDragMove'] = (coordinates) => {
if (this._popup) {
this._popup.update({coordinates});
}
this._props.onDragMove?.(coordinates);
};

private _updateTheme() {
const themeCtx = this._consumeContext(mappable.ThemeContext);
const theme = themeCtx.theme;
Expand Down
Loading