首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编辑webworldwind层?

如何编辑webworldwind层?
EN

Stack Overflow用户
提问于 2018-04-18 14:15:07
回答 1查看 40关注 0票数 0

我正在使用webworldwind显示由geoserver发布的矢量层,如何将它们设置为活动以进行编辑?例如,我可以从我的点矢量图层中删除一个点?感谢每一个回复!

EN

回答 1

Stack Overflow用户

发布于 2019-02-06 17:02:11

这个问题缺少很多相关的信息。我将假设您在GeoServer中集成了向量层,然后通过WMS协议显示该层。

如果是这种情况,那么您需要控制器的组合来侦听点击,然后使用WFS协议(https://docs.geoserver.org/stable/en/user/services/wfs/reference.html)来更改层。以下函数显示了如何获取给定点上的特征。

代码语言:javascript
复制
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文档中有更多示例。

代码语言:javascript
复制
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();
    });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49892429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档