我正在创建一个 Point 特征,如下所示:
const myFeature = {
"geometry": {"coordinates": [position[0], position[1]], "type": "Point"},
"type": "Feature",
"id": 'my-point-feature'
}
this.geoJSONObject['features'].push(myFeature)
这工作完美。
但是当我这样做时:
const myFeature = new Feature(new Point([position[0], position[1]]))
myFeature.setId('my-point-feature')
this.geoJSONObject['features'].push(myFeature)
我得到错误:
未捕获的类型错误:geometryReader 不是函数。 jsonfeature.js:60)
为什么会有这种行为差异?
一个GeoJSON的特征和功能的OpenLayers是不同的对象类型,使用new GeoJSON().writeFeatureObject
和new GeoJSON().readFeature
以格式之间进行转换:
const myFeature = new Feature(new Point([position[0], position[1]]))
myFeature.setId('my-point-feature')
const gjFeature = new GeoJSON().writeFeatureObject(myFeature)
this.geoJSONObject['features'].push(gjFeature)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句