Guest User

Untitled

a guest
May 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Tiled WMS</title>
  5. <link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
  6. <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  7. <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
  8. <script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js"></script>
  10. </head>
  11. <body>
  12. <div id="map" class="map"></div>
  13. <script>
  14.  
  15. ol.proj.setProj4(proj4);
  16. proj4.defs('EPSG:27700','+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs');
  17. const proj27700 = ol.proj.get('EPSG:27700');
  18. const center_point = [394108.6719, 331807.5317];
  19.  
  20. var parser = new ol.format.WMSCapabilities();
  21. var extentbox = []
  22.  
  23. fetch('http://localhost:8080/geoserver/cite/wms?request=getCapabilities&version=1.3.0').then(function(response) {
  24. return response.text();
  25. }).then(function(text) {
  26.  
  27. var result = parser.read(text);
  28. extentbox = result.Capability.Layer.Layer[2].BoundingBox[1].extent;
  29. tilesorigin = extentbox.slice(0,2);
  30. tilesorigin_string = tilesorigin.toString();
  31. proj27700.setExtent(extentbox);
  32. var projectionExtent = proj27700.getExtent();
  33.  
  34. var layers = [
  35. new ol.layer.Tile({
  36. opacity: 1,
  37. source: new ol.source.XYZ({
  38. attributions: 'Tiles © <a href="https://services.arcgisonline.com/ArcGIS/' +
  39. 'rest/services/World_Imagery/MapServer">ArcGIS</a> 2018',
  40. url: 'https://server.arcgisonline.com/ArcGIS/rest/services/' +
  41. 'World_Imagery/MapServer/tile/{z}/{y}/{x}'
  42. })
  43. }),
  44. new ol.layer.Tile({
  45. source: new ol.source.TileWMS({
  46. url: 'http://localhost:8080/geoserver/cite/wms',
  47. params: {'LAYERS': 'Flood 3', 'TILED': true, tilesorigin: tilesorigin_string},
  48. serverType: 'geoserver'
  49. })
  50. })
  51. ];
  52.  
  53. var map = new ol.Map({
  54. layers: layers,
  55. target: 'map',
  56. view: new ol.View({
  57. center: center_point,
  58. extent: projectionExtent,
  59. projection: proj27700,
  60. zoom: 3
  61. })
  62. });
  63. });
  64. </script>
  65. </body>
  66. </html>
Add Comment
Please, Sign In to add comment