junh_eee(이준희)
7 months ago
2 changed files with 140 additions and 192 deletions
@ -0,0 +1,112 @@
|
||||
import * as turf from '@turf/turf'; |
||||
|
||||
const handlerCoords = (latLng, buffer, angle) => { |
||||
const coords = turf.destination( |
||||
turf.point([latLng[0], latLng[1]]), |
||||
buffer / 1000, |
||||
angle, |
||||
{ units: 'kilometers' } |
||||
).geometry.coordinates; |
||||
|
||||
return coords; |
||||
}; |
||||
|
||||
const handlerLine = (id, latLng, buffer, angleArr) => { |
||||
const line = { |
||||
id: id, |
||||
type: 'Feature', |
||||
geometry: { |
||||
type: 'LineString', |
||||
coordinates: [ |
||||
handlerCoords(latLng, buffer, angleArr[0]), |
||||
handlerCoords(latLng, buffer, angleArr[1]) |
||||
] |
||||
}, |
||||
properties: { |
||||
stroke: '#000', |
||||
'stroke-width': 0.8, |
||||
'stroke-opacity': 0.7 |
||||
} |
||||
}; |
||||
return line; |
||||
}; |
||||
|
||||
export const airSquareLine = (air, map) => { |
||||
const squareLineArr = []; |
||||
const radius = air.buffer; |
||||
const position = air.center; |
||||
|
||||
let angle = 0; |
||||
let layerId = 1; |
||||
|
||||
// 사분면 선분
|
||||
for (let quadrant = 0; quadrant < 4; quadrant++) { |
||||
angle += 90; |
||||
let buffer = 0; |
||||
|
||||
// 한 면당 안쪽 가운데 선 제외하고 선분 9개
|
||||
for (let strokeCnt = 0; strokeCnt < 9; strokeCnt++) { |
||||
// 1미터 간격
|
||||
buffer += 1000; |
||||
|
||||
const coord = handlerCoords(position, buffer, angle); |
||||
|
||||
let reduce = 0; |
||||
reduce = air.reduce[strokeCnt]; |
||||
|
||||
if (angle % 180 === 0) { |
||||
const widthLine = handlerLine( |
||||
layerId++, |
||||
coord, |
||||
radius - reduce, |
||||
[90, 270] |
||||
); |
||||
squareLineArr.push(widthLine); |
||||
} else { |
||||
const lengthLine = handlerLine( |
||||
layerId++, |
||||
coord, |
||||
radius - reduce, |
||||
[0, 180] |
||||
); |
||||
squareLineArr.push(lengthLine); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// 정 가운데 선분
|
||||
const centerWidthLine = handlerLine(layerId++, position, radius, [90, 270]); |
||||
const centerLengthLine = handlerLine(layerId++, position, radius, [0, 180]); |
||||
squareLineArr.push(centerWidthLine); |
||||
squareLineArr.push(centerLengthLine); |
||||
|
||||
// map에 레이어 존재 시 삭제
|
||||
if (map.getLayer(air.title)) { |
||||
map.removeLayer(air.title); |
||||
map.removeSource(air.title); |
||||
} |
||||
|
||||
// source, layer 추가
|
||||
map.addSource(air.title, { |
||||
type: 'geojson', |
||||
data: { |
||||
type: 'FeatureCollection', |
||||
features: squareLineArr |
||||
} |
||||
}); |
||||
|
||||
map.addLayer({ |
||||
id: air.title, |
||||
type: 'line', |
||||
source: air.title, |
||||
layout: { |
||||
'line-join': 'round', |
||||
'line-cap': 'round' |
||||
}, |
||||
paint: { |
||||
'line-color': '#000', |
||||
'line-width': 0.8, |
||||
'line-opacity': 0.7 |
||||
} |
||||
}); |
||||
}; |
Loading…
Reference in new issue