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

feat: add hover events and anchor points to advanced markers #472

Merged
merged 12 commits into from
Sep 13, 2024

Conversation

mrMetalWood
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@usefulthink usefulthink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks a lot!

I think there's just two things missing here: updated documentation and some more explanations about the DOM structure being built for the marker.

What do you think, do we need to be worried that the added dom-element will cause backwards compatibility issues?

examples/advanced-marker-interaction/README.md Outdated Show resolved Hide resolved
examples/advanced-marker-interaction/src/app.tsx Outdated Show resolved Hide resolved
examples/advanced-marker-interaction/src/app.tsx Outdated Show resolved Hide resolved
examples/advanced-marker-interaction/src/app.tsx Outdated Show resolved Hide resolved
examples/advanced-marker-interaction/src/app.tsx Outdated Show resolved Hide resolved
examples/advanced-marker-interaction/src/control-panel.tsx Outdated Show resolved Hide resolved
src/components/advanced-marker.tsx Outdated Show resolved Hide resolved
src/components/advanced-marker.tsx Show resolved Hide resolved
src/components/advanced-marker.tsx Outdated Show resolved Hide resolved
@@ -58,7 +58,15 @@ export const Pin = (props: PropsWithChildren<PinProps>) => {
}

// Set content of Advanced Marker View to the Pin View element
advancedMarker.content = pinElement.element;
const markerContent = advancedMarker.content?.firstChild;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use some more explanation with this, isn't the cleanup below something that the react portal will take care of? Maybe I'm condifusing the different elements here.

Copy link
Collaborator Author

@mrMetalWood mrMetalWood Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes an issue that has already been addressed in #428 where the the Pin component would overwrite the styles on an advanced marker by setting the content rather than replace the children.

Below is just a more verbose way of saying ...replaceChildren(pinElement.element); since that doesn't seem to be supported by our transpile target I think.

@mrMetalWood
Copy link
Collaborator Author

Here is a comparison of the DOM structure output:

Before:
Screenshot 2024-09-05 at 12 17 47

After:
Screenshot 2024-09-05 at 11 57 50

@mrMetalWood mrMetalWood marked this pull request as ready for review September 5, 2024 10:24
@mrMetalWood mrMetalWood changed the title feat: add hover event and anchor points to advanced markers feat: add hover events and anchor points to advanced markers Sep 5, 2024
Copy link
Collaborator

@usefulthink usefulthink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very cool, almost there :)

if (anchorWidth === 0 && anchorHeight === 0) {
// We can safely typecast here since we control that element and we know that
// it is a div
const anchorDomContent = anchor.content.firstChild as Element;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be risky, I think firstChild could also be a text- or even a comment-node, using Element.firstElementChild should be fine here.

anchorDomContent?.getBoundingClientRect().width;

const anchorComputedStyles = getComputedStyle(anchorDomContent);
const transformMatrix = new WebKitCSSMatrix(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the Webkit prefix, I think it's now called DOMMatrix.

If I understood this right, we need to compute the offset of the top/center of the marker-content to the current position of the marker. According to the spec, getBoundingClientRect() already have all transforms applied, so we could maybe just take the values from there? Maybe the BCR of our 0x0 anchoring div could be used as reference to get to the actual offset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :) Yes we can.

@usefulthink
Copy link
Collaborator

can you also have a look at this comment here: #368 (reply in thread)? Is this going to be obsolete with the new implementation?

@mrMetalWood
Copy link
Collaborator Author

can you also have a look at this comment here: #368 (reply in thread)? Is this going to be obsolete with the new implementation?

Yes, I think that should be resolved with the new implementation

@usefulthink usefulthink merged commit cc4a397 into visgl:main Sep 13, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants