I am using the webworldwind to display my vector layers that published by the geoserver, how can I set them active to edit? For example, i can delete a point from my point vector layer? Every response id appreciate!!
1 Answers
The question is missing lots of relevant information. I will assume that you integrated the Vector layer in the GeoServer and then you display the layer via WMS protocol.
If this is the case, then you need the combination of the controller to listen for the clicks and then use WFS protocol (https://docs.geoserver.org/stable/en/user/services/wfs/reference.html) to change the layer. The following function shows how you can get the features on the given point.
function getFeaturesForPoint(url, layerNames, point) {
// The URL will look something similar to http://localhost/geoserver/workspace/wfs
var url = url + '?service=wfs&version=1.1.0&request=GetFeature&typeNames='+layerNames+'&FILTER=' +
'<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><Intersects><PropertyName>the_geom</PropertyName><gml:Point srsName="EPSG:4326"><gml:coordinates>'+point.longitude+','+ point.latitude + '</gml:coordinates></gml:Point></Intersects></Filter>' +
'&outputFormat=application/json';
return fetch(url, {
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}).then(function(response){
return response.json();
}).then(function(feature){
if (data.type === 'FeatureCollection' && data.features && data.features.length) {
return data.features;
}
});
}
This function accepts the URL of the GeoServer up to the WFS endpoint for given workspace and a point defined by latitude and longitude and returns all features on given point in the layers in the format layer1,layer2 (It is possible to provide only one layer). This function gives you key information for the subsequent WFS requests such as ID of the feature.
To delete the point following function shows an example with the WFS Transaction request. There are more examples in the GeoServer documentation linked above.
function deleteFeature(url, layerName, featureId) {
// The URL will look something similar to http://localhost/geoserver/workspace/wfs
return fetch(url, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/xml',
'Accept': 'application/json'
},
body: '<wfs:Transaction service="WFS" version="1.0.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs"><wfs:Delete typeName="'+layerName+'"><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>'+featureId+'</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter></wfs:Delete></wfs:Transaction>'
}).then(function(response){
return response.json();
});
}

- 315
- 1
- 7