Skip to content

Instantly share code, notes, and snippets.

@tkrajina
Created April 19, 2013 04:07
Show Gist options
  • Save tkrajina/5418085 to your computer and use it in GitHub Desktop.
Save tkrajina/5418085 to your computer and use it in GitHub Desktop.
OpenStreetMap images layer on Google Map
map.mapTypes.set("OSM", new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
var imagesPerUnit = Math.pow(2, zoom);
// Stitch horizontaly:
var x = coord.x < 0 ? imagesPerUnit + (coord.x % imagesPerUnit) : coord.x;
var x = x >= imagesPerUnit ? 0 : x;
// Do not stitch verticaly, if overflow -- don't show:
if(coord.y < 0 || coord.y >= imagesPerUnit)
return null;
return "http://tile.openstreetmap.org/" + zoom + "/" + x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
name: "OSM",
maxZoom: 18
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment