Places UI Kit: A ready-to-use library that provides room for customization and low-code development. Try it out, and share yourinput on your UI Kit experience.

Overlaying an Image Map Type

  • This example demonstrates how to overlay an image representing a building's interior onto a Google Map using image tiles.

  • It utilizes thegoogle.maps.ImageMapType class to define the image overlay and its tile coordinates.

  • The code provides functionality to fetch and display image tiles within specified zoom levels and bounds.

  • A predefined set of image tiles is used, and the example showcases how to integrate them with the map.

  • Users can explore the interactive example via provided links to JSFiddle and Google Cloud Shell, or clone the sample code for local execution.

This example uses image tiles to overlay an image that represents the interiorof a building onto the map.

Read thedocumentation.

TypeScript

functioninitMap():void{constmap=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{zoom:18,center:{lat:37.783,lng:-122.403},});constbounds:Record<number,[[number,number],[number,number]]>={17:[[20969,20970],[50657,50658],],18:[[41939,41940],[101315,101317],],19:[[83878,83881],[202631,202634],],20:[[167757,167763],[405263,405269],],};constimageMapType=newgoogle.maps.ImageMapType({getTileUrl:function(coord,zoom){if(zoom <17||zoom >20||bounds[zoom][0][0] >coord.x||coord.x >bounds[zoom][0][1]||bounds[zoom][1][0] >coord.y||coord.y >bounds[zoom][1][1]){return"";}return["https://www.gstatic.com/io2010maps/tiles/5/L2_",zoom,"_",coord.x,"_",coord.y,".png",].join("");},tileSize:newgoogle.maps.Size(256,256),});map.overlayMapTypes.push(imageMapType);}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
Note: Read theguide on using TypeScript and Google Maps.

JavaScript

functioninitMap(){constmap=newgoogle.maps.Map(document.getElementById("map"),{zoom:18,center:{lat:37.783,lng:-122.403},});constbounds={17:[[20969,20970],[50657,50658],],18:[[41939,41940],[101315,101317],],19:[[83878,83881],[202631,202634],],20:[[167757,167763],[405263,405269],],};constimageMapType=newgoogle.maps.ImageMapType({getTileUrl:function(coord,zoom){if(zoom <17||zoom >20||bounds[zoom][0][0] >coord.x||coord.x >bounds[zoom][0][1]||bounds[zoom][1][0] >coord.y||coord.y >bounds[zoom][1][1]){return"";}return["https://www.gstatic.com/io2010maps/tiles/5/L2_",zoom,"_",coord.x,"_",coord.y,".png",].join("");},tileSize:newgoogle.maps.Size(256,256),});map.overlayMapTypes.push(imageMapType);}window.initMap=initMap;
Note: The JavaScript is compiled from the TypeScript snippet.

CSS

/* * Always set the map height explicitly to define the size of the div element * that contains the map. */#map{height:100%;}/* * Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}

HTML

<html>  <head>    <title>Overlaying an Image Map Type</title>    <link rel="stylesheet" type="text/css" href="./style.css" />    <script type="module" src="./index.js"></script>  </head>  <body>    <div></div>    <!--       The `defer` attribute causes the script to execute after the full HTML      document has been parsed. For non-blocking uses, avoiding race conditions,      and consistent behavior across browsers, consider loading using Promises. See      https://developers.google.com/maps/documentation/javascript/load-maps-js-api      for more information.      -->    <script      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"      defer    ></script>  </body></html>

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow theseinstructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

gitclone-bsample-maptype-image-overlayhttps://github.com/googlemaps/js-samples.gitcdjs-samplesnpminpmstart

Other samples can be tried by switching to any branch beginning withsample-SAMPLE_NAME.

gitcheckoutsample-SAMPLE_NAMEnpminpmstart

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-21 UTC.