I have noticed that when you drag the map, if you drag with an accelerating movement, after you release the mouse, the map has some sort of momentum and it keeps sliding for a short period of time, but the 'dragend' event is fired when you release the mouse (which to me it seems correct).
But how can you get the exact moment when the maps finishes SLIDING? I'm not interested in 'center_changed' / 'bounds_changed' solutions, because I need to make a XHR request on the event, and process some data.
How about the idle event, which is fired only once at the end (unlike center_changed and bounds_changed). From the docs:
This event is fired when the map becomes idle after panning or
zooming.
Try using idle event. Link to docs.
This event is fired when the map becomes idle after panning or
zooming.
If you want idle event to fire only after dragend then try the snippet below.
This code prints coordinates to console after both dragend and idle events fire.
mapObj.addListener('dragend', function () {
var idleListener = mapObj.addListener('idle', function () {
google.maps.event.removeListener(idleListener);
console.log(mapObj.getCenter().lat());
console.log(mapObj.getCenter().lng());
});
});
Related
I am displaying several identical charts (showing different datasets) side-by-side. Upon brushing on one chart, the brush should be replicated on all others.
Currently, I do this by calling brush.move on a selection of all charts excluding the currently brushed chart, as soon as someone brushes on a chart. This happens in a brush-type eventListener.
However, this brush.move triggers the brush-type event attached to the brush, leading to an error (or, more generally, an infinite loop).
How can I prevent this?
You can use the d3.event object to check what caused the update of the brush. From the API docs on brush events:
Brush Events
When a brush event listener is invoked, d3.event is set to the current brush event. The event object exposes several fields:
…
sourceEvent - the underlying input event, such as mousemove or touchmove.
If your brush is modified programtically, i.e. by calling brush.move(), the d3.event.sourceEvent property will be null, because no input event caused this update. In your event handler you can check this property to skip execution for programmatic changes:
if (!d3.event.sourceEvent) return;
The same technique is employed by Mike Bostock in his Brush Snapping Block. While handling the actual input event the brush is modified again to snap to the nearest value, which, obviously, should not trigger another run of the event handler.
I'm trying to implement system-wide drag operation with middle mouse button. It should override middle mouse drag behavior in other programs. Currently, I am handling global mouse events with system-wide hooks.
Problem is - many programs still receive and handle same events like I did not intercept them.
Here's what I tried:
not call the next hook for mouse down event: I never receive mouse up, so I don't know where and when to stop dragging
not call the next hook for mouse move: cursor slows down tremendously
not call the next hook for mouse up: most windows in the system stop reacting to mouse events completely after my drag is finished
always call the next hook in the chain: if the control under mouse has scroll in it, most of the time it will be scrolling while my drag is in progress. Also UWP apps continue receiving mouse events during my drag, so if a link in MS Edge happens to be under cursor when it started, and mouse does not leave Edge boundary, Edge receives click event, and new tab is opened
What I need is: when user holds middle mouse and starts dragging, my drag handler should be called, and no other handlers, like file drag, scroll, etc should happen.
I ended up with somewhat hacky solution:
do not call the next hook for mouse down for middle button
record where it was pressed
when handling mouse up, if user did not drag - replay the whole mouse up + mouse down using SendInput from a separate thread (to avoid deadlock due to reentrancy)
I am using navigation window in my app.
I want to reset variable when every time window appear.
I tried
$.win.addEventListener("focus", function(e){
alert("window appear");
});
This is not calling. So i tried following:
$.win.addEventListener("open", function(e){
alert("window appear");
});
But this is only call when first time it open..it is not called when screen open from back clicked.
Focus should work if you minimise the app or show the status bar, blur will also be triggered when the window loses focus.
It sounds like you are never closing the window or you are registering the event listeners inside another function, ensure the event listeners are defined at the top level (not in any other functions).
Console.log doesn't work very well in titanium use Ti.API.info('Alert message');
Is there a way to detect a click and hold within a NSView? I want to trigger an event after holding the mouse button down for 0.5 sec - similar to a longPressGesture in iOS.
I don't know of a specific selector for this, which is what it sounds like you're asking for, but you could, quite easily, handle this yourself.
Start a timer when the mouse down event occurs and when the amount of time has passed, react to it if the mouse up event did not occur before the specified elapsed time.
Im using Ext JS 4. I have a button inside a container. I want the container to receive mouseover, mouseout, and click events, but the button is causing the mouseover and mouseout event handlers to be called twice on the container. How can i disable the events on the child button?
I believe you are running to 4.0's new bubbleEvents behavior. Components now propagate some events to their parent containers. This happens in code, independent of DOM event bubbling, up the component hierarchy.
http://dev.sencha.com/deploy/ext-4.0.0/docs/api/Ext.container.Container.html
The best fix is to simply stop the event once you've handled it. That should prevent all bubbling, component or DOM. It is generally a good idea to do this for click events to make sure one and only one thing happens in response to a click, but I'm less certain it's appropriate for mouseover and mouseout.
panel.on('click', function(e) {
e.stopEvent();
// do your stuff
});
another fix you could try (I haven't) is to wipe bubbleEvents on the button.
Another, possibly less robust fix is to turn on event buffering:
el.on('click', this.onClick, this, {buffer: 10});
Buffering collapses duplicate events in a configurable time window into one and it's useful for smoothing out rapid fire or duplicate UI events, but I'm not sure how it plays with bubbling.
{
...
preventDefault: true,
...
}