首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OpenLayers读/写GeoJSON

OpenLayers读/写GeoJSON
EN

Stack Overflow用户
提问于 2020-03-31 00:29:54
回答 1查看 404关注 0票数 0

我尝试将OpenLayers地图层的要素存储到数据库中,因此我尝试将features对象写入GeoJSON对象。但是当我尝试读取对象时,我得到了一个Unsupported GeoJSON type: undefined错误。下面是我尝试过的:

代码语言:javascript
运行
复制
       const testFeature = new Feature({
          geometry: new Point([0, 0]),
          name: 'Test Point '
        });
        const geoJsonObject = new GeoJSON();
        geoJsonObject.writeFeaturesObject(testFeature);
        console.log(geoJsonObject);

        const importObject = new GeoJSON().readFeatures(geoJsonObject);
        console.log(importObject);

geoJsonObject的第一个日志:

代码语言:javascript
运行
复制
{
  "dataProjection": {
    "code_": "EPSG:4326",
    "units_": "degrees",
    "extent_": [
      -180,
      -90,
      180,
      90
    ],
    "worldExtent_": [
      -180,
      -90,
      180,
      90
    ],
    "axisOrientation_": "neu",
    "global_": true,
    "canWrapX_": true,
    "defaultTileGrid_": null,
    "metersPerUnit_": 111319.49079327358
  },
  "defaultFeatureProjection": null
}

下面是importObject日志中的错误:

代码语言:javascript
运行
复制
Unsupported GeoJSON type: undefined

OpenLayers版本: 6.2.1文档:https://openlayers.org/en/latest/apidoc/module-ol_format_GeoJSON-GeoJSON.html#writeFeature

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-31 03:46:54

除了需要writeFeaturesObject的一系列特性之外,您对geoJsonObject的使用也是错误的

代码语言:javascript
运行
复制
const geoJsonObject = new GeoJSON().writeFeaturesObject([testFeature]);
console.log(geoJsonObject);

const importObject = new GeoJSON().readFeatures(geoJsonObject);
console.log(importObject);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60935080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档