I'm following the Google Maps API v3 ImageMapType example here: https://developers.google.com/maps/documentation/javascript/examples/maptype-image
But, I don't have a clear understanding from the documentation how the tiles/zoom work. For now, I'm just trying to get it to work with 0 zoom. Once I tackle that, then I can figure out the zoom piece.
My image is 2000px X 2000px. I've sliced it up into 8 tiles by 8 tiles at 250px X 250px per tile.
I am doing console.log on getTileUrl. I was expecting to see all 64 of my tiles loaded from 0-0.png to 7-7.png But, I'm seeing 0-0.png attempt to load nine times.
I've created this http://jsfiddle.net/2N2sy/1/ (code below) to simulate my code.
Help unraveling the tiles/zoom would be greatly appreciated!
function getNormalizedCoord(coord, zoom) {
var y = coord.y;
var x = coord.x;
// tile range in one direction range is dependent on zoom level
// 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc
var tileRange = 1 << zoom;
// don't repeat across y-axis (vertically)
if (y < 0 || y >= tileRange) {
return null;
}
// repeat across x-axis
if (x < 0 || x >= tileRange) {
x = (x % tileRange + tileRange) % tileRange;
}
return {
x: x,
y: y
};
}
var map;
function initMaps() {
$.getScript("http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js").done(function (script, textStatus) {
var customMapTypeOptions = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
console.log('http://img.photobucket.com/albums/v229/s15199d/ + normalizedCoord.x + '-' + (bound - normalizedCoord.y - 1) + '.png');
return 'http://img.photobucket.com/albums/v229/s15199d/ + normalizedCoord.x + '-' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(250, 250),
maxZoom: 0,
minZoom: 0,
radius: 1738000,
name: 'custom map'
};
var customMapType = new google.maps.ImageMapType(customMapTypeOptions);
var latlng = new google.maps.LatLng(0, 0), // center point
mapOptions = {
zoom: 0,
center: latlng,
draggable: true,
scrollwheel: false,
mapTypeControl: false,
panControl: false,
scaleControl: false,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.RIGHT_TOP
},
streetViewControl: false,
streetViewControlOptions: {
position: google.maps.ControlPosition.RIGHT_TOP
},
mapTypeControlOptions: {
mapTypeIds: ['custom map']
}
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
map.mapTypes.set('custom map', customMapType);
map.setMapTypeId('custom map');
});
}
$(function () {
if (window.google && google.maps) {
//alert("Map script is already loaded. Initializing");
initMaps();
} else {
//alert("Lazy loading Google map...");
lazyLoadGoogleMap();
}
});
function lazyLoadGoogleMap() {
$.getScript("http://maps.google.com/maps/api/js?sensor=true&callback=initMaps")
.done(function (script, textStatus) {
//alert("Google map script loaded successfully");
})
.fail(function (jqxhr, settings, ex) {
//alert("Could not load Google Map script: " + jqxhr);
});
}