当前位置:   article > 正文

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

vue openlayers turf缓冲区

一、下载安装turf

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

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

二、使用openlayers配个turf.js

(1) 点数据的缓存

  1. //创建缓冲数据
  2. var point = turf.point([114.2058,33.2469]);
  3. var buffered = turf.buffer(point , 0.2, {units: 'kilometers'});
  4. //创建数据geojson对象和数据源对象
  5. var format = new ol.format.GeoJSON();
  6. var source =new ol.source.Vector()
  7. //读取geojson数据
  8. var a = format.readFeature(point);
  9. var b = format.readFeature(buffered);
  10. //将数据添加数据源的
  11. source.addFeature(a);
  12. source.addFeature(b);
  13. //添加图层
  14. var test= new ol.layer.Vector({source: source})
  15. map.addLayer(test);

 

(2)线数据的缓冲区

  1. //创建缓冲数据
  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]]);
  3. var buffered = turf.buffer(line , 0.2, {units: 'kilometers'});
  4. //创建数据geojson对象和数据源对象
  5. var format = new ol.format.GeoJSON();
  6. var source =new ol.source.Vector()
  7. //读取geojson数据
  8. var a = format.readFeature(line);
  9. var b = format.readFeature(buffered);
  10. //将数据添加数据源的
  11. source.addFeature(a);
  12. source.addFeature(b);
  13. //添加图层
  14. var test= new ol.layer.Vector({source: source})
  15. map.addLayer(test);

 

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

 

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

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/595106
推荐阅读
相关标签
  

闽ICP备14008679号