Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Context menu in mobile does not work on long taps. #562

Open
razumnyak opened this issue Aug 31, 2017 · 1 comment
Open

Context menu in mobile does not work on long taps. #562

razumnyak opened this issue Aug 31, 2017 · 1 comment

Comments

@razumnyak
Copy link

razumnyak commented Aug 31, 2017

I'm having a problem with mobile devices.
In the example does not work rightclick (long tap event)
https://hpneo.github.io/gmaps/examples/context_menu.html

file gmaps.js:441:

google.maps.event.addListener(this.map, 'rightclick', function(e) {
  if (options.rightclick) {
    options.rightclick.apply(this, [e]);
  }

  if(window.context_menu[self.el.id]['map'] != undefined) {
    self.buildContextMenu('map', e);
  }
});

https://stackoverflow.com/questions/45986000

@razumnyak
Copy link
Author

razumnyak commented Aug 31, 2017

Solving the problem, simulate a long click on the point.
befor:

        google.maps.event.addListener(this.map, 'rightclick', function (e) {

insert the code:

        /**
         * Start TIMER open context menu
         */
        google.maps.event.addListener(this.map, 'mousedown', function(e) {
            var context_menu_element = getElementById('gmaps_context_menu');

            document.pressTimer = window.setTimeout(function() {
                jQuery(context_menu_element).addClass('mouse_tap');

                if (options.rightclick) {
                    options.rightclick.apply(this, [e]);
                }

                if (window.context_menu[self.el.id]['map'] != undefined) {
                    self.buildContextMenu('map', e);
                }
            },1000);
            return false;
        });

        /**
         * Stop TIMER, and safe open or close context menu
         */
        google.maps.event.addListener(this.map, 'mouseup', function () {
            var context_menu_element = getElementById('gmaps_context_menu');

            if (jQuery(context_menu_element).hasClass('mouse_tap')){
                setTimeout(function () {
                    context_menu_element.style.display = 'block';
                }, 0);

                jQuery(context_menu_element).removeClass('mouse_tap');
            } else {
                this.hideContextMenu;
            }

            clearTimeout(document.pressTimer);
            return false;
        });

        /**
         * if we move the map - cancel the opening of the context menu
         */
        var context_menu_with_mouse = ['drag', 'dragend', 'dragstart'];
        for (var ev = 0; ev < context_menu_with_mouse.length; ev++) {
            (function (object, name) {
                google.maps.event.addListener(object, name, function () {
                    clearTimeout(document.pressTimer);
                    jQuery(getElementById('gmaps_context_menu')).removeClass('mouse_tap').css('display', 'none');
                    return false;
                });
            })(this.map, context_menu_with_mouse[ev] );
        }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant