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

Does not work in areas #15

Open
GeTechG opened this issue Aug 22, 2021 · 0 comments
Open

Does not work in areas #15

GeTechG opened this issue Aug 22, 2021 · 0 comments

Comments

@GeTechG
Copy link

GeTechG commented Aug 22, 2021

It doesn't work
Screenshot_1

Work
Screenshot_2

html

<svg viewBox="0 0 1356 678" xmlns="http://www.w3.org/2000/svg" id="test">
        <path id="check" fill="#ffffff" stroke="#000000" d="M 369.884 206.316 C 369.891 206.316 442.308 206.316 442.315 206.316 C 442.315 206.336 442.315 404.933 442.315 404.952 C 442.308 404.952 369.891 404.952 369.884 404.952 C 369.884 404.933 369.884 206.336 369.884 206.316 Z"/>
        <circle id="ind" r="25" cx="70" cy="70" stroke="none" fill="#ff0000" />
        <circle id="cursor" r="2" cx="70" cy="70" stroke="none" fill="#000000" />
    </svg>

js

          document.querySelector("#test").onclick = function(event) {
              let d = document.querySelector("#check").getAttribute("d");
              let check = pointInSvgPath(d, event.pageX, event.pageY);
              document.querySelector("#cursor").setAttribute("cx", event.pageX);
              document.querySelector("#cursor").setAttribute("cy", event.pageY);
              if (check) {
                  document.querySelector("#ind").setAttribute("fill", "#00ff00");
            } else {
                document.querySelector("#ind").setAttribute("fill", "#ff0000");
              }
          }

Actually I found a solution, I replaced .toFixed(2) with .toFixed(1) and it started detecting correctly.

P.s On more complex ones, the problem is not solved.

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

No branches or pull requests

1 participant