Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is my javascript code of layers
- <script>
- var landuseLayer = new ol.layer.Image({
- coordinates: [79.14511833527447, 20.987418098133496, 79.2018842619151, 21.050233196545],
- source: new ol.source.ImageWMS({
- url: 'http://localhost:8080/geoserver/sagy/wms',
- params: {'LAYERS': 'sagy:pachgaon_LULC'},
- maxZoom: 19
- }),
- visible: false
- });
- var soilLayer = new ol.layer.Image({
- coordinates: [79.14511833527447, 20.987418098133496, 79.2018842619151, 21.050233196545],
- source: new ol.source.ImageWMS({
- url: 'http://localhost:8080/geoserver/sagy/wms',
- params: {'LAYERS': 'sagy:pachgaon_LULC'},
- maxZoom: 19
- }),
- visible: false
- });
- var map = new ol.Map({
- layers: [landuseLayer, soilLayer],
- renderer: 'canvas',
- target: document.getElementById('map'),
- controls: ol.control.defaults({
- attributionOptions: ({
- collapsible: false
- })
- }).extend([
- new ol.control.ZoomSlider(),
- new ol.control.ZoomToExtent({
- extent: [
- 79.14511833527447, 20.987418098133496, 79.2018842619151, 21.050233196545
- ]
- }),
- new ol.control.Rotate(),
- new ol.control.OverviewMap(),
- new ol.control.ScaleLine(),
- new ol.control.FullScreen(),
- new ol.control.MousePosition({
- coordinateFormat: ol.coordinate.createStringXY(4),
- projection: 'EPSG:4326'
- })
- ]),
- interactions: ol.interaction.defaults().extend([
- new ol.interaction.Select({
- condition: ol.events.condition.mouseMove
- })
- ]),
- view: new ol.View({
- center: new ol.geom.Point([20, 19])
- .transform('EPSG:4326', 'EPSG:4326').getCoordinates(),
- zoom: 2
- }),
- target: 'map'
- });
- $('input[type=checkbox]').on('change', function() {
- var layer = {
- landuse: landuseLayer,
- }[$(this).attr('id')];
- layer.setVisible(!layer.getVisible());
- });
- // define a custom control that can be used to draw points
- var DrawControl = function (opt_options) {
- var options = opt_options || {};
- this.active = options.active || false;
- var draw = new ol.interaction.Draw({
- source: options.source,
- type: 'Point'
- });
- var this_ = this;
- var handleDrawPoint = function (e) {
- e.preventDefault();
- if (!this.active) {
- this_.getMap().addInteraction(draw);
- this.active = true;
- } else {
- this_.getMap().removeInteraction(draw);
- this.active = false;
- }
- };
- // this will be the ui of the component
- var anchor = document.createElement('a');
- anchor.href = '#draw-point';
- anchor.innerHTML = 'New Point';
- // bind to click and touchevents to support mobile
- anchor.addEventListener('click', handleDrawPoint, false);
- anchor.addEventListener('touchstart', handleDrawPoint, false);
- var element = document.createElement('div');
- element.className = 'ol-control draw-point ol-unselectable';
- element.appendChild(anchor);
- ol.control.Control.call(this, {
- element: element,
- target: options.target
- });
- };
- // inherit base functionality from ol.control.Control
- ol.inherits(DrawControl, ol.control.Control);
- // init a vector layer whose source can be used with our new control
- var vectorSource = new ol.source.Vector();
- var vectorLayer = new ol.layer.Vector({
- source: vectorSource,
- style: new ol.style.Style({
- fill: new ol.style.Fill({
- color: 'rgba(255, 255, 255, 0.2)'
- }),
- stroke: new ol.style.Stroke({
- color: '#ffcc33',
- width: 2
- }),
- image: new ol.style.Circle({
- radius: 7,
- fill: new ol.style.Fill({
- color: '#ffcc33'
- })
- })
- })
- });
- map.addLayer(vectorLayer);
- // here we use our new control
- map.addControl(new DrawControl({
- source: vectorSource
- })); </script>
- <?php
- $host = "localhost";
- $user = "postgres";
- $pass = "admin";
- $db = "Querybuilderdb";
- $con = pg_connect("host=$host dbname=$db user=$user password=$pass")
- or die ("Could not connect to servern");
- $sql = "SELECT st_asgeojson(geom) AS geojson FROM " .pachgaon_lulc. "";
- // Return route as GeoJSON
- $rs = pg_query($con, $sql);
- if (!$rs) {
- echo "An SQL error occured.n";
- exit;
- }
- # Build GeoJSON
- $output = '';
- $rowOutput = '';
- while ($row = pg_fetch_assoc($rs)) {
- $rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "geometry": ' . $row['geojson'] . ', "properties": {';
- $props = '';
- $id = '';
- foreach ($row as $key => $val) {
- if ($key != "geojson") {
- $props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"';
- }
- if ($key == "gid") {
- $id .= ',"gid":"' . escapeJsonString($val) . '"';
- }
- }
- $rowOutput .= $props . '}';
- $rowOutput .= $id;
- $rowOutput .= '}';
- $output .= $rowOutput;
- }
- $output = '{ "type": "FeatureCollection", "features": [ ' . $output . ' ]}';
- echo $output;
- ?>
- { "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