2017-09-17 9 views
1

問題フィルターgetFeatureInfo結果(リーフレットは、プラグインをWMS)

。問題は、ジオサーバーがプレーンテキストのみでデータを配信し、下の図に示すように混乱していることです。

Yep, it is a mess indeed

したがって私は有用な情報を表示するために、GetFeatureInfoクエリの結果をフィルタリングしたいです。私はたくさんのJavaScript行を書きました。魔女は、GetFeatureInfoリクエストの結果を含む<div>をフィルタリングします。

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; 

私はスクリプトウィッチの下にこれらの行を追加しようとしましたが、マップを起動して設定しましたが、動作しませんでした。私は、それらの行が正しい瞬間に実行されないと思います。

ソリューションSebastian Schulzから

おかげで、私はGetFeatureInfoクエリの結果をフィルタリングするために管理してきました。 L.WMS.Sourceクラスを拡張し、フックshowFeatureInfoを使用して、クラスがGetFEatureInfoをポップアップに表示する方法を編集する必要があります。このような:セバスチャンが言ったように

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" 
    } 
); 

、(とりわけ)この方法は、documentationです。また、フック構文がleaflet.wms.jsスクリプトにあることもわかりました。 RTFMは私が

答えて

0

:)リーフレットWMSによると...推測documentationあなたはクラスL.WMS.Sourceを拡張し、フック(例えばshowFeatureInfo)をオーバーライドする必要があります。このスニペットをチェックして、の情報変数を編集して、カスタムポップアップを作成します。

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); 
+0

ありがとうございます@sebastian。私は上記のようにクラスを拡張しようとしましたが(https://stackoverflow.com/q/46268753/7074472)、この種のエラーがあります: 'TypeError:L.WMS.source.extendは関数ではありません'。 –

+0

jsfiddleでコードの一部を提供できますか?次に、それをデバッグすることができます。マップオブジェクトを作成し、WMSレイヤーの例を追加してみてください。 https://jsfiddle.net/ –

+0

[jsfiddle](https://jsfiddle.net/xuq8zszg/2/)のコードですが、jsfiddleはGetFeatureInfoのコンテンツを表示しないようですhtt接続ではなくhttp接続で、私はそれを変更できません)。ただし、[jsbin](http://jsbin.com/nupehu/edit?html,js,output)で動作します。ご協力いただきありがとうございます。 –

関連する問題