Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. <script>
  2. //var formatWFS = new ol.format.WFS();
  3.  
  4. var formatGML = new ol.format.GML({
  5. featureNS : 'http://localhost:8080/geoserver/ilfs',
  6. featureType : 'ilfs:ilfs_parceldata',
  7. srsName: 'EPSG:3857',
  8. /* srsName : 'EPSG:32643' 'http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd' */
  9. schemaLocation : 'http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd' // http://localhost:8080/geoserver/ilfs/wfs/DescribeFeatureType?typename=ilfs:ilfs_parceldata'
  10. });
  11. console.log(formatGML);
  12. /* var formatWFS = new ol.format.WFS(); */
  13. var formatWFS = new ol.format.WFS({
  14. featureNS:'http://localhost:8080/geoserver/ilfs',
  15. featureType:'ilfs:ilfs_parceldata',
  16. version: '2.0.0',
  17. schemaLocation:'http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd'
  18. });
  19.  
  20. var xs = new XMLSerializer();
  21. //var filter = "kid='111' ";
  22. var filter = null;
  23.  
  24. var wfsSource = ILFS.GetBoundingBox(filter)
  25. var sourceWFS = wfsSource.source;
  26.  
  27. var layerWFS = new ol.layer.Vector({
  28. source : sourceWFS
  29. });
  30.  
  31. var interaction;
  32.  
  33. var interactionSelectPointerMove = new ol.interaction.Select({
  34. condition : ol.events.condition.pointerMove
  35. });
  36.  
  37. var interactionSelect = new ol.interaction.Select({
  38. style : new ol.style.Style({
  39. stroke : new ol.style.Stroke({
  40. color : '#FF2828'
  41. })
  42. })
  43. });
  44.  
  45. var interactionSnap = new ol.interaction.Snap({
  46. source : layerWFS.getSource()
  47. });
  48.  
  49. var map = new ol.Map(
  50. {
  51. target : 'map',
  52. controls : [],
  53. interactions : [ interactionSelectPointerMove,
  54. new ol.interaction.MouseWheelZoom(),
  55. new ol.interaction.DragPan() ],
  56. layers : [ layerWFS ],
  57. view : new ol.View({
  58. center : [0,0],
  59. zoom : 14
  60. })
  61. });
  62.  
  63. var bounds = [673562.512010076,1873273.77078815,675067.642255779,1875701.29118918];
  64. map.getView().fit(bounds, map.getSize());
  65.  
  66. //wfs-t
  67. var dirty = {};
  68. var transactWFS = function(mode, f) {
  69. var node;
  70. switch (mode) {
  71. case 'insert':
  72. node = formatWFS.writeTransaction([ f ], null, null, formatGML/* {gmlOptions: formatGML, version : '2.0.0'} */);
  73. break;
  74. case 'update':
  75. node = formatWFS.writeTransaction(null, [ f ], null, formatGML);
  76. break;
  77. case 'delete':
  78. node = formatWFS.writeTransaction(null, null, [ f ], formatGML);
  79. break;
  80. }
  81. console.log(node);
  82. var payload = xs.serializeToString(node);
  83. console.log(payload);
  84. $.ajax('http://localhost:8080/geoserver/wfs', {
  85. type : 'POST',
  86. dataType : 'xml',
  87. processData : false,
  88. contentType : 'text/xml',
  89. data : str,
  90. success: function(data) {
  91. var result = formatWFS.readTransactionResponse(data);
  92. console.log(result);
  93. bootbox.alert('Results <br><br>' + result);
  94. //f.setId(result.insertIds[0]);
  95. },
  96. error: function(e) {
  97. var errorMsg = e? (e.status + ' ' + e.statusText) : "";
  98. bootbox.alert('Error saving this feature to GeoServer.<br><br>' + errorMsg);
  99. },
  100. context: this
  101. }).done(function() {
  102. //bootbox.alert("done");
  103. //sourceWFS.clear();
  104. });
  105. };
  106.  
  107. $('button').click(function() {
  108. $(this).siblings().removeClass('btn-active');
  109. $(this).addClass('btn-active');
  110. map.removeInteraction(interaction);
  111. interactionSelect.getFeatures().clear();
  112. map.removeInteraction(interactionSelect);
  113.  
  114. switch ($(this).attr('id')) {
  115.  
  116. case 'btnPoint':
  117. interaction = new ol.interaction.Draw({
  118. type : 'Point',
  119. source : layerWFS.getSource()
  120. });
  121. map.addInteraction(interaction);
  122. interaction.on('drawend', function(e) {
  123. transactWFS('insert', e.feature);
  124. });
  125. break;
  126.  
  127. default:
  128. break;
  129. }
  130. });
  131. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement