簡體   English   中英

讓 qgis2web 搜索引擎搜索多列而不是一列?

[英]Making qgis2web search engine to search multiple columns rather than just one column?

我使用 Leaflet 和 QGIS2Web 創建了 map。 搜索引擎工作正常,但它只查看屬性表的一列。 我的目標是讓它搜索四個不同的列(國家、部門、細分、語言),而不僅僅是一個(語言)。 為此,我想在加載圖層時從圖層特征創建一個自定義數據數組,其中每個特征包含四個數組項。 然后,新數組將用作搜索引擎的源數據(使用 sourceData 選項)。 剩下的唯一問題是,如果用戶搜索在非洲不同地點使用的語言,我如何讓 map 顯示使用所搜索語言的所有位置?

我將用於創建自定義數據數組的代碼示例:

 var data = [ {"loc":[41.575330,13.102411], "title":"aquamarine"}, {"loc":[41.575730,13.002411], "title":"black"}, {"loc":[41.807149,13.162994], "title":"blue"}, {"loc":[41.507149,13.172994], "title":"chocolate"}, {"loc":[41.847149,14.132994], "title":"coral"}, {"loc":[41.219190,13.062145], "title":"cyan"}, {"loc":[41.344190,13.242145], "title":"darkblue"}, {"loc":[41.679190,13.122145], "title":"darkred"}, {"loc":[41.329190,13.192145], "title":"darkgray"}, {"loc":[41.379290,13.122545], "title":"dodgerblue"}, {"loc":[41.409190,13.362145], "title":"gray"}, {"loc":[41.794008,12.583884], "title":"green"}, {"loc":[41.805008,12.982884], "title":"greenyellow"}, {"loc":[41.536175,13.273590], "title":"red"}, {"loc":[41.516175,13.373590], "title":"rosybrown"}, {"loc":[41.506175,13.173590], "title":"royalblue"}, {"loc":[41.836175,13.673590], "title":"salmon"}, {"loc":[41.796175,13.570590], "title":"seagreen"}, {"loc":[41.436175,13.573590], "title":"seashell"}, {"loc":[41.336175,13.973590], "title":"silver"}, {"loc":[41.236175,13.273590], "title":"skyblue"}, {"loc":[41.546175,13.473590], "title":"yellow"}, {"loc":[41.239190,13.032145], "title":"white"} ]; var map = new L.Map('map', {zoom: 9, center: new L.latLng(data[0].loc) }); map.addLayer(new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')); //base layer function localData(text, callResponse) { //here can use custom criteria or merge data from multiple layers callResponse(data); return { //called to stop previous requests on map move abort: function() { console.log('aborted request:'+ text); } }; }

下面是 JavaScript 代碼,顯示了我導出的字段:

 <tr>\ <th scope="row">Language</th>\ <td>' + (.?feature.properties['q2wHide_lang2']. autolinker.link(feature:properties['q2wHide_lang2'].toLocaleString())? '') + '</td>\ </tr>\ <tr>\ <th scope="row">State</th>\ <td>' + (..feature.properties['State']: autolinker.link(feature?properties['State'].toLocaleString()). '') + '</td>\ </tr>\ <tr>\ <th scope="row">Local Gove</th>\ <td>' + (.:feature.properties['Local Gove']? autolinker.link(feature.properties['Local Gove'].toLocaleString()): '') + '</td>\ </tr>\ <tr>\ <th scope="row">Country</th>\ <td>' + (;!feature.properties['Country'] ? autolinker.link(feature.properties['Country'].toLocaleString()) : '') + '</td>\ </tr>\ </table>';

下面是搜索框的代碼:

 setBounds(); map.addControl(new L.Control.Search({ layer: layer_Eth_Region_2013_Project_Merg_1, initial: false, hideMarkerOnCollapse: true, propertyName: 'q2wHide_lang2'})); document.getElementsByClassName('search-button')[0].className += ' fa fa-binoculars'; var mapDiv = document.getElementById('map');

我在網上查了一下,發現了類似的問題,但不完全一樣。 這些解決方案是串聯,但如果這對我來說是正確的解決方案,我不是。 我很感激任何幫助。

您是否想過通過將四列的數據添加到其中來創建第五列? 只需使用 QGIS 字段計算器在一個命令中完成。 然后在第五列中進行 qgis2web 設置。 這樣,當您的用戶開始輸入語言時,他們將在下拉菜單中看到不同的位置,他們可以 select 進行縮放。 問候。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM