Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- //var formatWFS = new ol.format.WFS();
- var formatGML = new ol.format.GML({
- featureNS : 'http://localhost:8080/geoserver/ilfs',
- featureType : 'ilfs:ilfs_parceldata',
- srsName: 'EPSG:3857',
- /* srsName : 'EPSG:32643' 'http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd' */
- 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'
- });
- console.log(formatGML);
- /* var formatWFS = new ol.format.WFS(); */
- var formatWFS = new ol.format.WFS({
- featureNS:'http://localhost:8080/geoserver/ilfs',
- featureType:'ilfs:ilfs_parceldata',
- version: '2.0.0',
- schemaLocation:'http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd'
- });
- var xs = new XMLSerializer();
- //var filter = "kid='111' ";
- var filter = null;
- var wfsSource = ILFS.GetBoundingBox(filter)
- var sourceWFS = wfsSource.source;
- var layerWFS = new ol.layer.Vector({
- source : sourceWFS
- });
- var interaction;
- var interactionSelectPointerMove = new ol.interaction.Select({
- condition : ol.events.condition.pointerMove
- });
- var interactionSelect = new ol.interaction.Select({
- style : new ol.style.Style({
- stroke : new ol.style.Stroke({
- color : '#FF2828'
- })
- })
- });
- var interactionSnap = new ol.interaction.Snap({
- source : layerWFS.getSource()
- });
- var map = new ol.Map(
- {
- target : 'map',
- controls : [],
- interactions : [ interactionSelectPointerMove,
- new ol.interaction.MouseWheelZoom(),
- new ol.interaction.DragPan() ],
- layers : [ layerWFS ],
- view : new ol.View({
- center : [0,0],
- zoom : 14
- })
- });
- var bounds = [673562.512010076,1873273.77078815,675067.642255779,1875701.29118918];
- map.getView().fit(bounds, map.getSize());
- //wfs-t
- var dirty = {};
- var transactWFS = function(mode, f) {
- var node;
- switch (mode) {
- case 'insert':
- node = formatWFS.writeTransaction([ f ], null, null, formatGML/* {gmlOptions: formatGML, version : '2.0.0'} */);
- break;
- case 'update':
- node = formatWFS.writeTransaction(null, [ f ], null, formatGML);
- break;
- case 'delete':
- node = formatWFS.writeTransaction(null, null, [ f ], formatGML);
- break;
- }
- console.log(node);
- var payload = xs.serializeToString(node);
- console.log(payload);
- $.ajax('http://localhost:8080/geoserver/wfs', {
- type : 'POST',
- dataType : 'xml',
- processData : false,
- contentType : 'text/xml',
- data : str,
- success: function(data) {
- var result = formatWFS.readTransactionResponse(data);
- console.log(result);
- bootbox.alert('Results <br><br>' + result);
- //f.setId(result.insertIds[0]);
- },
- error: function(e) {
- var errorMsg = e? (e.status + ' ' + e.statusText) : "";
- bootbox.alert('Error saving this feature to GeoServer.<br><br>' + errorMsg);
- },
- context: this
- }).done(function() {
- //bootbox.alert("done");
- //sourceWFS.clear();
- });
- };
- $('button').click(function() {
- $(this).siblings().removeClass('btn-active');
- $(this).addClass('btn-active');
- map.removeInteraction(interaction);
- interactionSelect.getFeatures().clear();
- map.removeInteraction(interactionSelect);
- switch ($(this).attr('id')) {
- case 'btnPoint':
- interaction = new ol.interaction.Draw({
- type : 'Point',
- source : layerWFS.getSource()
- });
- map.addInteraction(interaction);
- interaction.on('drawend', function(e) {
- transactWFS('insert', e.feature);
- });
- break;
- default:
- break;
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement