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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:41:01+00:00 2026-06-09T09:41:01+00:00

I am trying to get Google maps to display an image I can use

  • 0

I am trying to get Google maps to display an image I can use to zoom. I have used this tutorial for most of the work but I am running into two problems.

  1. The image I am trying to display naturally is 256×193. The image gets stretched to fit 256×256. How can I let google maps know to only display the image at 256×193.
  2. I am trying to bound the box so that the image is always in view and never the background. I am close but I was hopping for a better solution. The one I am using only bounds the center. I can still partially see the map background if I pan.

    var allowedBounds = null;
    var lastValidCenter = null;
    
    google.maps.event.addListenerOnce(map, 'idle', function(){
        allowedBounds = map.getBounds();
        lastValidCenter = map.getCenter();
    });    
    
    google.maps.event.addListener(map, 'center_changed', function() {
        if (allowedBounds.contains(map.getCenter())) {
        lastValidCenter = map.getCenter();
            return; 
        }
    
        map.panTo(lastValidCenter);
    });
    

PS. I am using Google because I kind of have a crush on them for all things. If there is a better more standard solution that lets me zoom with multiple image levels please let me know.

UPDATE: I got the random image size working! The code bellow modifies what the above tutorial started

    Demo.ImgMapType.prototype.imageSize= new google.maps.Size(256, 193);
    Demo.ImgMapType.prototype.getTile = function (coord, zoom, ownerDocument) {
        var tilesCount = Math.pow(2, zoom);
        var maxWidth = this.imageSize.width * tilesCount;
        var maxHeight = this.imageSize.height * tilesCount;
        var width = this.tileSize.width;
        var height = this.tileSize.height;
        var maxX = width * (1 + coord.x);
        var maxY = height * (1 + coord.y);
        if (maxX > maxWidth){
            width = width - (maxX - maxWidth);
        }
        if (maxY > maxHeight){
            height = height - (maxY - maxHeight);
        }

        var div = ownerDocument.createElement('div');
        div.style.width = this.tileSize.width + 'px';
        div.style.height = this.tileSize.height + 'px';
        div.style.backgroundColor = this._backgroundColor;

        if (width <= 0 || coord.x < 0 || height <= 0 || coord.y < 0) {
            return div;    
        }

        var img = ownerDocument.createElement('IMG');
        img.width = width;
        img.height = height;
        img.src = Demo.Utils.GetImageUrl(this._theme + '_' + zoom + '_' + coord.x + '_' + coord.y + '.jpg');
        // Add the image to the div so that we hide the map background
        div.appendChild(img);
        return 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-09T09:41:03+00:00Added an answer on June 9, 2026 at 9:41 am

    I got the random image size working! The code bellow modifies what the tutorial I mentioned started

        Demo.ImgMapType.prototype.imageSize= new google.maps.Size(256, 193);
        Demo.ImgMapType.prototype.getTile = function (coord, zoom, ownerDocument) {
            var tilesCount = Math.pow(2, zoom);
            var maxWidth = this.imageSize.width * tilesCount;
            var maxHeight = this.imageSize.height * tilesCount;
            var width = this.tileSize.width;
            var height = this.tileSize.height;
            var maxX = width * (1 + coord.x);
            var maxY = height * (1 + coord.y);
            if (maxX > maxWidth){
                width = width - (maxX - maxWidth);
            }
            if (maxY > maxHeight){
                height = height - (maxY - maxHeight);
            }
    
            var div = ownerDocument.createElement('div');
            div.style.width = this.tileSize.width + 'px';
            div.style.height = this.tileSize.height + 'px';
            div.style.backgroundColor = this._backgroundColor;
    
            if (width <= 0 || coord.x < 0 || height <= 0 || coord.y < 0) {
                return div;    
            }
    
            var img = ownerDocument.createElement('IMG');
            img.width = width;
            img.height = height;
            img.src = Demo.Utils.GetImageUrl(this._theme + '_' + zoom + '_' + coord.x + '_' + coord.y + '.jpg');
            // Add the image to the div so that we hide the map background
            div.appendChild(img);
            return div;
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get Marker Manager to work on Google Maps V3. I've
I am trying to get into the google maps api v3 to display store
Ok, I use mootools to display flash content through google maps and I work
I am trying to build a Google Maps-driven web application that can display a
I'm trying to get mouseover to work polygons in google maps api v3. I've
I am trying to get google maps to work in my android project. I
I've been trying to get a certain Google API to work for two days
I'm trying to get mail(imap) from google by oauth authorization . I have got
I'm trying to get an overlay in google maps api v3 to appear above
I am trying to get a google API key to add google maps to

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.