Konva stage does not trigger on click using synthetic MouseEvent - mouseevent

i'm using MouseEvent to click on Konva stage. The user does not click on the Konva's canvas, directly, instead, the user clicks on something else and that click is translated to Konva canvas based on some calculations.
I have a 3D platform written in Babylonjs that uses Konva's canvas as the dynamic texture.
The texture is then applied to the mesh. When there is a click on the mesh, it will tell me which area (x,y) of the texture was clicked. Now I will have to programmatically trigger a click on the texture (Konva's canvas) so that Konva's shape gets selected and they can drag it around the texture and this will be updated real-time on the mesh (3d).
The problem is that my custom mouse event is not recognized by
stage.on('click'.
Please check the below example.
https://jsbin.com/sayiwajega/1/edit?html,js,console,output
Working solution using fabricjs.
https://www.babylonjs-playground.com/#9U086#238
I know that there is an
this.stage.fire('click', { posX, posY });
But the limitation here is that you cant pass an actual click or a drag event. as a result, you cant just transfer the action from the 3d Canvas to Konva's canvas.

Konva doesn't listen to click event on the canvas to trigger its own click event.
Instead, it is listening to
mousedown / touchstart / pointerdown
mousemove / touchmove / pointermove
mouseup / touchend / pointerup
So to replicate most of Konva events you need to proxy these events into container.
stage.on('click', (evt) => {
console.log('you clicked on the circle!');
});
customMouseEvent = () => {
const cb = document.getElementById('container').getElementsByTagName('canvas')[0];
let evt = new MouseEvent("mousedown", {
bubbles: true,
cancelable: true,
view: window
});
cb.dispatchEvent(evt);
evt = new MouseEvent("mouseup", {
bubbles: true,
cancelable: true,
view: window
});
cb.dispatchEvent(evt);
}

Related

Zoom out by scrolling in a testcafe test

I have a map in my angular application OpenLayers map.
During the test using testcafe, I have to zoom out, but I have no way how to do that.
I only have to put my mouse at the center of the screen, and then scroll down to zoom out.
Already tried using ClientFunction with scrollBy and etc but nothing happens in map.
Thank you
Find out on which element the handler you need hangs and what event it listens to. This is most likely a 'mousewheel' event. This should help you:
const zoom = ClientFunction(zoomSize => {
const event = new WheelEvent('wheel', { deltaY: zoomSize });
document.querySelector('#zommed-element').dispatchEvent(event);
});

Openlayer pan using only mouse middle button

I need to build a custom pan for openlayer(ol3) map using press and drag mouse middle key only. This is what i need.
new ol.interaction.DragPan({
condition: function(event) {
// return event.originalEvent.ctrlKey
// need event for mouse middle key instated of ctrl
}
});
Any suggestion?
NOTE: similar question is Openlayers middle mouse button panning, with no answer

Cancel WinJS.UI.Animation.pointerDown if not clicked

I'm using WinJS.UI.Animation.pointerDown and WinJS.UI.Animation.pointerUp within a WinJS repeater's item template.
The problem is if a user holds their finger or the mouse button down on an item and moves off it, the pointerUp animation doesn't seem to fire or it fires but has no effect because the element that the up event is on is not the same as the one before. The best example of this is in the animation sample in example 6 (tap and click). Hold down the mouse button on a tile and move it off. It will stay in it's animated state and won't fire the pointerup event. Here's the code I'm using.
How can I cancel the pointerdown animation if the user moves off the element?
target1.addEventListener("pointerdown", function () {
WinJS.UI.Animation.pointerDown(this);
}, false);
target1.addEventListener("pointerup", function () {
WinJS.UI.Animation.pointerUp(this);
}, false);
target1.addEventListener("click", function () {
//do something spectacular
}, false);
I'm using the click event to commit the click action so that the right click remains clear for launching the navigation at the top of the app.
Have you tried adding an event listener for pointerout? That's the event that's dispatched when a pointing device (e.g. mouse cursor or finger) is moved out of the hit test boundaries of an element.
See the docs on pointer events here:
http://msdn.microsoft.com/en-us/library/ie/hh772103(v=vs.85).aspx

How to use dojo moveTo programmatically through javascript?

I can markup a Heading or ListItem to have a moveTo attribute and that transition works perfectly.
Is there a way perform a transition to a named view programmatically say, on a button click?
Somewhere on the net I found below code, but its not working. I need something similar to this -
function moveTo(){
var w = dijit.byId('currentView');
w.performTransition('#newView',1,"fade",null);
}
This code sample registers an onclick event handler on a button with the id "ButtonID". After pressing the button, a lookup in the dijit registry will be performed to find the displayed view.
You can call the function performTransition(...) on any dojox.mobile.View.
require(["dijit/registry"], function(registry) {
dojo.ready(function() {
// Button Listener
registry.byId("ButtonID").on("click", function(){
var oldView = dijit.registry.byId("ID_View1");
oldView.performTransition("ID_View2", 1, "slide", null);
});
});
But:
Changing "moveTo" parameters programmatically is much more difficult than performing transitions between views. You have to do some nasty things to override the moveTo Attribute of a widget like for example a Backbutton in a dojox.mobile.Heading
var heading1 = dijit.registry.byId("ID_Heading");
heading1.destroyDescendants();
heading1.moveTo = viewId;
heading1.backButton = false;
heading1._setBackAttr("Zurück");

Leaflet markers do not open popup on click

I just started using Leaflet and Marker Clusterer to organize the markers.
Problem #1: When an unclustered marker is clicked, no popup appears.
Problem #2: When a cluster is clicked several times, all the markers within that cluster appears, and when one of this marker is clicked, its popup appears! However, after closing the popup by clicking on the map, clicking on any of these clustered markers do not open any popups!
If I only have 3 unclustered markers, the popup works fine. However, as more markers are added, once a cluster forms, clicking on the marker within any cluster will not cause the popup to open!
Initializing markerclusterer
markers = new L.MarkerClusterGroup();
map.addLayer(markers);
All markers added to markercluster markers
A loop calls on the render function to create the marker and add it to the markerclusterer's array markers. (ignore the backbone.js code)
ListingMarkerView = Backbone.View.extend({
template: _.template( $('#tpl_ListingMarkerView').html() ),
render: function() {
// Create marker
var content = this.template( this.model.toJSON() );
var marker = new L.marker(
[this.model.get('lat'), this.model.get('lng')],
{content: content});
marker.bindPopup(content);
// Add to markerclusterer
markers.addLayer(marker);
}
});
Without markerclusterer
If I add the marker directly to map instead of the markerclusterer array markers, the popups work fine, so I guess the problem has something to do with markerclusterer.
Did I do something wrong that resulted in such behavior of the popups? All help appreciated, thanks!
From what little I know of the cluster marker group, you should do this:
var markerGroup = new L.MarkerClusterGroup();
markerGroup.on('click', function(ev) {
// Current marker is ev.layer
// Do stuff
});
To add an event handler to the cluster layer instead, do this:
markerGroup.on('clusterclick', function(ev) {
// Current cluster is ev.layer
// Child markers for this cluster are a.layer.getAllChildMarkers()
// Do stuff
});
Oh, and read the github README carefully, it's all in there...
Make sure you have the right versions of everything in your Leaflet + Clusterer stack (Js and Css). Compare against the examples in the Clusterer Github repo.