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 4598750
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:26:38+00:00 2026-05-21T23:26:38+00:00

I’m working on a map that has several pre-existing polygons. The polygons are outlined

  • 0

I’m working on a map that has several pre-existing polygons. The polygons are outlined and filled in red.

On mouseover, the infoWindow appears with the polygon’s title and on mouseout the infoWindow disappears, which is correct.

I’ve added a click event listener so that on click the polygon is outlined and filled with yellow to indicate the “current” polygon.

I have two problems with the mouseout and click events:

  1. If the user clicks on a second polygon, I want the first selected polygon to return to the original red fill/outline.

  2. The click event listener also makes the infoWindow appear over the selected polygon, but once the user hovers or mouses-over another polygon, the infoWindow disppears as it is canceled out by the mouseout event. I want the infoWindow to stay, and then I can add a z-index for any other infoWindows that appear on mouseover.

Code:

    var overlay = new google.maps.Polygon({
        paths: verticesArray,
        strokeColor: "#FF0000",
        strokeOpacity: 0.5,
        strokeWeight: 1,
        fillColor: "#FF0000",
        fillOpacity: 0.20,
        position: cent,
        map:map });

    function attachInfoWindow(overlay, number) {
      var infowindow = new google.maps.InfoWindow({ content: siteNames[number]});
      google.maps.event.addListener(overlay, 'mouseover', function() { infowindow.open(map, overlay); });
      google.maps.event.addListener(overlay, 'mouseout', function() { infowindow.close(map, overlay); });
      google.maps.event.addListener(overlay, 'click', function() {
            infowindow.open(map, overlay); 
            this.setOptions({ strokeColor: '#ffd100', fillColor:"#ffd100", fillOpacity:0.5,
      });
    });

I’m not good at javascript and am not sure how to fix these click and mouseout event problems.

Please let me know if more info is required or whether clarification is required.

MTIA.

  • 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-21T23:26:38+00:00Added an answer on May 21, 2026 at 11:26 pm

    I shall try to answer your questions.

    1)
    One thing you can do is have a global variable called selectedPolygon, and each time a user presses a Polygon, you change the color of the previously selectedPolygon, and set the variable to point to the Polygon the user have just pressed. This sort of thing have worked well for me in the past.

    2)
    I am pretty sure there is no immediate way to say “Don’t run the mouseout event”. A solution, although not that pretty, could be to have a global array filled with all the infowindows you want to stay open. Then in your mouseout event you run through that array and check whether the infowindow is in the array, and if it’s not you close it.
    You must ofc remember to remove the infowindows from the array and close them when you don’t want them to be showed anymore 🙂

    Hope this helped.

    EDIT

    Here’s a small example where I use the technique on a infowindow to make sure an open one closes if you try to open a new one:

    var currentinfowindow = null;
    
    function addeventlistenerinfo(marker, infowindow, i){
            google.maps.event.addListener(marker, 'click', function() {
                    if (currentinfowindow)
                        currentinfowindow.close();
                    infowindow.open(map,marker);
                    currentinfowindow = infowindow;
                });
        }
    

    The code is two snippets and consists of the global variable currentinfowindow, and the function addeventlistenerinfo.

    The function simply makes a eventlistener for your marker, and you could do this for your overlay instead. The whenever you run the event, you check whether the global variable has a value, and then do your rutine that sets the color of the different Polygons.

    This is the best example I can come with right now. Hope it helps to clarify it a bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.