In the context of a SVG file, the following JavaScript:
var svg = document.rootElement, hitRect, hits;
hitRect = svg.createSVGRect();
hitRect.height = 1;
hitRect.width = 1;
hitRect.y = 100;
hitRect.x = 100;
hits = svg.getIntersectionList(hitRect, null);
always assigns null
to hits
, regardless if there were any intersections at all (in the case of no intersections, it should've been an empty NodeList).
Has anyone stumbled in to this problem? Is there a known workaround for hit-testing a SVG in Android?
Tested on: Android default browser on Android 4.0.3 (emulator), 4.0.3 (GALAXY Note SC-05D). (Google Chrome works)
Edit
I also tried looping through all elements (document.getElementsByTagName("*")
), testing each one with svg.checkIntersection
, to no avail. checkIntersection
just returned true
for every single element.
I also encounter the problem when test of iOS Safari <= 5.0, same like it's not support SVG 1.1, so after adding following attribute to the svg element, it's no effect:
Above test code should alert:
But in iOS Safari <=5.0 and some android it's alert:
So, if you want to get better compatibility, only rely on the method:
it's get topmost element under the point (x,y), even support IE 5.5
You can test 5 points in a small rect area(center, 4 corner) (or more points), to workaround this.