Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  2. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  3. </head>
  4. <body>
  5. <div class="row-fluid">
  6. <div class="span12">
  7. <div id="map" class="map"></div>
  8.  
  9. <div id="popup" class="ol-popup"> <a href="#" id="popup-closer" class="ol-popup-closer"></a>
  10. <a href="#" id="popup-closer" class="ol-popup-closer">X</a>
  11. <div id="popup-content"></div>
  12. </div>
  13. </div>
  14. </div>
  15. <script>
  16. var container = document.getElementById('popup');
  17. var content = document.getElementById('popup-content');
  18. var closer = document.getElementById('popup-closer');
  19. closer.onclick = function() {
  20. overlay.setPosition(undefined);
  21. closer.blur();
  22. return false;
  23. };
  24.  
  25. var layers = [
  26. new ol.layer.Tile({
  27. source: new ol.source.TileWMS({
  28. url: 'http://ndem.nrsc.gov.in/geoserver/wms',
  29. params: {'LAYERS': 'ndem50k:stateadmin50census2011'}
  30. })
  31. }),
  32.  
  33. new ol.layer.Tile({
  34. source: new ol.source.TileWMS({
  35. url: 'http://localhost:8089/geoserver/manjula/wms',
  36. params: {'LAYERS': 'manjula:prakasam'}
  37. })
  38. }),
  39. new ol.layer.Tile({
  40. source: new ol.source.TileWMS({
  41. url: 'http://localhost:8089/geoserver/manjula/wms',
  42. params: {'LAYERS': 'manjula:krishna'}
  43. })
  44. }),
  45.  
  46. new ol.layer.Tile({
  47. source: new ol.source.TileWMS({
  48. url: 'http://localhost:8089/geoserver/manjula/wms',
  49. params: {'LAYERS': 'manjula:guntur'}
  50. })
  51.  
  52. })
  53.  
  54. ];
  55. var container = document.getElementById('popup');
  56. var content = document.getElementById('popup-content');
  57. var popup = new ol.Overlay( /** @type {olx.OverlayOptions} */ ({
  58. element: container,
  59. autoPan: true,
  60. autoPanAnimation: {
  61. duration: 250
  62. }
  63. }));
  64. var mapcenter = [79.60,23.44];
  65. var map = new ol.Map({
  66. layers: layers,
  67. target: 'map',
  68. overlays: [popup],
  69. view: new ol.View({
  70. projection: 'EPSG:4326',
  71. center: mapcenter,
  72. zoom: 5,
  73. extent: [66.2329, 7.68083, 98.2223, 39.03874],
  74. maxZoom:16,
  75. minZoom: 4,
  76. })
  77. });
  78.  
  79. map.on('singleclick', function (evt) {
  80. //alert();
  81. content.innerHTML = "";
  82.  
  83. var displayedLayers = [];
  84. var responses = 0;
  85. var layersCollection = map.getLayers();
  86. // alert(layersCollection.a.length-1);
  87. //alert("0"+ layersCollection.item(0).getSource());
  88. for (i = 1; i <= ((layersCollection.a.length-1)); i++)
  89. { //Loops through all layers excluding baselayer at index 0 and gets their URL
  90. alert();
  91. var layerID = layersCollection.item(i);
  92. var url = layerID.getSource().getGetFeatureInfoUrl( evt.coordinate,map.getView().getResolution(), 'EPSG:4326',{'INFO_FORMAT': 'text/plain'});
  93. alert(url);
  94. popup.setPosition(evt.coordinate);
  95. content.innerHTML =
  96. '<iframe src="' + url + '"></iframe>';
  97. //document.content.appendChild("<iframe></iframe>");
  98. container.style.display = 'block';
  99.  
  100. }
  101.  
  102. });
  103. </script>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement