我正在使用webworldwind显示由geoserver发布的矢量层,如何将它们设置为活动以进行编辑?例如,我可以从我的点矢量图层中删除一个点?感谢每一个回复!
发布于 2019-02-06 17:02:11
这个问题缺少很多相关的信息。我将假设您在GeoServer中集成了向量层,然后通过WMS协议显示该层。
如果是这种情况,那么您需要控制器的组合来侦听点击,然后使用WFS协议(https://docs.geoserver.org/stable/en/user/services/wfs/reference.html)来更改层。以下函数显示了如何获取给定点上的特征。
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;
}
});
}对于给定的工作空间和由纬度和经度定义的点,此函数接受GeoServer的URL,并以layer1,layer2格式返回图层中给定点上的所有要素(可以只提供一个图层)。此函数为您提供后续WFS请求的关键信息,如功能的ID。
删除点跟随函数给出了一个WFS事务请求的例子。上面链接的GeoServer文档中有更多示例。
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();
});
}https://stackoverflow.com/questions/49892429
复制相似问题