首页 / 浏览问题 / 三维GIS / 问题详情
序列化一个要素对象,几何对象,要素对象数组为一个GeoJSON字符串出错
39EXP 2020年04月21日

功能忽然不能用了,以前能用

new SuperMap.Format.GeoJSON().write()

使用new SuperMap.Format.GeoJSON 的write方法,将超图面和线转geojson字符串出错。

new SuperMap.Format.GeoJSON().write(new SuperMap.Geometry.Polygon(new SuperMap.Geometry.LinearRing([new SuperMap.Geometry.Point(22,23),
         new SuperMap.Geometry.Point(23,43),
         new SuperMap.Geometry.Point(35,21),
         new SuperMap.Geometry.Point(22,35)])))
null

2 个回答

          您好,我这边测试没有问题,您可以确认下构造方式是否正确

          var points2 = [
                    new SuperMap.Geometry.Point(-120, 54.142),
                    new SuperMap.Geometry.Point(-110, 40),
                    new SuperMap.Geometry.Point(-120, 25.857),
                    new SuperMap.Geometry.Point(-140, 25.857),
                    new SuperMap.Geometry.Point(-150, 40),
                    new SuperMap.Geometry.Point(-140, 54.142)

                ],
                linearRings = new SuperMap.Geometry.LinearRing(points2),
                region = new SuperMap.Geometry.Polygon([linearRings]);
                
      let foramt=new SuperMap.Format.GeoJSON();
      let string_fea=foramt.write(region);   
      console.log(string_fea,'string_fea')

3,352EXP 2020年04月21日

感觉可能是类库的问题,您那边可以直接引入https://iclient.supermap.io/web/libs/iclient8c/libs/SuperMap-8.1.1-17729.js这个在线js文件

3,352EXP 2020年04月21日

请问您用的在线示例是哪个?我用在线的也不行。
http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/examples/leaflet/editor.html#01_mapQueryByGeometry

          var points2 = [
                    new SuperMap.Geometry.Point(-120, 54.142),
                    new SuperMap.Geometry.Point(-110, 40),
                    new SuperMap.Geometry.Point(-120, 25.857),
                    new SuperMap.Geometry.Point(-140, 25.857),
                    new SuperMap.Geometry.Point(-150, 40),
                    new SuperMap.Geometry.Point(-140, 54.142)

                ],
                linearRings = new SuperMap.Geometry.LinearRing(points2),
                region = new SuperMap.Geometry.Polygon([linearRings]);

      let foramt=new SuperMap.Format.GeoJSON();
      let string_fea=foramt.write(region);  
     console.log("lineRings",linearRings)
     console.log("region",region);
      console.log(string_fea,'string_fea')

您用的示例是leaflet的,应该是没有构造成supermap.format.geojson()这个类库,建议您那边引入下这个库https://iclient.supermap.io/web/libs/iclient8c/libs/SuperMap-8.1.1-17729.js

请问下我想用本地的应该用哪个类库?
...