Coder Social home page Coder Social logo

cprpa's Introduction

cpRPA

植保无人机凸多边形地块工作路线规划

航线规划

快速使用

  1. 通过普通script标签引入,也支持cmd amd引入
  2. 根据所使用的地图类型不同,需要在使用前传入当前地图框架的一些计算方法:
/**@method 设置距离计算方法
 * @param {Function} 传入计算的函数
 * @param {Object} p1 该函数接收的第一个点,格式为{lat,lng} lat为纬度,lng为经度
 * @param {Object} p2 同上,第二个点
 */
cpRPA.setDistanceFn(function(p1,p2){
    /**以百度地图为例子,百度地图获取两经纬度点距离的方法:*/
    return new BMap.Map().getDistance(new BMap.Point(p1.lng, p1.lat), new BMap.Point(p2.lng, p2.lat));

    /** 
    * 高德地图获取两经纬度点距离的方法:
    return new AMap.LngLat(p1.lng, p1.lat).distance(new AMap.LngLat(p2.lng, p2.lat));

    * leaflet框架获取两经纬度点距离的方法
    return L.latLng(p1.lat, p1.lng).distanceTo(L.latLng(p2.lat, p2.lng))
    */
});

/**@method 设置经纬度转换成页面像素坐标的方法*/
cpRPA.setLatlng2PxFn(function(latlng){
    /**百度,map为 new BMap.Map() 对象*/
    return map.pointToPixel(new BMap.Point(latlng.lng, latlng.lat))

    /**
    * 高德,map为 new AMap.Map() 对象
    * return map.lngLatToContainer(new AMap.LngLat(latlng.lng, latlng.lat))
    *
    * leaflet map 为 L.map对象
    * return map.latLngToLayerPoint(L.latLng(latlng.lat, latlng.lng)) 
    */
});

/**@method 设置像素坐标转换成经纬度点的方法*/
cpRPA.setPx2LatlngFn(function(px){
     /**百度,map为 new BMap.Map() 对象*/
    return map.pixelToPoint(new BMap.Pixel(px[0], px[1]))

    /**
    * 高德,map为 new AMap.Map() 对象
    * return map.containerToLngLat(new AMap.Pixel(px[0], px[1]))
    * 
    * leaflet map 为 L.map对象
    *  return map.layerPointToLatLng(L.point(px[0], px[1]))
    */
});
  1. 执行.setOptions方法,获得计算完的点集
var polylineLatlngs=cpRPA.setOptions({
    polygon:[/*凸多边形顶点点集*/],
    rotate:0,
    space: 5
});
console.log(polylineLatlngs)

方法:

  • setDistanceFn
    设置距离计算方法 ,接收一个函数"function(p1,p2){return /**具体地图类型的距离计算方法*/}",必须在第一个.setOptions方法前设置。
    该传参函数的参数p1,p2为形如{lat,lng}的经纬度对象

  • setLatlng2PxFn
    设置经纬度转地图像素坐标的方法, 接收一个函数"function(latlng){return /**具体地图类型的转换方法*/}",必须在第一个.setOptions方法前设置。
    该传参函数的参数latlng为形如{lat,lng}的经纬度对象

  • setPx2LatlngFn 设置地图像素转地图像素坐标的方法, 接收一个函数"function(px){return /**具体地图类型的转换方法*/}",必须在第一个.setOptions方法前设置。
    该传参函数的参数px为形如[x,y]的像素坐标数组

  • setOptions
    设置输入参数,返回航线点集

    参数类型说明
    polygon Array 凸多边形的顶点集
    rotate Number 航线围绕地块中心点的旋转角度,顺时针为+,逆时针为-
    space Number 无人机飞行相邻两条航线距离的一半。比如说,无人机翼展为5米,则两条航线之间的合理距离为10米,则space的值为5
  • getPolygonArea 获取地块的初略面积,传入多边形地块的顶点经纬度数组,返回数值型面积值,这个面积值不是一个精确值。

    • 参数: latlngs.<Array>
    • 返回: {Number}
  • getPolylineArea 获取航线扫过的面积

    • 参数: (latlngs.<Array>,space.<Number>)
    • 返回:{Number}

demo

cprpa's People

Contributors

char-ten avatar

Watchers

taozywu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.