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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:47:15+00:00 2026-06-05T12:47:15+00:00

I have this layer with Google Maps: (note the generateAPIKey() function inside the getTileUrl

  • 0

I have this layer with Google Maps: (note the generateAPIKey() function inside the getTileUrl function)

    var options ={
      center:new google.maps.LatLng(somelat,somelon),
      zoom:14,
      disableDefaultUI:true,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      minZoom:11,
      maxZoom:16, 
    };

    var map = new google.maps.Map(document.getElementById('map_canvas'),options);

    var myLayerOptions = {
      getTileUrl: function(coord, zoom) {
        return 'http://localhost/mylayer/'+zoom+'/'+coord.x+'/'+coord.y+'.png&apikey='+ generateAPIKey();
      },
      tileSize: new google.maps.Size(256, 256),
      isPng: true,
      opacity:1.0
    };
    var myLayerMapType = new google.maps.ImageMapType(myLayerOptions);
    map.overlayMapTypes.insertAt(0, myLayerMapType);

So my main problem is that I have a dynamic API key for the service I’m using, with open layers I’ve got this:

var mylayer = new OpenLayers.Layer.XYZ(
    "mylayer",
    [
        "http://localhost/mylayer/${z}/${x}/${y}.png&apikey='+ generateAPIKey()
    ], {
        sphericalMercator: true,
        wrapDateLine: true,
        transitionEffect: "resize",
        buffer: 1,
        numZoomLevels: 17
    }
);

var map = new OpenLayers.Map({
    div: "map_canvas",
    layers: [mylayer],
    controls: [
        new OpenLayers.Control.Attribution(),
        new OpenLayers.Control.Navigation({
            dragPanOptions: {
                enableKinetic: true
            }
        }),
        new OpenLayers.Control.Zoom(),
        new OpenLayers.Control.Permalink({anchor: true})
    ],


       center: [somelat,somelon],
        zoom: 14

});

I understand what is wrong, the generateAPIKey function is only executed once. Is there something like the Google getTileUrl?

  • 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-05T12:47:16+00:00Added an answer on June 5, 2026 at 12:47 pm

    Yep, XYZ-layer has method getURL that gets called for every tile and looks like this:

        /**
         * Method: getURL
         *
         * Parameters:
         * bounds - {<OpenLayers.Bounds>}
         *
         * Returns:
         * {String} A string with the layer's url and parameters and also the
         *          passed-in bounds and appropriate tile size specified as
         *          parameters
         */
        getURL: function (bounds) {
            var xyz = this.getXYZ(bounds);
            var url = this.url;
            if (OpenLayers.Util.isArray(url)) {
                var s = '' + xyz.x + xyz.y + xyz.z;
                url = this.selectUrl(s, url);
            }
    
            return OpenLayers.String.format(url, xyz);
        }
    

    Just override this method and append your API key.

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

Sidebar

Related Questions

I am instantiating a Google Map object like so: this.map = new google.maps.Map(this.el, {
I am new to Google Maps, so I have most likely missed something very
I've imported the google maps street layer with arc2earth and produced a new one,
I'm using google maps for the page. I have to set up the layer
I tried to implement this code (http://stackoverflow.com/questions/10318316/how-to-hide-or-display-a-google-maps-layer/) on my page, to put the weather/clouds
I have one like this: CALayer *layer = stripeButton.layer; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@bounds.origin.y];
I have this sort of format asp.net MVC View -> Service Layer -> Repository.
I have a Div layer like this ... <style type=text/css> <!-- #newImg { position:absolute;
I have a project called Data which is a data layer. In this project,
I have a problem with IE. I have a layer that has this style

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.