你好,前端在进行sql查询结束后返回的结果包含了数据集和数据源的信息,在recordsets下按照不同数据集来源把返回的结果进行了分类的便于分辨。
你好,我这边测试openlayer返回结果也是有recordsets分类的。
下面是测试代码,用的是官网的示例:https://iclient.supermap.io/examples/openlayers/editor.html#01_mapQueryBySQL
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title data-i18n="resources.title_mapQueryBySQL"></title> <script type="text/javascript" src="../js/include-web.js"></script> <script type="text/javascript" src="../../dist/ol/include-ol.js"></script> </head> <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;"> <div id="map" style="width: 100%;height:100%"></div> <script type="text/javascript"> var map, resultLayer, url = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World"; map = new ol.Map({ target: 'map', controls: ol.control.defaults({attributionOptions: {collapsed: false}}) .extend([new ol.supermap.control.Logo()]), view: new ol.View({ center: [0, 0], zoom: 2, projection: 'EPSG:4326', multiWorld: true }) }); var layer = new ol.layer.Tile({ source: new ol.source.TileSuperMapRest({ url: url }), projection: 'EPSG:4326' }); map.addLayer(layer); query(); function query() { var param = new ol.supermap.QueryBySQLParameters({ queryParams: [ {name: "Capitals@World.1",attributeFilter: "SMID < 10"}, {name: "Countries@World.1",attributeFilter: "SMID < 10"} ] }); new ol.supermap.QueryService(url).queryBySQL(param, function (serviceResult) { console.log(serviceResult); var vectorSource = new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.recordsets[0].features), wrapX: false }); resultLayer = new ol.layer.Vector({ source: vectorSource }); map.addLayer(resultLayer); var vectorSource1 = new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.recordsets[1].features), wrapX: false }); resultLayer1 = new ol.layer.Vector({ source: vectorSource1 }); map.addLayer(resultLayer1); }); } </script> </body> </html>
对数据服务的sql查询,result结果里面不会显示数据集名称来区分,你可以在查询的时候分开设置查询过滤参数,这样在返回的结果里面的serviceResult.object.options.data可以区分数据集来源,比如:
function query() { var sqlParam = new ol.supermap.GetFeaturesBySQLParameters({ queryParameter: { name: "Countries@World", attributeFilter: "SMID < 10" }, datasetNames: ["World:Countries"] }); var sqlParam1 = new ol.supermap.GetFeaturesBySQLParameters({ queryParameter: { name: "Capitals@World", attributeFilter: "SMID < 10" }, datasetNames: ["World:Capitals"] }); new ol.supermap.FeatureService(url).getFeaturesBySQL(sqlParam, function (serviceResult) { console.log(serviceResult.object.options.data); var vectorSource = new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.features), wrapX: false }); resultLayer = new ol.layer.Vector({ source: vectorSource }); map.addLayer(resultLayer); }); new ol.supermap.FeatureService(url).getFeaturesBySQL(sqlParam1, function (serviceResult) { console.log(serviceResult.object.options.data); var vectorSource = new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.features), wrapX: false }); resultLayer = new ol.layer.Vector({ source: vectorSource }); map.addLayer(resultLayer); }); }