Hi everyone,
I’m new to this forum, so let me introduce myself first. I’m a software developer for a french company in security and I’m working on a mobile app (targeted for Android first, and then for iOS but later in the project) for civil aviation. I’ve been using Ionic for my project since 6 month now and I have to say that I love it!
Now here’s my problem. It’s been several days I’m stuck with it after having tried some many different thins and read a lot of post on this forum or to some place else. I am using Google Maps API within my application. More particularly I am showing a map inside a ion-content of a modal view. The purpose of this map is to let the user placing a marker on the map to select geographic coordinates.
After having created the modal and create Google Maps instance within it, I register event listeners for mousedown and mouseup on the map object. The purpose is to create a timeout on mousedown that will place a marker with a 1 sec delay and cancel this timeout (if not already triggered) on mouseup (to be exhaustive, I do the same on other event like dragstart to avoid placing a marker when user is dragging map, but I am omitting it here for simplicity purpose).
This just work fine when using Chrome on PC, but on my Android test device (Nexus 7 2013) or using Chrome on PC with DevTool and “device mode” enabled, it does not work properly. The fact is that any touch event received by application is first captured by Ionic framework that will kind of “disabling” next touch event within the 2 next sec. Meaning that when I tap down, my application receive the mousedown event, but when I tap up, the event is never received if it happen less than 2 sec after being tap down. It results from that than even if I didn’t tap for 1 sec, a marker is placed on the map. Moreover, if I’m continuously tapping for less than 1 sec, only the first tap event is received.
The element which Google Maps is binding to is declared with:
data-tap-disabled="true"
So that’s not my issue. I have deeply look into Ionic’s code and have found that it ionic.tap is neutralizing event with a 2 sec delay using the function below:
// ionic.bundle.js v1.0.0-beta13 line 2781
function tapEnableTouchEvents() {
tapEnabledTouchEvents = true;
clearTimeout(tapMouseResetTimer);
tapMouseResetTimer = setTimeout(function(){
tapEnabledTouchEvents = false;
}, 2000);
}
I have commented that code into Ionic for test purpose and It works perfectly on both my Android device and Chrome DevTool in device mode but then I have some weird behavior in other parts of my app. So I want to understand what I am doing wrong? I’m sure that someone had already did this before in its app, so it may be possible. Is there something I forgot somewhere? Or maybe I’m totally wrong and that not the correct way to place a marker on map with a “long press”?
I’m not sure if it’s a Ionic or Google Maps issue so I’m asking for your help. Here is a CodePen of a very simplified version which just work perfectly on Chrome, but if you are using Chrome DevTools (by pressing F12 while on the page) and then enabling “device mode” (by clicking the phone icon on the top-left corner of DevTool and then reloading the page with F5), you will see that it does not work anymore. I put some console log on map mousedown and mouseup event so you can see that event are received when device mode is off but not when device mode is on:
Thanks in advance for your help.