Openlayer4 数据格式转换

wkt:

LINESTRING (106.285126 29.532158, 106.285172 29.531994, 106.285174 29.531986, 106.285295 29.53161)

geoJSON:

"geometry": {
         "type": "Polygon",
         "coordinates": [
           [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
             [100.0, 1.0], [100.0, 0.0] ]
           ]
       }

wkt转geoJSON:

 var wkt_c=new ol.format.WKT();
var geometry=wkt_c.readGeometry(wkt);
var convertor = new ol.format.GeoJSON();
var geojson=convertor.writeGeometry(geometry);

openlayer4.0数据可以不用转换使用如:

var source = new ol.source.Vector({
        features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
      });

直接指定格式就可以了,简直又蠢了一把。。。。。

转载自:https://blog.csdn.net/ZillahV06/article/details/80251373

You may also like...