首页 / 浏览问题 / WebGIS / 问题详情
ISERVER格式的数据如何作为矢量图层添加
251EXP 2023年06月19日
如题,在iClient for Openlayers中已设置完getFeatureBySQLParams,准备获取数据服务的feature,途中设置了ol.supermap.DataFormat.ISERVER,具体代码如下:

getFeatureBySQLService = new ol.supermap.FeatureService(dataUrl).getFeaturesBySQL(
        getFeatureBySQLParams,
        prProcessAsync,
        ol.supermap.DataFormat.ISERVER
    );

在我们的范例中,使用这种形式获取的数据可以比较简单的作为专题图的features加入source中,但使用同样的方法往ol.source.Vector中添加features就会失败,如果不使用ol.supermap.DataFormat.ISERVER格式返回数据的话,可以通过以下形式往ol.source.Vector中添加features:

features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.features)

请问,如果要使用ol.supermap.DataFormat.ISERVER格式返回的数据制作ol.layer.Vector,应该如何往source中添加features

1个回答

您好,回调函数返回的serviceResult.result.features要素传给vectorSource:new ol.source.Vector(),vectorSource再绑定到new ol.layer.Vector()中,最后通过map.addLayer()上图即可。

参考https://iclient.supermap.io/examples/openlayers/editor.html#02_getFeatureBySQL

1,865EXP 2023年06月19日
您好,加入了ol.supermap.DataFormat.ISERVER后,返回的数据的格式和您给的范例中的数据的格式并不相同,无法参考,请问我提的这种格式应该如何作为features要素传给vectorSource?

补充:在加入了ol.supermap.DataFormat.ISERVER后,我这边添加个别值专题图的source时,使用的是如下方法

var feas = [];

循环加入features[i]

feas.push(result.features.features[i]);

最后加入个别值专题图的source内

themeSource.addFeatures(feas);

但上述步骤在VectorSource中无法生效
如果要使用ol.supermap.DataFormat.ISERVER格式返回的数据,需要自行构造openlayer图层(point,line,polygon)格式进行上图, 例如,如果是面要素就要用new ol.geom.Polygon([[[]]]),然后将要素传入,new ol.source.Vector(),再绑定到new ol.layer.Vector()中,最后通过map.addLayer()上图即可。

getFeaturesBySQL接口本身返回的serviceResult.result.features是GEOJSON格式,直接获取到feature上图即可。
...