首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >过滤getFeatureInfo结果(传单wms插件)

过滤getFeatureInfo结果(传单wms插件)
EN

Stack Overflow用户
提问于 2017-09-17 20:49:14
回答 1查看 4K关注 0票数 2

问题

使用leaflet.wms.js插件,我只需单击WMS层就可以显示关于WMS层的信息(使用GetFeatureInfo)。问题是geoserver只提供纯文本的数据,如下图所示,它是一片混乱。

是啊,真是一团糟

因此,我想过滤GetFeatureInfo查询的结果,以便只显示有用的信息。我编写了一堆JavaScript行,它过滤了包含GetFeatureInfo请求结果的<div>

代码语言:javascript
复制
var GetFeatureInfo = document.getElementsByClassName("leaflet-popup-content")[0].innerHTML;
tipo = GetFeatureInfo.split(/'/)[21];
legenda = GetFeatureInfo.split(/'/)[27];
document.getElementsByClassName("leaflet-popup-content")[0].innerHTML = tipo + ":<br/>PERICOLOSITÀ " + legenda;

我试图在脚本的底部添加这些行,女巫调用并配置映射,但是它没有工作。我想这些行不是在正确的时候执行的。

溶液

多亏了塞巴斯蒂安·舒尔茨,我成功地过滤了GetFeatureInfo查询的结果。我们需要扩展L.WMS.Source类,并使用钩子showFeatureInfo编辑类在弹出窗口中显示GetFEatureInfo的方式。如下所示:

代码语言:javascript
复制
var CleanInfoSource = L.WMS.Source.extend({
    'showFeatureInfo': function(latlng, info){
        if (!this._map){return;}
        tipo = info.split(/'/)[21];
        legenda = info.split(/'/)[27];
        info = tipo + ":<br/>PERICOLOSITÀ " + legenda;
        this._map.openPopup(info, latlng);
    }
});

var minambPAI = new CleanInfoSource("http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/WMS_v1.3/Vettoriali/PAI_pericolosita.map",{
        format: "image/png",
        transparent: true,
        attribution: "<a href='http://www.pcn.minambiente.it'>Ministero dell&#8217;Ambiente</a>",
        info_format: "text/plain"
    }
);

正如塞巴斯蒂安所说,这种方法(以及其他方法)在文档中。我还发现钩子语法在leaflet.wms.js脚本中。我想是的..。:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-18 10:58:24

根据传单WMS 文档,您需要扩展类L.WMS.Source并覆盖钩子(例如showFeatureInfo)。检查此代码段并编辑信息变量,以生成自定义弹出。

代码语言:javascript
复制
var map = L.map('map').setView([43.53, 10.32], 13);
var openTopoMap = L.tileLayer(
  'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
  {attribution: '<a href="https://opentopomap.org/copyright">OpenTopoMap</a>'}).addTo(map);
var MySource = L.WMS.Source.extend({
    'showFeatureInfo': function(latlng, info) {
        if (!this._map) {
            return;
        }
        // do whatever you like with info
        console.log(info)
        this._map.openPopup(info, latlng);
    }
});
var minambPAI = new MySource("http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/WMS_v1.3/Vettoriali/PAI_pericolosita.map",
    {
        format: "image/png",
        transparent: true,
        attribution: "<a href='http://www.pcn.minambiente.it'>Ministero dell&#8217;Ambiente</a>",
        info_format: "text/plain"
    }
);
var periAlluvioneMME = minambPAI.getLayer('RN.PAI.PERICOLOSITA.ALLUVIONE').addTo(map);
var periFranaMME = minambPAI.getLayer('RN.PAI.PERICOLOSITA.FRANA_01');
var control = L.control.layers({}, {
    'Pericolosità  Alluvioni: moderata a molto elevata': periAlluvioneMME,
    'Pericolosità  Frane: moderata a molto elevata': periFranaMME
})
control.addTo(map);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46268753

复制
相关文章

相似问题

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