ol-demo.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <script src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-us'></script>
  4. <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
  5. <script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script>
  6. <link rel="stylesheet" href="/geoserver/style.css" type="text/css" />
  7. <link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css" />
  8. <style type="text/css">
  9. body {
  10. margin: 1em;
  11. }
  12. #map {
  13. width: 95%;
  14. height: 512px;
  15. border: 1px solid gray;
  16. }
  17. div.olControlMousePosition {
  18. color: white;
  19. }
  20. #bounds {
  21. font-size: 0.9em;
  22. }
  23. </style>
  24. <script src="http://openlayers.org/api/OpenLayers.js"></script>
  25. <script type="text/javascript">
  26. // make map available for easy debugging
  27. var map;
  28. // avoid pink tiles
  29. OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
  30. OpenLayers.Util.onImageLoadErrorColor = "transparent";
  31. function init(){
  32. /**
  33. * The commercial layers (Google, Virtual Earth, and Yahoo) are
  34. * in a custom projection - we're calling this Spherical Mercator.
  35. * GeoServer understands that requests for EPSG:900913 should
  36. * match the projection for these commercial layers. Note that
  37. * this is not a standard EPSG code - so, if you want to load
  38. * layers from another WMS, it will have to be configured to work
  39. * with this projection.
  40. */
  41. var options = {
  42. // the "community" epsg code for spherical mercator
  43. projection: "EPSG:900913",
  44. // map horizontal units are meters
  45. units: "m",
  46. // this resolution displays the globe in one 256x256 pixel tile
  47. maxResolution: 78271.51695,
  48. // these are the bounds of the globe in sperical mercator
  49. maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
  50. 20037508, 20037508)
  51. };
  52. // construct a map with the above options
  53. map = new OpenLayers.Map('map', options);
  54. // create Google layer
  55. var gsat = new OpenLayers.Layer.Google(
  56. "Google Satellite",
  57. {type: G_SATELLITE_MAP, sphericalMercator: true}
  58. );
  59. // create Virtual Earth layer
  60. var veaer = new OpenLayers.Layer.VirtualEarth("Bing maps", {
  61. type: VEMapStyle.Aerial, sphericalMercator: true
  62. });
  63. // create Yahoo layer (only the default layer works, the hibrid and the
  64. // satellite ones do throw exceptions and rendering goes totally bye bye)
  65. var yahoosat = new OpenLayers.Layer.Yahoo("Yahoo", {
  66. sphericalMercator: true
  67. });
  68. // you can create your own layers here
  69. // create WMS layer
  70. var wms = new OpenLayers.Layer.WMS(
  71. "TOPP States",
  72. "http://localhost:8080/geoserver/wms?",
  73. {
  74. layers: 'topp:states',
  75. styles: '',
  76. srs: 'EPSG:4326',
  77. format: 'image/png',
  78. tiled: 'true',
  79. tilesOrigin : "143.60260815000004,-43.851764249999995",
  80. transparent: true
  81. },
  82. {
  83. 'opacity': 0.75, 'isBaseLayer': false, 'wrapDateLine': true
  84. }
  85. );
  86. var usBounds = new OpenLayers.Bounds(
  87. -14392000, 2436200, -7279500, 6594375
  88. );
  89. // add the created layers to the map
  90. // (if you want custom layers to show up they must be here as well)
  91. map.addLayers([gsat, veaer, yahoosat, wms]);
  92. map.addControl(new OpenLayers.Control.LayerSwitcher());
  93. map.addControl(new OpenLayers.Control.MousePosition());
  94. map.zoomToExtent(usBounds);
  95. // the part below is just to make the bounds show up on the page
  96. var boundsOutput = document.getElementById('bounds');
  97. function updateBounds() {
  98. var code =
  99. " var bounds = new OpenLayers.Bounds(\n" +
  100. " " + map.getExtent().toBBOX().replace(/,/g, ', ') + "\n" +
  101. " );\n" +
  102. " map.zoomToExtent(bounds);"
  103. boundsOutput.innerHTML = code;
  104. }
  105. // update the bounds with each map move
  106. map.events.register('moveend', map, updateBounds);
  107. // and update the bounds on first load
  108. updateBounds();
  109. }
  110. </script>
  111. </head>
  112. <body onload="init()">
  113. <h3>Geoserver OpenLayers Demo</h3>
  114. <div id="map"></div>
  115. <p>In creating your own OpenLayers application, you can use the bounds shown
  116. above as your initial extent. For example, the following code would zoom
  117. your map to the current extent:
  118. </p>
  119. <pre id="bounds"></pre>
  120. </body>
  121. </html>