一、封装通用函数
/**
* 扩展范围函数
* @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))
网友评论