-
Notifications
You must be signed in to change notification settings - Fork 448
Add sticky marker tooltip for touch devices #1597
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,3 +90,7 @@ | |
| .pm-textarea.pm-hasfocus { | ||
| cursor: auto; | ||
| } | ||
|
|
||
| .leaflet-tooltip-stickynote::before { | ||
| display: none; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||
| import Draw from './L.PM.Draw'; | ||||||||||||||||
| import { getTranslation } from '../helpers'; | ||||||||||||||||
| import { getTranslation, deviceHasFinePointer } from '../helpers'; | ||||||||||||||||
|
|
||||||||||||||||
| Draw.Marker = Draw.extend({ | ||||||||||||||||
| initialize(map) { | ||||||||||||||||
|
|
@@ -63,6 +63,8 @@ Draw.Marker = Draw.extend({ | |||||||||||||||
| }); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| this._setupTouchScreenTips(); | ||||||||||||||||
|
|
||||||||||||||||
| // fire drawstart event | ||||||||||||||||
| this._fireDrawStart(); | ||||||||||||||||
| this._setGlobalDrawMode(); | ||||||||||||||||
|
|
@@ -194,4 +196,62 @@ Draw.Marker = Draw.extend({ | |||||||||||||||
| this._hintMarker?.setIcon(this.options.markerStyle.icon); | ||||||||||||||||
| } | ||||||||||||||||
| }, | ||||||||||||||||
| _setupTouchScreenTips() { | ||||||||||||||||
| let markerHintTip = null; | ||||||||||||||||
|
|
||||||||||||||||
| this._map.on('pm:drawstart', (event) => { | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventlistener should be only added if the global option for mobile tooltip is enabled |
||||||||||||||||
| if (event.shape === 'Marker' && !deviceHasFinePointer()) { | ||||||||||||||||
| // Hides the "hint marker" as that is confusing for touch screen users. | ||||||||||||||||
| const drawMarker = this._map.pm.Draw.Marker; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. creating the variable |
||||||||||||||||
| drawMarker._hintMarker.remove(); | ||||||||||||||||
|
|
||||||||||||||||
| // Creates the touch screen hint "permanently" (while using the tool) | ||||||||||||||||
| // sticked at the top of the map. | ||||||||||||||||
| markerHintTip = L.tooltip([0, 0], { | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we should use a plain html element, positioned absolute, instead. Then there would be no need to recalculate the position with every move |
||||||||||||||||
| className: 'leaflet-tooltip-stickynote', | ||||||||||||||||
| content: getTranslation('tooltips.placeMarkerTip'), | ||||||||||||||||
| direction: 'bottom', | ||||||||||||||||
| permanent: true, | ||||||||||||||||
| }).addTo(this._map); | ||||||||||||||||
|
|
||||||||||||||||
| const updateHandler = () => this._updateHintPosition(markerHintTip); | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call should be throttled Reference: leaflet-geoman/src/js/Mixins/Modes/Mode.Drag.js Lines 15 to 21 in d720305
|
||||||||||||||||
|
|
||||||||||||||||
| updateHandler(); | ||||||||||||||||
| this._map.on('zoomlevelschange resize move', updateHandler, this); | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
| this._map.on('pm:drawend', (event) => { | ||||||||||||||||
| if (event.shape === 'Marker' && markerHintTip) { | ||||||||||||||||
| markerHintTip.remove(); | ||||||||||||||||
| markerHintTip = null; | ||||||||||||||||
| this._map.off( | ||||||||||||||||
| 'zoomlevelschange resize move', | ||||||||||||||||
| this._updateHintPosition, | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't remove the correct event listener function |
||||||||||||||||
| this | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
| }, | ||||||||||||||||
| _updateHintPosition(markerHintTip) { | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to have |
||||||||||||||||
| if (!markerHintTip) { | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const bounds = this._map.getBounds(); | ||||||||||||||||
|
|
||||||||||||||||
| // Calculate the longitude distance of the map's visible area. This allows | ||||||||||||||||
| // for an easy way to figure out the center point of the map. | ||||||||||||||||
| const distance = this._map.distance( | ||||||||||||||||
| bounds.getNorthWest(), | ||||||||||||||||
| bounds.getNorthEast() | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| // Calculate new bounds with the current latitude distance of the visible | ||||||||||||||||
| // map from the northwest point of the map. Within these new bounds, the | ||||||||||||||||
| // east border is at the center of the map. | ||||||||||||||||
| const newBounds = bounds.getNorthWest().toBounds(distance); | ||||||||||||||||
|
|
||||||||||||||||
| // Set the hint at the top center of the map. | ||||||||||||||||
| markerHintTip.setLatLng([bounds.getNorth(), newBounds.getEast()]); | ||||||||||||||||
| }, | ||||||||||||||||
| }); | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the variable to the context:
this._markerHintTip