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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:36:45+00:00 2026-05-24T03:36:45+00:00

We have a map which uses polygons to create overlays on top of countries.

  • 0

We have a map which uses polygons to create overlays on top of countries. When a user hovers over a country the polygons change color.

When the mouse leave the country it changes back (or at least we want it to)

Us the code below what happens is that that both countries access the settings for JUST the last section of code. It seems all other code is overwritten.

I don’t know which variable to make unique.

for(var i = 0; i < germany.length; i++){
    addListener( germany[ i ], germany );
    }
function addListener( germany_item, tweened )
{   
    google.maps.event.addListener(germany_item, "mouseover",function() {
                    for( var i in tweened ) 
        tweened[ i ].setOptions({ fillColor: "#DD732B", strokeColor: "#DD732B" });
    });
    google.maps.event.addListener(germany_item, "mouseout",function() {
                    for( var i in tweened ) 
        tweened[ i ].setOptions({ fillColor: "#5EA9BD", strokeColor: "#5EA9BD" });
    });
}//
for(var i = 0; i < france.length; i++){
    addListener( france[ i ], france );
    }
function addListener( france_item, tweened )
{   
    google.maps.event.addListener(france_item, "mouseover",function() {
                    for( var i in tweened ) 
        tweened[ i ].setOptions({ fillColor: "#DD732B", strokeColor: "#DD732B" });
        });
    google.maps.event.addListener(france_item, "mouseout",function() {    
                    for( var i in tweened ) 
            tweened[ i ].setOptions({ fillColor: "#006886", strokeColor: "#006886" });
        });
  • 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-24T03:36:46+00:00Added an answer on May 24, 2026 at 3:36 am

    You cannot have two functions with the same name (you have two copies of function addListener()). If you do that, then only the last one will be active (which is what you were experiencing). I would suggest you either change the name of both functions to addListenerGermany() and addListenerFrance() or replace them both with one function and pass in the minor difference between the two as a parameter so you can serve both need with one block of code.

    For example, you could change it all to this:

    for (var i = 0; i < germany.length; i++) {
        addListenerCommon( germany[ i ], germany , "#5EA9BD", "#5EA9BD");
    }
    
    for(var i = 0; i < france.length; i++) {
        addListenerCommon( france[ i ], france, "#006886", "#006886" );
    }
    
    function addListenerCommon(item, tweened, fill, stroke ) {   
        google.maps.event.addListener(item, "mouseover",function() {
            for( var i in tweened ) {
                tweened[ i ].setOptions({ fillColor: "#DD732B", strokeColor: "#DD732B" });
            }
        });
        google.maps.event.addListener(item, "mouseout",function() {
            for( var i in tweened ) {
                tweened[ i ].setOptions({ fillColor: fill, strokeColor: stroke });
            }
        });
    }
    

    If you’re going to add more countries, then you can make a function for the for loop:

    function initCountry(country, fill, stroke) {
        for (var i = 0; i < country.length; i++) {
            addListenerCommon(country[i], country, fill, stroke);
        }
    }
    
    initCountry(germany, "#5EA9BD", "#5EA9BD");
    initCountry(france, "#006886", "#006886");
    initCountry(australia, "#FF6886", "#FF6886");
    

    and so on…

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

Sidebar

Related Questions

I have a Google V3 map which uses steetView and some map markers. The
I have a legacy DB which uses a guid to map children to the
I have a Haskell program which uses Data.Map.! at several places. After executing the
I have an app which uses the user's location. I have a dialog(pic below)
I have developed an app which uses google map. The problem is when I
I have an OpenLayers map, which uses OpenSpace as a base layer, and is
I have a dynamic web project in eclipse, which uses annotations to map servlets
I want to have a map (which is image-mapped) show green in areas where
I have a terrain map which i would like to represent some data in.
I have made a map with jQuery which is split up in many regions,

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.