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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:50:29+00:00 2026-06-06T10:50:29+00:00

I am working in Google Maps and have three+ tile overlays to create. An

  • 0

I am working in Google Maps and have three+ tile overlays to create. An example:

Tile Overlay

var parkingOptions = {                     //Parking Overlay
    getTileUrl: function(coord, zoom) {
        return "/maps/tiles/tilesparking/" + zoom + "_" + coord.x + "_" + coord.y + ".png";
    },
    tileSize: new google.maps.Size(256, 256)
};

var parkingMapType = new google.maps.ImageMapType(parkingOptions);

However, to avoid 404 errors by missing tiles outside of my mapping range, my code is a little more complex; thus, I intended to make a loop where a specific keyword assigned to each overlay (here given as “parking”) would be inserted into the above code. Thus:

For Loop

var tileNames = ["base", "parking", "access"];

for (var i = 0; i < tileNames.length; i++) {
    //insert Tile Overlay code here
};

However, I have one particular issue: I can not find a way to take the string from the tileNames array and use them in initializing the two variables in the Tile Overlay code. Ideally, I would like to achieve something like this:

Attempt 1

var tileNames[1] + "Options" = {  //ideally: var parkingOptions = {
    //insert remaining code
};

However this doesn’t work, nor did I really expect it to. Neither would trying to create those full strings and trying to insert it into the initialization:

Attempt 2

var newOptions = tileNames[1] + "Options";
var newOptions = {
    //insert remaining code
};

Thus, is there a way to do place a string into initializing variables?


Note: I have included my own alternative solution to the problem as an answer. It should work, but it destroys the names of the variables and replaces it with a nondescript array variable. I preferably would like to retain a descriptive variable name as they are used often in adding and hiding the overlays in the resulting code.


Solution For this question anyways…

var tileNames = ["beloit", "parking", "access"];
var mapType = {};

for (var i = 0; i < tileNames.length; i++) {
    var tileOptions = {
        getTileUrl: function(coord, zoom) {
            return "/maps/tiles/tiles" + tileNames[i] + "/" + zoom + "_" + coord.x + "_" + coord.y + ".png";
        },
        tileSize: new google.maps.Size(256, 256)
    };
    mapType[tileNames[i]] = new google.maps.ImageMapType(tileOptions);
};

The other part of the puzzle, the “tileNames[i]” in the getTileUrl function is undefined because the function wants it when it is executed rather than placing the name string into the function; however, that is a new question to be found here: Javascript: Making a variable static when defining a function in a loop?

  • 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-06T10:50:30+00:00Added an answer on June 6, 2026 at 10:50 am

    you can’t do this:

    var tileNames[1] + "Options" = {
      //insert remaining code
    };
    

    but you can do this:

    window['a'] = 'b';
    alert(a); // shows 'b'
    

    or if you are in a function

    this['a'] = 'b';
    

    EDIT:

    var obj = {};
    obj.a = 'a';
    // obj.a == obj['a']
    alert(obj['a']) // alerts a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with Google Maps, I have the following code: var tileNames = [base, parking,
I have my current google maps code working to the point where if I
I have a jqueryMobile app that uses google maps api and is working properly
I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
I have been playing with Google maps I had it working but when I
I have a v3 Google Maps working fine with dynamic markers but I am
I have multiple Google Maps on a single page. Scenario: Maps are working as
I'm working on an application that uses the Google Maps API. I have no
I've been unable to get the basic Google maps example working on my site.
I am working on WP7 , i have integrated google maps in map control.

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.