openlayers+turf.js实现缓冲区的绘制

一、下载安装turf

下载地址:https://github.com/Turfjs/turf

api和示例地址:http://turfjs.org/docs/

二、使用openlayers配个turf.js

(1) 点数据的缓存

//创建缓冲数据
var point =  turf.point([114.2058,33.2469]);
var buffered = turf.buffer(point , 0.2, {units: 'kilometers'});
//创建数据geojson对象和数据源对象
var format = new ol.format.GeoJSON();
var source =new ol.source.Vector()
//读取geojson数据
var a = format.readFeature(point);
var b = format.readFeature(buffered);
//将数据添加数据源的
source.addFeature(a);
source.addFeature(b);
//添加图层
var test= new ol.layer.Vector({source: source})
map.addLayer(test);

 

(2)线数据的缓冲区

//创建缓冲数据
var line =  turf.lineString([[114.2058,33.2469],[114.1715,33.2443],[114.1735,33.2271],[114.2085,33.2257],[114.2058,33.2469]]);
var buffered = turf.buffer(line , 0.2, {units: 'kilometers'});
//创建数据geojson对象和数据源对象
var format = new ol.format.GeoJSON();
var source =new ol.source.Vector()
//读取geojson数据
var a = format.readFeature(line);
var b = format.readFeature(buffered);
//将数据添加数据源的
source.addFeature(a);
source.addFeature(b);
//添加图层
var test= new ol.layer.Vector({source: source})
map.addLayer(test);

 

(3)面数据的缓冲区的分析

 

//创建缓冲数据
var py =  turf.polygon([[[114.2058,33.2469],[114.1715,33.2443],[114.1735,33.2271],[114.2085,33.2257],[114.2058,33.2469]]]);
var buffered = turf.buffer(py , 0.2, {units: 'kilometers'});
//创建数据geojson对象和数据源对象
var format = new ol.format.GeoJSON();
var source =new ol.source.Vector()
//读取geojson数据
var a = format.readFeature(py );
var b = format.readFeature(buffered);
//将数据添加数据源的
source.addFeature(a);
source.addFeature(b);
//添加图层
var test= new ol.layer.Vector({source: source})
map.addLayer(test);

 

 

  • 1
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值