Guest User

Untitled

a guest
May 1st, 2012
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.67 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Salem world map</title>
  5. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  6. <style type="text/css">
  7.     html { height: 100% }
  8.     body { height: 100%; margin: 0px; padding: 0px }
  9.     #map_canvas { height: 100% }
  10. </style>
  11. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  12. <script type="text/javascript">
  13.  
  14. var currentSession = 0;
  15.  
  16. function myProjection() {
  17.     var MAP_RANGE = 51200;
  18.     this.worldOrigin_ = new google.maps.Point(0, 0);
  19.     this.pixelsPerLonDegree_ = MAP_RANGE / 360;
  20.     this.pixelsPerLatDegree_ = MAP_RANGE / 180;
  21. };
  22.  
  23. myProjection.prototype.fromLatLngToPoint = function(latLng) {
  24.     var origin = this.worldOrigin_;
  25.     var x = origin.x + latLng.lng() * this.pixelsPerLonDegree_;
  26.     var y = origin.y + latLng.lat() * this.pixelsPerLatDegree_;
  27.     return new google.maps.Point(x, y);
  28. };
  29.  
  30. myProjection.prototype.fromPointToLatLng = function(point) {
  31.     var origin = this.worldOrigin_;
  32.     var lng = (point.x - origin.x) / this.pixelsPerLonDegree_;
  33.     var lat = (point.y - origin.y) / this.pixelsPerLatDegree_;
  34.     return new google.maps.LatLng(lat, lng);
  35. };
  36.  
  37. function CoordMapType(tileSize) {
  38.     this.tileSize = tileSize;
  39. }
  40.  
  41. CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
  42.     var div = ownerDocument.createElement('DIV');
  43.     div.innerHTML = coord;
  44.     div.style.width = this.tileSize.width + 'px';
  45.     div.style.height = this.tileSize.height + 'px';
  46.     div.style.fontSize = '16px';
  47.     div.style.borderStyle = 'solid';
  48.     div.style.borderWidth = '1px';
  49.     div.style.borderColor = 'yellow';
  50.     div.style.color = 'yellow';
  51.     return div;
  52. };
  53.  
  54. function HomeControl(controlDiv, map) {
  55.     controlDiv.style.padding = '5px';
  56.     var controlUI = document.createElement('DIV');
  57.     controlUI.style.backgroundColor = 'white';
  58.     controlUI.style.borderStyle = 'solid';
  59.     controlUI.style.borderWidth = '2px';
  60.     controlUI.style.cursor = 'pointer';
  61.     controlUI.style.textAlign = 'center';
  62.     controlUI.title = 'Click to go to start point';
  63.     controlDiv.appendChild(controlUI);
  64.     var controlText = document.createElement('DIV');
  65.     controlText.style.fontFamily = 'Arial,sans-serif';
  66.     controlText.style.fontSize = '12px';
  67.     controlText.style.paddingLeft = '4px';
  68.     controlText.style.paddingRight = '4px';
  69.     controlText.innerHTML = 'Go to start point';
  70.     controlUI.appendChild(controlText);
  71.     google.maps.event.addDomListener(controlUI, 'click', function() {
  72.         map.setCenter(new google.maps.LatLng(0, 0))
  73.     });
  74. }
  75.  
  76. function GridControl(controlDiv, map) {
  77.     controlDiv.style.padding = '5px';
  78.     var controlUI = document.createElement('DIV');
  79.     controlUI.style.backgroundColor = 'white';
  80.     controlUI.style.borderStyle = 'solid';
  81.     controlUI.style.borderWidth = '2px';
  82.     controlUI.style.cursor = 'pointer';
  83.     controlUI.style.textAlign = 'center';
  84.     controlUI.title = 'Click to show or hide grid';
  85.     controlDiv.appendChild(controlUI);
  86.     var controlText = document.createElement('DIV');
  87.     controlText.style.fontFamily = 'Arial,sans-serif';
  88.     controlText.style.fontSize = '12px';
  89.     controlText.style.paddingLeft = '4px';
  90.     controlText.style.paddingRight = '4px';
  91.     controlText.innerHTML = 'Show/Hide grid';
  92.     controlUI.appendChild(controlText);
  93.     google.maps.event.addDomListener(controlUI, 'click', function() {
  94.         if (map.overlayMapTypes.getLength()) {
  95.             map.overlayMapTypes.pop();
  96.         }
  97.         else {
  98.             map.overlayMapTypes.push(new CoordMapType(new google.maps.Size(100, 100)))
  99.         }
  100.     });
  101. }
  102.  
  103.  
  104. function initialize() {
  105.  
  106.     var map;
  107.  
  108.     var myMapType = new google.maps.ImageMapType({
  109.         tileSize: new google.maps.Size(100, 100),
  110.         minZoom: 9,
  111.         maxZoom: 9,
  112.         getTileUrl: function(coord, zoom) {
  113.             currentSession = window.location.href.replace('map.html', '');
  114.             return currentSession + '/tile_' + coord.x + '_' + coord.y + '.png';
  115.         },
  116.         isPng: true
  117.     });
  118.  
  119.     myMapType.projection = new myProjection();
  120.  
  121.     var mapOptions = {
  122.         center: new google.maps.LatLng(0, 0),
  123.         mapTypeControl: false,
  124.         backgroundColor: '#E0C191',
  125.         zoom: 9
  126.     }
  127.  
  128.     map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  129.     map.mapTypes.set('myMapType', myMapType);
  130.     map.setMapTypeId('myMapType');
  131.  
  132.     var homeControlDiv = document.createElement('DIV');
  133.     var homeControl = new HomeControl(homeControlDiv, map);
  134.     homeControlDiv.index = 1;
  135.     map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
  136.     var gridControlDiv = document.createElement('DIV');
  137.     var gridControl = new GridControl(gridControlDiv, map);
  138.     gridControlDiv.index = 2;
  139.     map.controls[google.maps.ControlPosition.TOP_RIGHT].push(gridControlDiv);
  140. }
  141.  
  142. </script>
  143. </head>
  144. <body onload="initialize()">
  145.     <div id="map_canvas" style="width:100%; height:100%"></div>
  146. </body>
  147. </html>
Advertisement
Add Comment
Please, Sign In to add comment