Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. function getNormalizedCoord(coord, zoom) {
  2. var y = coord.y;
  3. var x = coord.x;
  4.  
  5. // tile range in one direction range is dependent on zoom level
  6. // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc
  7. var tileRange = 1 << zoom;
  8.  
  9. // don't repeat across y-axis (vertically)
  10. if (y < 0 || y >= tileRange) {
  11. return null;
  12. }
  13.  
  14. // repeat across x-axis
  15. if (x < 0 || x >= tileRange) {
  16. x = (x % tileRange + tileRange) % tileRange;
  17. }
  18.  
  19. return {
  20. x: x,
  21. y: y
  22. };
  23. }
  24.  
  25. var map;
  26.  
  27. function initMaps() {
  28.  
  29. $.getScript("http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js").done(function (script, textStatus) {
  30.  
  31. var customMapTypeOptions = {
  32. getTileUrl: function (coord, zoom) {
  33. var normalizedCoord = getNormalizedCoord(coord, zoom);
  34. if (!normalizedCoord) {
  35. return null;
  36. }
  37. var bound = Math.pow(2, zoom);
  38. console.log('http://img.photobucket.com/albums/v229/s15199d/ + normalizedCoord.x + '-' + (bound - normalizedCoord.y - 1) + '.png');
  39. return 'http://img.photobucket.com/albums/v229/s15199d/ + normalizedCoord.x + '-' + (bound - normalizedCoord.y - 1) + '.png';
  40. },
  41. tileSize: new google.maps.Size(250, 250),
  42. maxZoom: 0,
  43. minZoom: 0,
  44. radius: 1738000,
  45. name: 'custom map'
  46. };
  47.  
  48. var customMapType = new google.maps.ImageMapType(customMapTypeOptions);
  49.  
  50. var latlng = new google.maps.LatLng(0, 0), // center point
  51.  
  52. mapOptions = {
  53. zoom: 0,
  54. center: latlng,
  55. draggable: true,
  56. scrollwheel: false,
  57. mapTypeControl: false,
  58. panControl: false,
  59. scaleControl: false,
  60. zoomControl: true,
  61. zoomControlOptions: {
  62. style: google.maps.ZoomControlStyle.LARGE,
  63. position: google.maps.ControlPosition.RIGHT_TOP
  64. },
  65. streetViewControl: false,
  66. streetViewControlOptions: {
  67. position: google.maps.ControlPosition.RIGHT_TOP
  68. },
  69. mapTypeControlOptions: {
  70. mapTypeIds: ['custom map']
  71. }
  72. };
  73.  
  74. map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  75.  
  76. map.mapTypes.set('custom map', customMapType);
  77. map.setMapTypeId('custom map');
  78.  
  79. });
  80. }
  81.  
  82. $(function () {
  83. if (window.google && google.maps) {
  84. //alert("Map script is already loaded. Initializing");
  85. initMaps();
  86. } else {
  87. //alert("Lazy loading Google map...");
  88. lazyLoadGoogleMap();
  89. }
  90.  
  91. });
  92.  
  93. function lazyLoadGoogleMap() {
  94. $.getScript("http://maps.google.com/maps/api/js?sensor=true&callback=initMaps")
  95. .done(function (script, textStatus) {
  96. //alert("Google map script loaded successfully");
  97. })
  98. .fail(function (jqxhr, settings, ex) {
  99. //alert("Could not load Google Map script: " + jqxhr);
  100. });
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement