Resizable Split Map Panes Stay organized with collections Save and categorize content based on your preferences.
Page Summary
This example demonstrates how to compare two Google Maps layers side-by-side using resizable panes.
It utilizes the Split.js library to create and manage the resizable panes for a seamless user experience.
The code synchronizes the two map instances, ensuring that they maintain the same center and zoom level as the user interacts with either pane.
Both TypeScript and JavaScript code snippets are provided, along with HTML and CSS for styling and structure.
Users can clone and run the sample locally using Git and Node.js or try it directly in Google Cloud Shell.
Comparing layers
This example allows comparison of two layers with resizable map panes using theSplit.jslibrary.
TypeScript
functioninitMap():void{constmapOptions={center:{lat:44.5250489,lng:-110.83819},zoom:18,scaleControl:false,streetViewControl:false,};// instantiate the map on the left with control positioningmapLeft=newgoogle.maps.Map(document.getElementById("map-left")asHTMLElement,{...mapOptions,mapTypeId:"satellite",tilt:0,// at high zoom levels we need to maintain the same projectionfullscreenControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM,},mapTypeControlOptions:{position:google.maps.ControlPosition.LEFT_TOP,},zoomControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM,},});// instantiate the map on the right with control positioningmapRight=newgoogle.maps.Map(document.getElementById("map-right")asHTMLElement,{...mapOptions,fullscreenControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM,},mapTypeControlOptions:{position:google.maps.ControlPosition.RIGHT_TOP,},zoomControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM,},});// helper function to keep maps in syncfunctionsync(...maps:google.maps.Map[]){letcenter:google.maps.LatLng,zoom:number;functionupdate(changedMap){maps.forEach((m)=>{if(m===changedMap){return;}m.setCenter(center);m.setZoom(zoom);});}maps.forEach((m)=>{m.addListener("bounds_changed",()=>{constchangedCenter=m.getCenter()!;constchangedZoom=m.getZoom()!;if(changedCenter!==center||changedZoom!==zoom){center=changedCenter;zoom=changedZoom;update(m);}});});}sync(mapLeft,mapRight);functionhandleContainerResize(){constwidth=(document.getElementById("container")asHTMLElement).offsetWidth;(document.getElementById("map-left")asHTMLElement).style.width=`${width}px`;(document.getElementById("map-right")asHTMLElement).style.width=`${width}px`;}// trigger to set map container size since using absolutehandleContainerResize();// add event listenerwindow.addEventListener("resize",handleContainerResize);//@ts-ignoreSplit(["#left","#right"],{sizes:[50,50],});}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
JavaScript
functioninitMap(){constmapOptions={center:{lat:44.5250489,lng:-110.83819},zoom:18,scaleControl:false,streetViewControl:false,};// instantiate the map on the left with control positioningmapLeft=newgoogle.maps.Map(document.getElementById("map-left"),{...mapOptions,mapTypeId:"satellite",tilt:0,// at high zoom levels we need to maintain the same projectionfullscreenControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM,},mapTypeControlOptions:{position:google.maps.ControlPosition.LEFT_TOP,},zoomControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM,},});// instantiate the map on the right with control positioningmapRight=newgoogle.maps.Map(document.getElementById("map-right"),{...mapOptions,fullscreenControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM,},mapTypeControlOptions:{position:google.maps.ControlPosition.RIGHT_TOP,},zoomControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM,},});// helper function to keep maps in syncfunctionsync(...maps){letcenter,zoom;functionupdate(changedMap){maps.forEach((m)=>{if(m===changedMap){return;}m.setCenter(center);m.setZoom(zoom);});}maps.forEach((m)=>{m.addListener("bounds_changed",()=>{constchangedCenter=m.getCenter();constchangedZoom=m.getZoom();if(changedCenter!==center||changedZoom!==zoom){center=changedCenter;zoom=changedZoom;update(m);}});});}sync(mapLeft,mapRight);functionhandleContainerResize(){constwidth=document.getElementById("container").offsetWidth;document.getElementById("map-left").style.width=`${width}px`;document.getElementById("map-right").style.width=`${width}px`;}// trigger to set map container size since using absolutehandleContainerResize();// add event listenerwindow.addEventListener("resize",handleContainerResize);//@ts-ignoreSplit(["#left","#right"],{sizes:[50,50],});}window.initMap=initMap;
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;}#container,#left,#right,.map,.gutter{height:100%;}#left,#right,.gutter{float:left;position:relative;overflow:hidden;}#map-left{position:absolute;left:0;top:0;}#map-right{position:absolute;right:0;top:0;}.gutter{background-color:#eee;background-repeat:no-repeat;background-position:50%;}.gutter.gutter-horizontal{cursor:col-resize;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg==");}
HTML
<html> <head> <title>Split Map Panes</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/split.js/1.5.11/split.min.js"></script> <link rel="stylesheet" type="text/css" href="./style.css" /> <script type="module" src="./index.js"></script> </head> <body> <div> <div> <div></div> </div> <div> <div></div> </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-split-map-paneshttps://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-12-18 UTC.