gpt4 book ai didi

angularjs - 错误类型错误 : Cannot read property 'Point' of undefined, openlayers 3 & jsts - 服务器端

转载 作者:搜寻专家 更新时间:2023-10-30 22:00:14 25 4
gpt4 key购买 nike

我正在尝试关注 this example为了缓冲 map 上绘制的一些特征。

但是,这给了我以下错误:

ERROR TypeError: Cannot read property 'Point' of undefined

这是我的代码:

BufferFeature(feature){
var parser = new jsts.io.OL3Parser();
let format = new ol.format.WKT();
// convert the OpenLayers geometry to a JSTS geometry
var jstsGeom = parser.read(format.writeGeometry(feature.getGeometry()));

// create a buffer of 40 meters around each line
var buffered = jstsGeom.buffer(40);

// convert back from JSTS and replace the geometry on the feature
feature.setGeometry(parser.write(buffered));
let source = this.VectorOverlay.getSource();
source.addFeatures(feature);
}

有人能找出我哪里出错了吗?

最佳答案

我终于用OL3Parse的inject方法解决了这个问题。你的代码应该是这样的:

    var Geojson = require('ol/format/geojson');
var Vector = require('ol/source/vector');
var Feature = require('ol/feature');
var LineString = require('ol/geom/linestring');
var Point = require('ol/geom/point');
var jsts = require('jsts');

var ol3Parser = new jsts.io.OL3Parser();
ol3Parser.inject(Point, LineString);

BufferFeature(feature){
let format = new ol.format.WKT();
// convert the OpenLayers geometry to a JSTS geometry
var jstsGeom = ol3Parser.read(format.writeGeometry(feature.getGeometry()));

// create a buffer of 40 meters around each line
var buffered = jstsGeom.buffer(40);

// convert back from JSTS and replace the geometry on the feature
feature.setGeometry(parser.write(buffered));
let source = this.VectorOverlay.getSource();
source.addFeatures(feature);
}

这适用于:

 function inject(Point, LineString, LinearRing, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection) {};

关于angularjs - 错误类型错误 : Cannot read property 'Point' of undefined, openlayers 3 & jsts - 服务器端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45146569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com