@greenembrace for now, is there any reason you are using touchstart
over click
? Click should work on a touch screen & does contain coordintated.
@BartButenaers we need to handle this differently.
the touch events present their pageX and pageY coordinates in a different property to click.
e.g...
//touch event
pt.x = evt.originalEvent.touches[0].pageX;
pt.y = evt.originalEvent.touches[0].pageY;
//click event
pt.x = evt.pageX;
pt.y = evt.pageY;
So we can fix touch events like this...
initController: function($scope, events) {
// Remark: all client-side functions should be added here!
// If added above, it will be server-side functions which are not available at the client-side ...
// ADD THIS FUNCTION INSIDE initController....
//helper function to get event coordinates
function pointerEventToXY(e){
if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
var touches = e.touches || e.originalEvent && e.originalEvent.touches.touches;
if(touches && touches.length){
var touch = touches[0] || changedTouches[0];
return {
x : touch.pageX,
y : touch.pageY
}
}
} else if (e.type == 'click' || e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
return {
x : e.pageX,
y : e.pageY
}
}
return null;
};
...
...
...
//CHANGE THE BELOW AS FOLLOWS...
// Get the mouse coordinates (with origin at left top of the SVG drawing)
let evtpos = pointerEventToXY(evt);
if(evtpos){
var pt = $scope.svg.createSVGPoint();
pt.x = evtpos.x;
pt.y = evtpos.y;
pt = pt.matrixTransform($scope.svg.getScreenCTM().inverse());
//relative position on svg
msg.coordinates = {
x: pt.x,
y: pt.y
}
//absolute position on page - usefull for sending to popup menu
msg.position = evtpos;
}