美文网首页
Openlayers API-GeoJSON

Openlayers API-GeoJSON

作者: 写前端的大叔 | 来源:发表于2020-02-16 20:21 被阅读0次

GeoJSON用于读取和写入geojson文件,可以通过加载文件的方式,将文件解析后,直接将数据加载到图层上,GeoJSON提供了读写文件和解析JSON的功能,一个geojson文件的格式如下所示,包括了Featuretype类型和Feature数组features,然后每一个Feature包括了几何体类型,ID值,属性信息、几何信息等。

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "id": "AFG",
        "properties": {
            "name": "Afghanistan"
        },
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [61.210817, 35.650072],
                    [62.230651, 35.270664],
                    [62.984662, 35.404041],
                    [63.193538, 35.857166],
                    [63.982896, 36.007957],
                    [61.210817, 35.650072]
                ]
            ]
        }
    }]
}

属性

  • dataProjection:数据的投影,默认为EPSG:4326
  • featureProjection:按格式读取的要素投影。
  • geometryName:几何体的名称。
  • extractGeometryName:几何体扩展名称,如果设计了该字段名,将优先读取。

方法

  • readFeature:读取单个要素。
  • readFeatures:读取要素集。
  • readGeometry:读取几何体。
  • readProjection:读取投影值 。
  • writeFeature:写入一个字符串类型的要素。
  • writeFeatureObject:写入一个对象类型的要素。
  • writeFeatures:写入要素集。
  • writeFeaturesObject:写入对象类型的要素集。
  • writeGeometry:写入几何体。
  • writeGeometryObject:写入对象类型的几何体。
    个人博客

相关文章

网友评论

      本文标题:Openlayers API-GeoJSON

      本文链接:https://www.haomeiwen.com/subject/ewmmfhtx.html