美文网首页
Map一个点的范围扩展

Map一个点的范围扩展

作者: 朱凤丽 | 来源:发表于2020-05-11 21:46 被阅读0次

一、封装通用函数

/**
 * 扩展范围函数
 * @param lonlat  {object} 经纬度对象
 * @param number  {number} 扩展范围(单位为米)
 */
let extendPolygon= (lonlat,number) =>{
    let leftX = lonlat.lon - number;
    let rightX = lonlat.lon + number;
    let topY = lonlat.lat + number;
    let bottomY = lonlat.lat - number;
    let polygon = "POLYGON(("+leftX+" "+topY+","+leftX+" "+bottomY+","+rightX+" "+bottomY+","+rightX+" "+topY+","+leftX+" "+topY+"))";
    return polygon;
};

二、使用

let lonlat = {
    lon:12620081.678926,
    lat:2647744.0245114
};
extendPolygon(lonlat,15); //POLYGON((12620066.678926 2647759.0245114,12620066.678926 2647729.0245114,12620096.678926 2647729.0245114,12620096.678926 2647759.0245114,12620066.678926 2647759.0245114))

相关文章

网友评论

      本文标题:Map一个点的范围扩展

      本文链接:https://www.haomeiwen.com/subject/nlapnhtx.html