Skip to content

Commit

Permalink
Fix draggable marker with popup (#35)
Browse files Browse the repository at this point in the history
<!--

Thank you for submitting a pull request!

Here's a checklist you might find useful.
[ ] There is an associated issue that is labelled
  'Bug' or 'help wanted' or is in the Community milestone
[ ] Code is up-to-date with the `main` branch
[ ] You've successfully run `npm test` locally
[ ] There are new or updated tests validating the change

-->

Fixes #
  • Loading branch information
matthew44-mappable authored Sep 25, 2024
1 parent be5e155 commit eea7d06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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

0 comments on commit eea7d06

Please sign in to comment.