1 Star 0 Fork 6

zhouluxing/leaflet-wind

forked from 刘斌/leaflet-wind 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GeometryUtil.js 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
zhouluxing 提交于 2023-10-13 14:30 . 代码提交
L.GeometryUtil = L.extend(L.GeometryUtil || {}, {
// Ported from the OpenLayers implementation. See https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Geometry/LinearRing.js#L270
geodesicArea: function (latLngs) {
var pointsCount = latLngs.length
var area = 0.0
var d2r = (Math.PI / 180)
var p1; var p2
// console.log(pointsCount+"个");
// console.log(L.LatLng.DEG_TO_RAD);
// console.log(Math.PI/180);
if (pointsCount > 2) {
for (var i = 0; i < pointsCount; i++) {
p1 = latLngs[i]
p2 = latLngs[(i + 1) % pointsCount]
area += ((p2.lng - p1.lng) * d2r) *
(2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r))
}
area = area * 6378137.0 * 6378137.0 / 2.0
}
return Math.abs(area)
},
readableArea: function (area, isMetric) {
var areaStr
if (isMetric) {
if (area >= 1000000) {
areaStr = (area * 0.000001).toFixed(2) + ' km&sup2'
} else {
areaStr = area.toFixed(2) + ' m&sup2'
}
} else {
area *= 0.836127 // Square yards in 1 meter
if (area >= 3097600) { // 3097600 square yards in 1 square mile
areaStr = (area / 3097600).toFixed(2) + ' mi&sup2;'
} else if (area >= 4840) { // 48040 square yards in 1 acre
areaStr = (area / 4840).toFixed(2) + ' acres'
} else {
areaStr = Math.ceil(area) + ' yd&sup2;'
}
}
return areaStr
},
readableDistance: function (distance, isMetric) {
var distanceStr
if (isMetric) {
// show metres when distance is < 1km, then show km
if (distance > 1000) {
distanceStr = (distance / 1000).toFixed(2) + ' km'
} else {
distanceStr = Math.ceil(distance) + ' m'
}
} else {
distance *= 1.09361
if (distance > 1760) {
distanceStr = (distance / 1760).toFixed(2) + ' miles'
} else {
distanceStr = Math.ceil(distance) + ' yd'
}
}
return distanceStr
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhouluxing/leaflet-wind.git
git@gitee.com:zhouluxing/leaflet-wind.git
zhouluxing
leaflet-wind
leaflet-wind
master

搜索帮助