日照项目的居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.7 KiB

const cuizhuyuanPolygons = [[120.38991958, 36.29482584], [120.38965181, 36.29242696], [120.39158754, 36.2924393], [120.39187063, 36.29248247], [120.39252097, 36.29333965], [120.39285763, 36.29353082], [120.39313307, 36.29359866], [120.39314837, 36.29472101], [120.38991958, 36.29482584]]
const zhongchenglu120 = [[120.38813398, 36.29267429], [120.38773983, 36.29117054], [120.38933396, 36.29109289], [120.38943907, 36.29265311], [120.38813398, 36.29267429]]
const furongyuan = [[120.3907624, 36.29902493], [120.39019075, 36.2957125], [120.39029118, 36.2955008], [120.39313413, 36.29532646], [120.39319593, 36.2963725], [120.39226888, 36.29645967], [120.39182081, 36.29678344], [120.39161222, 36.29733137], [120.39196758, 36.29799136], [120.3926088, 36.29815324], [120.39322683, 36.29810966], [120.39324228, 36.29922417], [120.39101734, 36.29924908], [120.3907624, 36.29902493]]
const huachenglu1 = [[120.38679253, 36.29736561], [120.38677627, 36.2968675], [120.38718288, 36.29564844], [120.38969567, 36.29550425], [120.38996402, 36.29575986], [120.39027304, 36.29725419], [120.38679253, 36.29736561]]
const jinrixiaoqu = [[120.38975687, 36.29816328], [120.38968258, 36.29761918], [120.39013157, 36.29759575], [120.39028339, 36.29815807], [120.38975687, 36.29816328]]
const huachenglu2 = [[120.38714981, 36.30193872], [120.38710666, 36.30093002], [120.39055402, 36.30086915], [120.39051626, 36.30235611], [120.38873592, 36.30237351], [120.38873053, 36.30192133], [120.38714981, 36.30193872]]
const meiguiyuan = [[120.390775, 36.3024502], [120.39074464, 36.2994554], [120.39328611, 36.29940644], [120.39334686, 36.30241756], [120.390775, 36.3024502]]
const qingfulou = [[120.38727920717822, 36.300516530135205], [120.38723040717822, 36.29958376013521], [120.38773937717822, 36.299555670135206], [120.38778120717822, 36.300505290135206], [120.38727920717822, 36.300516530135205]]
// dataV获取边界数据转换为小程序地图多边形使用数据
const pushData = polygonsArray => {
const arr = []
polygonsArray.forEach(item => {
let point = {
longitude: item[0],
latitude: item[1]
}
arr.push(point)
})
return arr
}
const places = [
{
id: 100,
name: 'cuizhuyuan',
points: pushData(cuizhuyuanPolygons),
strokeColor: '#d20202f2',
fillColor: '#d202023d',
marker: [120.39065242, 36.29369167],
label: '翠竹苑',
labelFillColor: '#ec4504a8'
},
{
id: 101,
name: 'zhongchenglu120',
points: pushData(zhongchenglu120),
strokeColor: '#d20202f2',
fillColor: '#d202023d',
marker: [120.3887047, 36.2919985],
label: '中城路120号',
labelFillColor: '#ec4504a8'
},
{
id: 102,
name: 'furongyuan',
points: pushData(furongyuan),
strokeColor: '#2be7fdf2',
fillColor: '#2be7fd40',
marker: [120.3913773, 36.29654178],
label: '芙蓉苑',
labelFillColor: '#0092eebf'
},
{
id: 103,
name: 'huachenglu1',
points: pushData(huachenglu1),
strokeColor: '#2be7fdf2',
fillColor: '#2be7fd40',
marker: [120.38871706, 36.29666622],
label: '华城路1小区',
labelFillColor: '#0092eebf'
},
{
id: 107,
name: 'jinrixiaoqu',
points: pushData(jinrixiaoqu),
strokeColor: '#2be7fdf2',
fillColor: '#2be7fd40',
marker: [120.38993211, 36.29793679],
label: '今日小区',
labelFillColor: '#0092eebf'
},
{
id: 104,
name: 'huachenglu2',
points: pushData(huachenglu2),
strokeColor: '#b7b900f2',
fillColor: '#b7b90029',
marker: [120.3886075, 36.30210927],
label: '华城路2小区',
labelFillColor: '#ee9700cc'
},
{
id: 105,
name: 'meiguiyuan',
points: pushData(meiguiyuan),
strokeColor: '#b7b900f2',
fillColor: '#b7b90029',
marker: [120.39206791, 36.30168531],
label: '玫瑰苑',
labelFillColor: '#ee9700cc'
},
{
id: 106,
name: 'qingfulou',
points: pushData(qingfulou),
strokeColor: '#b7b900f2',
fillColor: '#b7b90029',
marker: [120.38750634, 36.29999986],
label: '青福楼小区',
labelFillColor: '#ee9700cc'
}
]
// 判断是否在某个多边形内
function isInPolygon(point, points) {
var n = points.length
var nCross = 0
for (let i = 0; i < n; i++) {
var p1 = points[i]
var p2 = points[(i + 1) % n]
// 求解 y=p.y 与 p1 p2 的交点
// p1p2 与 y=p0.y平行
if (p1.longitude == p2.longitude)
continue
// 交点在p1p2延长线上
if (point.longitude < Math.min(p1.longitude, p2.longitude))
continue
// 交点在p1p2延长线上
if (point.longitude >= Math.max(p1.longitude, p2.longitude))
continue
// 求交点的 X 坐标
var x = (point.longitude - p1.longitude) * (p2.latitude - p1.latitude) / (p2.longitude - p1.longitude) + p1.latitude
// 只统计单边交点
if (x > point.latitude)
nCross++
}
return (nCross % 2 == 1)
}
// 返回多边形数据
const getPolygonsDatas = () => {
return places
}
// 选中多边形,返回选中对象
function isSelectPolygon(point) {
let selectPolygon = {}
places.forEach(item => {
if (isInPolygon(point, item.points)) {
selectPolygon = item
}
})
return selectPolygon
}
module.exports = {
getPolygonsDatas,
isSelectPolygon
}