|
@@ -175,7 +175,7 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
|
|
|
strokeColor = lineAndMarkerStyle.strokeColor
|
|
strokeColor = lineAndMarkerStyle.strokeColor
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let startPoint, passPoints, endPoint, pointTypeFix, dataType
|
|
|
|
|
|
|
+ let startPoint, passPoints, endPoint, pointTypeFix, dataType, airlineWidth
|
|
|
|
|
|
|
|
if (lineProps.start_point) {
|
|
if (lineProps.start_point) {
|
|
|
dataType = 2 // 下划线模式
|
|
dataType = 2 // 下划线模式
|
|
@@ -184,13 +184,15 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
|
|
|
passPoints = lineProps['passing_points']
|
|
passPoints = lineProps['passing_points']
|
|
|
endPoint = lineProps['end_point']
|
|
endPoint = lineProps['end_point']
|
|
|
pointTypeFix = 'point_type';
|
|
pointTypeFix = 'point_type';
|
|
|
|
|
+ airlineWidth = parseInt(lineProps['airline_width'], 10)
|
|
|
} else {
|
|
} else {
|
|
|
dataType = 1 // 驼峰模式
|
|
dataType = 1 // 驼峰模式
|
|
|
|
|
|
|
|
startPoint = lineProps['dep']
|
|
startPoint = lineProps['dep']
|
|
|
passPoints = lineProps['passPoints']
|
|
passPoints = lineProps['passPoints']
|
|
|
endPoint = lineProps['arrive']
|
|
endPoint = lineProps['arrive']
|
|
|
- pointTypeFix = 'pointType'
|
|
|
|
|
|
|
+ pointTypeFix = 'pointType'
|
|
|
|
|
+ airlineWidth = parseInt(lineProps['airlineWidth'], 10)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (startPoint) {
|
|
if (startPoint) {
|
|
@@ -234,16 +236,121 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
|
|
|
if (coordinates.length > 1) {
|
|
if (coordinates.length > 1) {
|
|
|
lines.push({lineWidth, strokeColor, coordinates});
|
|
lines.push({lineWidth, strokeColor, coordinates});
|
|
|
}
|
|
}
|
|
|
|
|
+ lines = combineLines(lines)
|
|
|
|
|
+ if(airlineWidth > 0) {
|
|
|
|
|
+ // 有宽度的空域,需要线周围多画宽度的多边形
|
|
|
|
|
+ let polygons = processAirlineWidth(lines, airlineWidth)
|
|
|
|
|
+ return { lines, markers, polygons };
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return { lines, markers, polygons: [] };
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function combineLines(lines) {
|
|
|
|
|
+ // 合并线段,如果前后两个线段之间有交接,那就合并成一个
|
|
|
|
|
+ // 这样操作之后,lines 就只有不交接的线段了
|
|
|
|
|
+ let combinedLines = []
|
|
|
|
|
+ combinedLines.push(lines[0])
|
|
|
|
|
+ for(let i=1; i<lines.length; i++) {
|
|
|
|
|
+ let prevLine = lines[i-1]
|
|
|
|
|
+ let line = lines[i]
|
|
|
|
|
+ if(isLineConnect(prevLine, line)) {
|
|
|
|
|
+ let lastIdx = combinedLines.length-1
|
|
|
|
|
+ let lastLine = combinedLines[lastIdx]
|
|
|
|
|
+ let points = line.coordinates.slice()
|
|
|
|
|
+ points.splice(0, 1) //移除第一个点
|
|
|
|
|
+ combinedLines[lastIdx].coordinates = [... lastLine.coordinates, ...points]
|
|
|
|
|
+ } else {
|
|
|
|
|
+ combinedLines.push(line)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return combinedLines
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getFixedLatLng(point) {
|
|
|
|
|
+ let lat = point.latitude ? point.latitude : point.lat
|
|
|
|
|
+ let lng = point.longitude ? point.longitude : point.lng
|
|
|
|
|
+ return [lat, lng]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function processAirlineWidth(lines, airlineWidth) {
|
|
|
|
|
+ let polygons = []
|
|
|
|
|
+
|
|
|
|
|
+ for(let line of lines) {
|
|
|
|
|
+ let points = line.coordinates
|
|
|
|
|
+ let coordinates = []
|
|
|
|
|
+ let lastBearing = null
|
|
|
|
|
+ for(let i=0; i<points.length; i++) {
|
|
|
|
|
+ let [lat1, lng1] = getFixedLatLng(points[i])
|
|
|
|
|
+ let point = new LatLon(lat1, lng1)
|
|
|
|
|
+ let nextPoint = null
|
|
|
|
|
+ let bearing = lastBearing
|
|
|
|
|
+ if(i < points.length-1) {
|
|
|
|
|
+ let [lat2, lng2] = getFixedLatLng(points[i+1])
|
|
|
|
|
+ nextPoint = new LatLon(lat2, lng2)
|
|
|
|
|
+ bearing = point.bearingTo(nextPoint)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let [leftPoint, rightPoint] = getBearingPoint(point, lastBearing, bearing, airlineWidth)
|
|
|
|
|
+ coordinates.splice(0, 0, {lat: leftPoint.lat, lng: leftPoint.lon}) // add top
|
|
|
|
|
+ coordinates.push({lat: rightPoint.lat, lng: rightPoint.lon}) // add bottom
|
|
|
|
|
+ lastBearing = bearing
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let {imageName, lineWidth, strokeColor, fillColor} = getDefaultStyle()
|
|
|
|
|
+ polygons.push({lineWidth, strokeColor, fillColor, coordinates});
|
|
|
|
|
+ }
|
|
|
|
|
+ return polygons
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getBearingPoint(point, lastBearing, bearing, airlineWidth) {
|
|
|
|
|
+ if(!lastBearing)
|
|
|
|
|
+ lastBearing = bearing
|
|
|
|
|
|
|
|
- return { lines, markers };
|
|
|
|
|
|
|
+ let halfAngle = (180 - bearing + lastBearing)/2 // 两条线的夹角的一半
|
|
|
|
|
+ let rightBearing = bearing + halfAngle
|
|
|
|
|
+ let leftBearing = 180 + rightBearing
|
|
|
|
|
+
|
|
|
|
|
+ /* let fixAngle = Math.abs(halfAngle) > 180 ? Math.abs(halfAngle) : halfAngle
|
|
|
|
|
+ * let leftWidth = airlineWidth/Math.sin(fixAngle)
|
|
|
|
|
+ * let rightWidth = airlineWidth/Math.sin(fixAngle)
|
|
|
|
|
+ * console.log('width is', airlineWidth, leftWidth, rightWidth, fixAngle, halfAngle) */
|
|
|
|
|
+
|
|
|
|
|
+ let leftWidth = airlineWidth
|
|
|
|
|
+ let rightWidth = airlineWidth
|
|
|
|
|
+
|
|
|
|
|
+ let leftPoint = point.destinationPoint(leftWidth, leftBearing)
|
|
|
|
|
+ let rightPoint = point.destinationPoint(rightWidth, rightBearing)
|
|
|
|
|
+ return [leftPoint, rightPoint]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function isLineConnect(line1, line2) {
|
|
|
|
|
+ // 判断 line1 的终点和 line2 的起点是否相同
|
|
|
|
|
+ let line1LastPoint = line1.coordinates[line1.coordinates.length -1]
|
|
|
|
|
+ let line2FirstPoint = line2.coordinates[0]
|
|
|
|
|
+
|
|
|
|
|
+ let [line1lat, line1lng] = getFixedLatLng(line1LastPoint)
|
|
|
|
|
+ let [line2lat, line2lng] = getFixedLatLng(line2FirstPoint)
|
|
|
|
|
+
|
|
|
|
|
+ let precision = 9 // 比较的精度,经纬度会被经过度分秒方式到浮点方式的转化
|
|
|
|
|
+
|
|
|
|
|
+ if(line1lat.toFixed(precision) == line2lat.toFixed(precision)
|
|
|
|
|
+ && line1lng.toFixed(precision) == line2lng.toFixed(precision)) {
|
|
|
|
|
+ return true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+function getPolygonFromLine(line, airlineWidth) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
|
|
|
|
|
|
|
+function getLinesPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
|
|
|
let retLines = [];
|
|
let retLines = [];
|
|
|
let retMarkers = [];
|
|
let retMarkers = [];
|
|
|
|
|
+ let retPolygons = [];
|
|
|
if (!Array.isArray(airspaceInfos)) {
|
|
if (!Array.isArray(airspaceInfos)) {
|
|
|
- return { lines: retLines, markers: retMarkers };
|
|
|
|
|
|
|
+ return { lines: retLines, markers: retMarkers, polygons: retPolygons };
|
|
|
}
|
|
}
|
|
|
let lineStyle = setStyle('line');
|
|
let lineStyle = setStyle('line');
|
|
|
for (let i = 0; i < airspaceInfos.length; i++) {
|
|
for (let i = 0; i < airspaceInfos.length; i++) {
|
|
@@ -254,22 +361,23 @@ function getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
|
|
|
else
|
|
else
|
|
|
airspaceTypeFix = 'airspace_type';
|
|
airspaceTypeFix = 'airspace_type';
|
|
|
if (tmpLine[airspaceTypeFix] == Global.airspaceType.line && currentAirspaceIndex != i) {
|
|
if (tmpLine[airspaceTypeFix] == Global.airspaceType.line && currentAirspaceIndex != i) {
|
|
|
- let { lines, markers } = getLinesRouter(tmpLine, lineStyle);
|
|
|
|
|
|
|
+ let { lines, markers, polygons } = getLinesRouter(tmpLine, lineStyle);
|
|
|
retMarkers.push(...markers);
|
|
retMarkers.push(...markers);
|
|
|
retLines.push(...lines);
|
|
retLines.push(...lines);
|
|
|
|
|
+ retPolygons.push(...polygons)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return { lines: retLines, markers: retMarkers };
|
|
|
|
|
|
|
+ return { lines: retLines, markers: retMarkers, polygons: retPolygons };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-function getLineAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
|
|
|
|
|
|
|
+function getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
|
|
|
return createSelector(
|
|
return createSelector(
|
|
|
airspaceInfos,
|
|
airspaceInfos,
|
|
|
() => setStyle,
|
|
() => setStyle,
|
|
|
currentAirspaceIndex,
|
|
currentAirspaceIndex,
|
|
|
- getLinesAndMarkers
|
|
|
|
|
|
|
+ getLinesPolygonsAndMarkers
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -402,13 +510,14 @@ function getLineSelector(lineAndMarker) {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function getPolygons(polygonAndMarkers) {
|
|
|
|
|
- return polygonAndMarkers.polygons;
|
|
|
|
|
|
|
+function getPolygons(polygonAndMarkers, linePolygonsAndMarkers) {
|
|
|
|
|
+ return [...polygonAndMarkers.polygons, ...linePolygonsAndMarkers.polygons];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function getPolygonSelector(polygonAndMarkers) {
|
|
|
|
|
|
|
+function getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers) {
|
|
|
return createSelector(
|
|
return createSelector(
|
|
|
polygonAndMarkers,
|
|
polygonAndMarkers,
|
|
|
|
|
+ linePolygonsAndMarkers,
|
|
|
getPolygons
|
|
getPolygons
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -424,12 +533,12 @@ let setStyle = (style) => {
|
|
|
export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
|
|
export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
|
|
|
currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
|
|
currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
|
|
|
let circles = getCircleSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
|
|
let circles = getCircleSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
|
|
|
- let lineAndMarkers = getLineAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
|
|
|
|
|
- let lines = getLineSelector(lineAndMarkers);
|
|
|
|
|
|
|
+ let linePolygonsAndMarkers = getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
|
|
|
|
|
+ let lines = getLineSelector(linePolygonsAndMarkers);
|
|
|
let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
|
|
let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
|
|
|
- let polygons = getPolygonSelector(polygonAndMarkers);
|
|
|
|
|
- let markers = getMarkerSelector(polygonAndMarkers, lineAndMarkers);
|
|
|
|
|
- let regionPoints = getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers);
|
|
|
|
|
|
|
+ let polygons = getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers);
|
|
|
|
|
+ let markers = getMarkerSelector(polygonAndMarkers, linePolygonsAndMarkers);
|
|
|
|
|
+ let regionPoints = getRegionPointsSelector(circles, linePolygonsAndMarkers, polygonAndMarkers);
|
|
|
return {
|
|
return {
|
|
|
markers,
|
|
markers,
|
|
|
circles,
|
|
circles,
|