首页 / 浏览问题 / 其他 / 问题详情
openlayers序列化feature报错
43EXP 2020年05月06日

openlayers中使用SuperMap.Format.GeoJSON序列化feature对象报错,使用方法如下

var geoJSON=new SuperMap.Format.GeoJSON();
var feaStr= geoJSON.write(fea);其中fea和报错如下,请问如何解决

1个回答

您好,您那边用openlayer的地图框架用classic的接口构造矢量对象然后序列化? 您这个方式不太友好。建议使用什么地图框架就用该地图框架的构造方式构建要素。原生openlayer方法提供了序列化的方式,第一个是读序列,第二个是将features写成geojson对象

            let feas= (new ol.format.GeoJSON()).readFeatures(serviceResult.result.features);
            let format=new ol.format.GeoJSON();
            console.log(format.writeFeaturesObject(feas)) ;

如果您那边非得使用,可以引入<script type="text/javascript" src="https://iclient.supermap.io/web/libs/iclient8c/libs/SuperMap-8.1.1-17729.js"></script>,然后用如下代码

      var   pointFeature = new SuperMap.Feature.Vector(point);
      var format=new SuperMap.Format.JSON();
        let json= format.write(pointFeature)
      console.log(json,'pointFeature')
3,352EXP 2020年05月06日
...