Advertisement
Guest User

Untitled

a guest
Mar 6th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.43 KB | None | 0 0
  1. Here is my javascript code of layers
  2. <script>
  3. var landuseLayer = new ol.layer.Image({
  4. coordinates: [79.14511833527447, 20.987418098133496, 79.2018842619151, 21.050233196545],
  5. source: new ol.source.ImageWMS({
  6. url: 'http://localhost:8080/geoserver/sagy/wms',
  7. params: {'LAYERS': 'sagy:pachgaon_LULC'},
  8. maxZoom: 19
  9. }),
  10. visible: false
  11. });
  12.  
  13.  
  14. var soilLayer = new ol.layer.Image({
  15. coordinates: [79.14511833527447, 20.987418098133496, 79.2018842619151, 21.050233196545],
  16. source: new ol.source.ImageWMS({
  17. url: 'http://localhost:8080/geoserver/sagy/wms',
  18. params: {'LAYERS': 'sagy:pachgaon_LULC'},
  19. maxZoom: 19
  20. }),
  21. visible: false
  22. });
  23.  
  24. var map = new ol.Map({
  25. layers: [landuseLayer, soilLayer],
  26. renderer: 'canvas',
  27. target: document.getElementById('map'),
  28. controls: ol.control.defaults({
  29. attributionOptions: ({
  30. collapsible: false
  31. })
  32. }).extend([
  33. new ol.control.ZoomSlider(),
  34. new ol.control.ZoomToExtent({
  35. extent: [
  36. 79.14511833527447, 20.987418098133496, 79.2018842619151, 21.050233196545
  37.  
  38. ]
  39. }),
  40.  
  41. new ol.control.Rotate(),
  42. new ol.control.OverviewMap(),
  43. new ol.control.ScaleLine(),
  44. new ol.control.FullScreen(),
  45. new ol.control.MousePosition({
  46. coordinateFormat: ol.coordinate.createStringXY(4),
  47. projection: 'EPSG:4326'
  48. })
  49. ]),
  50.  
  51. interactions: ol.interaction.defaults().extend([
  52. new ol.interaction.Select({
  53. condition: ol.events.condition.mouseMove
  54. })
  55. ]),
  56.  
  57.  
  58. view: new ol.View({
  59. center: new ol.geom.Point([20, 19])
  60. .transform('EPSG:4326', 'EPSG:4326').getCoordinates(),
  61. zoom: 2
  62. }),
  63.  
  64. target: 'map'
  65. });
  66.  
  67.  
  68. $('input[type=checkbox]').on('change', function() {
  69. var layer = {
  70.  
  71. landuse: landuseLayer,
  72.  
  73.  
  74.  
  75. }[$(this).attr('id')];
  76. layer.setVisible(!layer.getVisible());
  77. });
  78.  
  79. // define a custom control that can be used to draw points
  80. var DrawControl = function (opt_options) {
  81. var options = opt_options || {};
  82. this.active = options.active || false;
  83. var draw = new ol.interaction.Draw({
  84. source: options.source,
  85. type: 'Point'
  86. });
  87. var this_ = this;
  88. var handleDrawPoint = function (e) {
  89. e.preventDefault();
  90. if (!this.active) {
  91. this_.getMap().addInteraction(draw);
  92. this.active = true;
  93. } else {
  94. this_.getMap().removeInteraction(draw);
  95. this.active = false;
  96. }
  97. };
  98.  
  99. // this will be the ui of the component
  100. var anchor = document.createElement('a');
  101. anchor.href = '#draw-point';
  102. anchor.innerHTML = 'New Point';
  103.  
  104. // bind to click and touchevents to support mobile
  105. anchor.addEventListener('click', handleDrawPoint, false);
  106. anchor.addEventListener('touchstart', handleDrawPoint, false);
  107.  
  108. var element = document.createElement('div');
  109. element.className = 'ol-control draw-point ol-unselectable';
  110. element.appendChild(anchor);
  111.  
  112. ol.control.Control.call(this, {
  113. element: element,
  114. target: options.target
  115. });
  116. };
  117. // inherit base functionality from ol.control.Control
  118. ol.inherits(DrawControl, ol.control.Control);
  119.  
  120. // init a vector layer whose source can be used with our new control
  121. var vectorSource = new ol.source.Vector();
  122. var vectorLayer = new ol.layer.Vector({
  123. source: vectorSource,
  124. style: new ol.style.Style({
  125. fill: new ol.style.Fill({
  126. color: 'rgba(255, 255, 255, 0.2)'
  127. }),
  128. stroke: new ol.style.Stroke({
  129. color: '#ffcc33',
  130. width: 2
  131. }),
  132. image: new ol.style.Circle({
  133. radius: 7,
  134. fill: new ol.style.Fill({
  135. color: '#ffcc33'
  136. })
  137. })
  138. })
  139. });
  140.  
  141. map.addLayer(vectorLayer);
  142.  
  143. // here we use our new control
  144. map.addControl(new DrawControl({
  145. source: vectorSource
  146. })); </script>
  147.  
  148. <?php
  149. $host = "localhost";
  150. $user = "postgres";
  151. $pass = "admin";
  152. $db = "Querybuilderdb";
  153.  
  154. $con = pg_connect("host=$host dbname=$db user=$user password=$pass")
  155. or die ("Could not connect to servern");
  156. $sql = "SELECT st_asgeojson(geom) AS geojson FROM " .pachgaon_lulc. "";
  157. // Return route as GeoJSON
  158. $rs = pg_query($con, $sql);
  159. if (!$rs) {
  160. echo "An SQL error occured.n";
  161. exit;
  162. }
  163. # Build GeoJSON
  164. $output = '';
  165. $rowOutput = '';
  166. while ($row = pg_fetch_assoc($rs)) {
  167. $rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "geometry": ' . $row['geojson'] . ', "properties": {';
  168. $props = '';
  169. $id = '';
  170. foreach ($row as $key => $val) {
  171. if ($key != "geojson") {
  172. $props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"';
  173. }
  174. if ($key == "gid") {
  175. $id .= ',"gid":"' . escapeJsonString($val) . '"';
  176. }
  177. }
  178.  
  179. $rowOutput .= $props . '}';
  180. $rowOutput .= $id;
  181. $rowOutput .= '}';
  182. $output .= $rowOutput;
  183. }
  184. $output = '{ "type": "FeatureCollection", "features": [ ' . $output . ' ]}';
  185. echo $output;
  186. ?>
  187.  
  188. { "type": "FeatureCollection", "features": [ {"type": "Feature", "geometry": {"type":"MultiPolygon","coordinates":[[[[311724.557056804,2325396.5591672],[311728.875795185,2325214.23670262],[311720.389401375,2325219.79621125],[311711.032898116,2325231.26872467],[311698.1337123,2325244.04434893],[311689.948665489,2325254.24070687],[311680.563637533,2325263.18766634],[311669.978533121,2325270.88543021],[311660.622136595,2325282.35794543],[311656.051449561,2325297.5649764],[311656.194696944,2325310.19264218],[311659.937987636,2325326.56829916],[311663.595287973,2325335.36729748],[311667.448182462,2325341.76536466],[311669.638435303,2325345.40220959],[311673.309950532,2325355.46398527],[311674.581603699,2325363.0270621],[311677.053239259,2325371.83953616],[311675.996509715,2325383.21789764],[311683.225120882,2325393.2393318],[311697.4960453,2325396.86621652],[311709.352694544,2325396.73173141],[311724.557056804,2325396.5591672]]]]}, "properties": {}},{"type": "Feature", "geometry": {"type":"MultiPolygon","coordinates":[[[[308202.966481524,2323120.82218353],[308168.476849081,2323117.71844138],[308131.877804368,2323128.72910848],[308122.448861758,2323129.4632976],[308094.905161214,2323139.42022616],[308065.987799505,2323153.59138438],[308059.965005328,2323156.54292217],[308048.695848158,2323161.84402059],[308039.104868505,2323172.29680561],[308036.007354829,2323184.39811965],[308036.186582377,2323199.9089684],[308036.365811051,2323215.41981573],[308036.445522195,2323222.31344603],[308041.559663341,2323244.66192722],[308049.910532513,2323266.97287711],[308051.648418207,2323277.29470612],[308057.10533578,2323284.85565436],[308067.515384455,2323313.48973648],[308081.50681366,2323343.57900233],[308092.81967272,2323372.41218014],[308109.356698155,2323398.46685299],[308126.784231834,2323407.29354641],[308159.851328253,2323406.4624808],[308184.84936863,2323400.54012036],[308197.777025204,2323388.30352574],[308197.311638861,2323369.78603334],[308186.231498147,2323350.21171106],[308188.212089473,2323323.69154311],[308188.783240768,2323313.26156945],[308203.061617756,2323289.96213072],[308213.568287156,2323282.31923568],[308224.249348427,2323275.03112175],[308226.429896861,2323264.49617143],[308236.280113114,2323235.13122258],[308239.018303768,2323186.09220112],[308229.028158621,2323157.2258525],[308215.302698421,2323137.7179753],[308202.966481524,2323120.82218353]]]]}, "properties": {}},{"type": "Feature", "geometry": {"type":"MultiPolygon","coordinates":[[[[311600.683072412,2322387.45441031],[311611.218646608,2322380.74914235],[311624.121070192,2322375.42668675],[311637.023393944,2322370.10423512],[311649.945324212,2322366.5070547],[311662.789136998,2322356.00908914],[311670.811594778,2322349.01656966],[311673.914979509,2322336.90363842],[311670.537846744,2322324.8641734],[311663.998717817,2322319.76212498],[311657.498595247,2322318.1104218],[311652.599021302,2322314.71508106],[311647.640839293,2322306.14432407],[311639.461950159,2322299.33547175],[311632.94232249,2322295.95859535],[311626.422594432,2322292.58172144],[311616.662655158,2322289.24158011],[311608.542374282,2322287.60824475],[311603.68200775,2322287.66334521],[311600.441696684,2322287.70008061],[311595.581329974,2322287.75518131],[311593.961174381,2322287.77354907],[311589.139815296,2322291.27899706],[311582.718004721,2322296.52798172],[311574.695542996,2322303.52050837],[311566.653477603,2322308.78786462],[311556.991356889,2322314.07358729],[311550.530338767,2322315.87223181],[311542.468769465,2322319.41441627],[311536.027358478,2322322.93833268],[311529.554526283,2322325.53752899],[311523.098817006,2322327.79864636],[311517.691714223,2322331.94218021],[311508.008953421,2322337.25053524],[311500.340828927,2322345.64869689],[311497.515822148,2322356.15764499],[311497.735748757,2322363.39472668],[311500.951787196,2322373.37262653],[311507.56934448,2322385.3752525],[311520.549892031,2322386.95347648],[311528.650565411,2322386.86153309],[311533.550141261,2322390.25676921],[311540.387247408,2322395.4798869],[311547.07055204,2322399.29514222],[311555.793336815,2322399.92990759],[311564.453125943,2322398.69322757],[311570.326454678,2322397.36373831],[311578.998210336,2322397.18542638],[311590.431332936,2322393.04036165],[311600.683072412,2322387.45441031]]]]},
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement