Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:52:58+00:00 2026-05-25T02:52:58+00:00

I have this code for context menu and it’s working fine google.maps.event.addListener(map, ‘rightclick’, function(e)

  • 0

I have this code for context menu and it’s working fine

google.maps.event.addListener(map, 'rightclick', function(e)
{
    // start buy hiding the context menu if its open
    contextMenu.hide();

    var mapDiv = $(map.getDiv()),
        x = e.pixel.x,
        y = e.pixel.y;

    // save the clicked location
    clickedLatLng = e.latLng;

    // adjust if clicked to close to the edge of the map
    if ( x > mapDiv.width() - contextMenu.width() )
        x -= contextMenu.width();

    if ( y > mapDiv.height() - contextMenu.height() )
        y -= contextMenu.height();

    // Set the location and fade in the context menu
    contextMenu.css({ top: y, left: x }).fadeIn(100);
});

My question is why this isn’t working, the same thing but click is now startMarker *click*?

google.maps.event.addListener(startMarker, 'click', function(e) {
            // start buy hiding the context menu if its open
            contextMenu.hide();

            var mapDiv = $(map.getDiv()),
                x = e.pixel.x,
                y = e.pixel.y;

            // save the clicked location
            clickedLatLng = e.latLng;

            // adjust if clicked to close to the edge of the map
            if ( x > mapDiv.width() - contextMenu.width() )
                x -= contextMenu.width();

            if ( y > mapDiv.height() - contextMenu.height() )
                y -= contextMenu.height();

            // Set the location and fade in the context menu
            contextMenu.css({ top: y, left: x }).fadeIn(100);
          });

And the rest of the code

// Create the context menu element
var contextMenu = $(document.createElement('ul')).attr('id', 'contextMenu');

// Fill our context menu with links
contextMenu.append(
    '<li><a href=\"#startMenu\">Start</a></li>' +
    '<li><a href=\"#stopMenu\">End</a></li>'
);

// Disable the browser context menu on our context menu
contextMenu.bind('contextmenu', function() { return false; });

// Append it to the map object
$(map.getDiv()).append(contextMenu);


// Set some events on the context menu links
contextMenu.find('a').click( function()
{
    // fade out the menu
    contextMenu.fadeOut(75);

    // The link's href minus the #
    var action = $(this).attr('href').substr(1);

    switch (action) {
        case 'startMenu':
            $.get('something1.php', method1);
            break;

        case 'stopMenu':
            $.get('something2.php', method2);   
            break;
    }

    return false;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:52:59+00:00Added an answer on May 25, 2026 at 2:52 am

    I got to activate the context menu right click on the map and mark, steps:

    1) Create a new MapCanvasProjection to use fromLatLngToContainerPixel function:

    overlay = new google.maps.OverlayView();
    overlay.draw = function() {};
    overlay.setMap(map);
    

    2) For Each Marker include RightClick Listener:

    google.maps.event.addListener(marker, 'rightclick', function() {
    
        google.maps.event.trigger(map, 'rightclick', this);
    
    });
    

    3) Replace the RightClick Listener Map with:

    g.event.addListener(this.theMap, 'rightclick', function(e)
    {
    
                try { 
    
                var lpx =     overlay.getProjection().fromLatLngToContainerPixel(e.getPosition());
                var latLng_r=e.getPosition();
    
                } catch(err) { 
    
                var lpx=e.pixel;
                var latLng_r=e.latLng;
    
            }
    
            // Shorthand some stuff
            var mapDiv = $(self.theMap.getDiv()),
                   menu = self.theMenu,
                           x = lpx.x,
                   y = lpx.y;
    
            // Hide the context menu if its open
            menu.hide();
    
            // Save the clicked location
                self.clickedLatLng = latLng_r;
    
            // Adjust the menu if clicked to close to the edge of the map
            if ( x > mapDiv.width() - menu.width() )
                x -= menu.width();
    
                if ( y > mapDiv.height() - menu.height() )
                y -= menu.height();
    
            // Set the location and fade in the context menu
                    menu.css({ top: y, left: x }).fadeIn(200);
            });
    
            // Hide context menu on several events
            $.each('click dragstart zoom_changed maptypeid_changed center_changed'.split(' '), function(i,name){
                g.event.addListener(self.theMap, name, function(){ self.theMenu.hide(); });
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I have this code: <toolbox id=navigator-toolbox> <toolbar id=abar accesskey=T class=chromeclass-toolbar context=toolbar-context-menu hidden=false persist=hidden>
In my soundboard app I have created a context menu using this code. public
I have written the code to display a context menu on right click of
In my code I have a ListActivity . One of the context menu options
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.