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

  • Home
  • SEARCH
  • 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 8531211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:25:54+00:00 2026-06-11T09:25:54+00:00

I am working with Google Maps and I am trying to create a sidebar

  • 0

I am working with Google Maps and I am trying to create a sidebar that enables different KML overlays. I have put the KML layers into variables with the same as the ID tag of the button to press to activate them, in hopes to call that ID as the variable, which can then be used in the setMap function.
Not sure if this is actually possible

In this script here I am trying to make it so you press element with ID tag ‘kml1′, set testvar=’kml1’, and then be able to put testvar.setMap(the_Map) in place of kml1.setMap(the_Map), as testvar==kml1

jQuery

kml1 = new google.maps.KmlLayer("http://www.domain.com/map_overlay1.txt", {
            preserveViewport: true,
        });
        kml2 = new google.maps.KmlLayer("http://www.odomain.com/map_overlay2.txt", {
            preserveViewport: true,
        });

    $(document).ready(function() {
        $('.kml_item').toggle(
                function() {
                    for (i=0; i<50; i++) {
                        testvar = this.id
                        if (testvar == 'kml' + i) {
                            testvar.setMap(the_Map);
                            break;
                        }
                    }
                },
                function() {
                    for (i=0; i<50; i++) {
                        testvar = this.id
                        if (testvar == 'kml' + i) {
                            testvar.setMap(null);
                            break;
                        }
                    }
            );
    })

associated HTML

<div id="kml1" class="kml_item">KML 1</div>
            <div id="kml2" class="kml_item">KML 2</div>
  • 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-06-11T09:25:56+00:00Added an answer on June 11, 2026 at 9:25 am

    Not sure if it’s really kosher to answer your own question on this site, but I figured out another method, although I do believe my initial problem of using an ID tag as a variable is unsolvable the way I was approaching it. Instead of each KML layer in a separate variable, I put them together in an array. Giving the clickable divs a number for a title tag allows the function to then count up until the array item matches the title number for the div and places that item from the array onto the map.

    KML array

    kml_arr = [
                new google.maps.KmlLayer("http://www.domain.com/map_overlay1.txt", {
                preserveViewport: true,
            }),
                new google.maps.KmlLayer("http://www.domain.com/map_overlay2.txt", {
                preserveViewport: true,
            })
            ]
    

    jQuery

    $(document).ready(function() {
            $('.kml_item').toggle(
                    function() {
                        $(this).animate({backgroundColor: '#ffffff'}, 200);
                        for (i=0; i<50; i++) {
                            if (i == this.title) {
                                kml_arr[i].setMap(the_Map);
                                break;
                            }
                        }
                    },
                    function() {
                        $(this).animate({backgroundColor: '#d0d0d0'}, 200);
                        for (i=0; i<50; i++) {
                            if (i == this.title) {
                                kml_arr[i].setMap(null);
                                break;
                            }
                        }
                    }
                );
        })
    

    associated HTML

                    <div title="0" id="kml1" class="kml_item">KML 1</div>
                <div title="1" id="kml2" class="kml_item">KML 2</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in Google Maps and have three+ tile overlays to create. An
I'm working on an application that uses the Google Maps API. I have no
I have jQuery mobile working with google maps so that I can display one,
I'm working on a GWT app that's using Google Maps. I'm trying to add
I just started working using Google Maps API yesterday, and trying to set up
Working with Google Maps, I have the following code: var tileNames = [base, parking,
I'm working with Google Maps API v3 and I have an array of markers
I have a v3 Google Maps working fine with dynamic markers but I am
I'm trying to create map (using the Google Maps JavaScript API V3 ) which
I am trying to create a custom google map using Longitudes and Latitudes that

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.