我正在研究 OpenLayers 和 Geoserver。當(dāng)用戶單擊一個功能時,我有一個已經(jīng)創(chuàng)建的制表符表來獲取功能信息數(shù)據(jù)。我的問題是我需要將 html 響應(yīng)從 Geoserver 轉(zhuǎn)換為 JSON。我怎樣才能做到這一點?這是 Geoserver 的響應(yīng)<table class="featureInfo"> <caption class="featureInfo">l1Data</caption> <tbody><tr> <th>id</th> <th>sensor</th> <th>timestamp</th> <th>reliability</th> </tr> <tr> <td>16021</td> <td>Basic</td> <td>Sep 18, 2020 12:05:02 PM</td> <td>0.929717403858748</td> </tr></tbody></table>制表符已設(shè)置為:table = new Tabulator("#eventtable", { //height:"311px", layout:"fitColumns", columns:[ {title:"ID", field:"id", visible:false}, {title:"Sensor", field:"sensor", sorter:"string"}, {title:"Last Detection", field:"timestamp", sorter:"date"}, {title:"Reliability", field:"reliability", sorter:"number"}, ], });編輯我發(fā)現(xiàn)我可以有一個 application/json 響應(yīng),但我不能放入 Tabulator。地圖上的代碼點擊:map.on('singleclick', function (evt) {var viewResolution = /** @type {number} */ (view.getResolution()); var url = wmsSource.getFeatureInfoUrl( evt.coordinate, viewResolution, 'EPSG:3857', { 'INFO_FORMAT': 'application/json' }); if (url) { fetch(url) .then(function (response) { return response.text(); }) .then(function (html) { var test1 = JSON.parse(html); var test2 = test1.features[0].properties; table.setData(test2); }); } });錯誤是:tabulator.min.js:2 Data Loading Error - Unable to process data due to invalid data type Expecting: array Received: object
Geoserver JSON 到制表符
慕尼黑5688855
2023-03-18 14:50:20