Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 替换';付款人';_Javascript_Openlayers 3 - Fatal编程技术网

Javascript 替换';付款人';

Javascript 替换';付款人';,javascript,openlayers-3,Javascript,Openlayers 3,我试图做的是在绘制特征后替换或更改其几何图形。e、 g:我画了一条线,画完后,我用turph.js修改几何体,在绘制的线周围创建一个缓冲区,并显示缓冲线(多边形),而不是线 var draw = new ol.interaction.Draw({ source: vectorSource, type: 'LineString' }); draw.on('drawend', function(e) { //Sending the LineString to a Turf

我试图做的是在绘制特征后替换或更改其几何图形。e、 g:我画了一条线,画完后,我用
turph.js
修改几何体,在绘制的线周围创建一个缓冲区,并显示缓冲线(多边形),而不是线

var draw = new ol.interaction.Draw({
    source: vectorSource,
    type: 'LineString'
});

draw.on('drawend', function(e) {

    //Sending the LineString to a Turf function with a buffer value and getting a Polygon in return
    var bfc = bufferedFeatureCollection(100, e.feature);

    //Replacing the LineString geometry with a Polygon geometry
    e.feature.setGeometry(bfc[0].getGeometry());

    //Removes and terminates the draw action.... 
    map.removeInteraction(this);
});
现在从
console.log()
,我可以看到
功能.geometry
已从
ol.geom.linestring
更改为
ol.geom.polygon
。但在地图上我仍然看到一条线在显示


我做错了什么?

在添加功能后进行这些修改,以便:


在功能添加到后执行这些修改,以便:


我犯的错误是,缓冲区值太低,无法被视为缓冲区,因此我只看到一条线(即使它是多边形),我必须将缓冲区值从
100增加到10000000

因此,在
draw.on('draund')
vectorSource.on('addfeature')
中,都可以替换已绘制的几何体

编辑:

为了答案的完整性。我必须将缓冲区从
100更改为10000000
的原因是,在将几何体传递给Turf函数之前,我忘记将其转换为
EPSG:4326
。Turf仅适用于
EPSG:4326

var draw = new ol.interaction.Draw({
    source: vectorSource,
    type: 'LineString'
});

draw.on('drawend', function(e) {

    e.feature.getGeometry().transform('EPSG:3857', 'EPSG:4326');

    var bfc = bufferedFeatureCollection(radius, e.feature);
    bfc[0].getGeometry().transform('EPSG:4326', 'EPSG:3857');

    e.feature.setGeometry(bfc[0].getGeometry());

    //Removes and terminates the draw action....
    map.removeInteraction(this); 
});

我犯的错误是,缓冲区值太低,无法被视为缓冲区,因此我只看到一条线(即使它是多边形),我必须将缓冲区值从
100增加到10000000

因此,在
draw.on('draund')
vectorSource.on('addfeature')
中,都可以替换已绘制的几何体

编辑:

为了答案的完整性。我必须将缓冲区从
100更改为10000000
的原因是,在将几何体传递给Turf函数之前,我忘记将其转换为
EPSG:4326
。Turf仅适用于
EPSG:4326

var draw = new ol.interaction.Draw({
    source: vectorSource,
    type: 'LineString'
});

draw.on('drawend', function(e) {

    e.feature.getGeometry().transform('EPSG:3857', 'EPSG:4326');

    var bfc = bufferedFeatureCollection(radius, e.feature);
    bfc[0].getGeometry().transform('EPSG:4326', 'EPSG:3857');

    e.feature.setGeometry(bfc[0].getGeometry());

    //Removes and terminates the draw action....
    map.removeInteraction(this); 
});

嘿,谢谢你的回复。我发现了问题所在。您的答案是正确的,我的代码也可以使用,因此在vectorSource.on('addfeature')和draw.on('draund')中都可以更改几何图形。问题是缓冲区的半径太小了,我不得不将值从100更改为10000000,以查看实际缓冲区…:谢伊,谢谢你的回复。我发现了问题所在。您的答案是正确的,我的代码也可以使用,因此在vectorSource.on('addfeature')和draw.on('draund')中都可以更改几何图形。问题是缓冲区的半径太小了,我不得不将值从100更改为10000000,以查看实际缓冲区…:s