-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Update DOM.mousePos() with Leaflet code #2276
Conversation
See also Leaflet/Leaflet#6055 - this specific bit of code dates back to 2018. |
ab542eb
to
49fc1c3
Compare
This **partially** fixes maplibre#1160, by using an adaptation of Leaflet's `L.DOMEvent.getMousePosition()`. The `DOM.touchPos()` static method should still display the bug. Signed-off-by: Iván Sánchez Ortega <[email protected]>
49fc1c3
to
17f5572
Compare
@@ -84,12 +84,32 @@ export default class DOM { | |||
}, 0); | |||
} | |||
|
|||
public static mousePos(el: HTMLElement, e: MouseEvent | Touch) { | |||
const rect = el.getBoundingClientRect(); | |||
public static getScale(element: HTMLElement) { |
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.
Can you add a return type here?
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.
TBH I've never done any typescript, so I don't know how to specify "an object containing two Number
s and one DomRect
" 😕
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.
You can easily google it or look in other places in the code.
Here's an exmaple:
type ScaleValue {
x: number;
y: number;
boundingClientRect: Rect;
}
} | ||
|
||
const scale = DOM.getScale(el), | ||
offset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y) |
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.
would be better to define another variable here.
Also since getScale
is a method you wrote, you can use a different name for boundingClientRect
or change the offset
variable name to boundingClientRect
. In general, it would make sense that they have the same name I think.
Thanks for taking the time to open this PR! |
@IvanSanchez what's the status of this PR? |
Hi @HarelM and @IvanSanchez , any update on this PR? |
I haven't heard back, your best approach would be to take the code in this PR and create another one with the relevant fix along side tests so I'll be able to merge it. |
@IvanSanchez, any updates on your PRs? There are two waiting for code review changes. |
I have created another PR with the relevant fix: #3437 |
This partially fixes #1160, by using an adaptation of Leaflet's
L.DOMEvent.getMousePosition()
(see https://github.com/Leaflet/Leaflet/blob/18d703176bec040a06f233702d3eec141e95daaf/src/dom/DomEvent.js#L245-L262).The
DOM.touchPos()
static method should still display the bug.Launch Checklist
CHANGELOG.md
under the## main
section.