Commit fa89e1e4 authored by sugita mamoru's avatar sugita mamoru

航跡を描画

parent 5bbab3e4
...@@ -12,4 +12,6 @@ enum LayerEnum: String{ ...@@ -12,4 +12,6 @@ enum LayerEnum: String{
case EcaLine case EcaLine
case SwitchingLine case SwitchingLine
case SwLineLabel case SwLineLabel
case WayPoints
case WakeLines
} }
...@@ -13,6 +13,7 @@ import UIKit ...@@ -13,6 +13,7 @@ import UIKit
struct MapRepresentable: UIViewControllerRepresentable{ struct MapRepresentable: UIViewControllerRepresentable{
@ObservedObject var ecaData = SharingData.eca @ObservedObject var ecaData = SharingData.eca
@ObservedObject var my = SharingData.my @ObservedObject var my = SharingData.my
@ObservedObject var map = SharingData.map
@State var mapVC = MapViewController() @State var mapVC = MapViewController()
func makeUIViewController(context: Context) -> some UIViewController { func makeUIViewController(context: Context) -> some UIViewController {
...@@ -36,6 +37,8 @@ struct MapRepresentable: UIViewControllerRepresentable{ ...@@ -36,6 +37,8 @@ struct MapRepresentable: UIViewControllerRepresentable{
mapVC.updateEcaSwitchingLine(center: mylocation, notice: ecaArea.swNotice, start: ecaArea.swStart, finish: ecaArea.swFinish) mapVC.updateEcaSwitchingLine(center: mylocation, notice: ecaArea.swNotice, start: ecaArea.swStart, finish: ecaArea.swFinish)
} }
} }
mapVC.updateWakeLines(legLine: map.legLine, portLine: map.portLine, starboardLine: map.starboardLine)
mapVC.updateWayPoints(points: map.wayPoints)
} }
} }
...@@ -47,6 +50,8 @@ class MapViewController : UIViewController{ ...@@ -47,6 +50,8 @@ class MapViewController : UIViewController{
var ecaLine = MapSource(layer: .EcaLine) var ecaLine = MapSource(layer: .EcaLine)
var ecaSwitchingLine = MapSource(layer: .SwitchingLine) var ecaSwitchingLine = MapSource(layer: .SwitchingLine)
var ecaSwLineLabel = MapSource(layer: .SwLineLabel) var ecaSwLineLabel = MapSource(layer: .SwLineLabel)
var wayPoints = MapSource(layer: .WayPoints)
var wakeLines = MapSource(layer: .WakeLines)
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -147,6 +152,29 @@ class MapViewController : UIViewController{ ...@@ -147,6 +152,29 @@ class MapViewController : UIViewController{
try! mapView.mapboxMap.style.addSource(ecaSwLineLabel.source, id: ecaSwLineLabel.sourceId) try! mapView.mapboxMap.style.addSource(ecaSwLineLabel.source, id: ecaSwLineLabel.sourceId)
try? mapView.mapboxMap.style.addLayer(ecaSwLabelLayer) try? mapView.mapboxMap.style.addLayer(ecaSwLabelLayer)
wakeLines.source.data = .featureCollection(FeatureCollection(features: []))
var wakeLineLayer = LineLayer(id: wakeLines.layerId)
wakeLineLayer.source = wakeLines.sourceId
wakeLineLayer.lineColor = .expression(Exp(.get) {
PropertyKey.Color.rawValue
})
try! mapView.mapboxMap.style.addSource(wakeLines.source, id: wakeLines.sourceId)
try? mapView.mapboxMap.style.addLayer(wakeLineLayer)
wayPoints.source.data = .featureCollection(FeatureCollection(features: []))
var wayPointsLayer = SymbolLayer(id: wayPoints.layerId)
wayPointsLayer.source = wayPoints.sourceId
wayPointsLayer.iconImage = .expression(Exp(.get) {
PropertyKey.IconImage.rawValue
})
wayPointsLayer.iconColor = .expression(Exp(.get) {
PropertyKey.Color.rawValue
})
try! mapView.mapboxMap.style.addSource(wayPoints.source, id: wayPoints.sourceId)
try? mapView.mapboxMap.style.addLayer(wayPointsLayer)
} }
///自船 ///自船
...@@ -239,6 +267,52 @@ class MapViewController : UIViewController{ ...@@ -239,6 +267,52 @@ class MapViewController : UIViewController{
}catch{} }catch{}
} }
func updateWakeLines(legLine: [CLLocationCoordinate2D], portLine: [CLLocationCoordinate2D], starboardLine: [CLLocationCoordinate2D]){
do{
var legLineFeature = Feature(geometry: LineString(legLine))
legLineFeature.properties = [PropertyKey.Color.rawValue: .string(Color.blue.description)]
var portLineFeature = Feature(geometry: LineString(portLine))
portLineFeature.properties = [PropertyKey.Color.rawValue: .string(Color.blue.description)]
var starboardLineFeature = Feature(geometry: LineString(starboardLine))
starboardLineFeature.properties = [PropertyKey.Color.rawValue: .string(Color.blue.description)]
try self.mapView.mapboxMap.style.updateGeoJSONSource(withId: wakeLines.sourceId, geoJSON: .featureCollection(FeatureCollection(features: [legLineFeature, portLineFeature, starboardLineFeature])))
}catch{}
}
///子午線を跨ぐ位置情報をチェックして東経ベースに補正する。
static func checkStraddleMeridian(_ locations: [CLLocationCoordinate2D]) -> [CLLocationCoordinate2D]{
let eastLon = FloatingPointSign.plus
var returnLocations : [CLLocationCoordinate2D] = []
for location in locations {
if location.longitude.sign != eastLon{
var loc = location
loc.longitude += 360
returnLocations.append(loc)
}else{
returnLocations.append(location)
}
}
return returnLocations
}
func updateWayPoints(points: [CLLocationCoordinate2D]){
do{
var wayPointsFeatures : [Feature] = []
for point in points{
var feature = Feature(geometry: Point(point))
feature.properties = [PropertyKey.IconImage.rawValue: .string(IconImage.SwFinisheBack.rawValue),
PropertyKey.Color.rawValue: .string("#EF6135")]
wayPointsFeatures.append(feature)
}
try self.mapView.mapboxMap.style.updateGeoJSONSource(withId: ecaSwLineLabel.sourceId, geoJSON: .featureCollection(FeatureCollection(features: wayPointsFeatures)))
}catch{}
}
......
...@@ -41,6 +41,7 @@ class MonitoringRoute { ...@@ -41,6 +41,7 @@ class MonitoringRoute {
point.longitude = CLLocationDegrees(legline.lon ?? 0.0) point.longitude = CLLocationDegrees(legline.lon ?? 0.0)
SharingData.map.legLine.append(point) SharingData.map.legLine.append(point)
} }
SharingData.map.legLine = MapViewController.checkStraddleMeridian(SharingData.map.legLine)
} }
SharingData.map.portLine = [] SharingData.map.portLine = []
...@@ -51,6 +52,7 @@ class MonitoringRoute { ...@@ -51,6 +52,7 @@ class MonitoringRoute {
point.longitude = CLLocationDegrees(portline.lon ?? 0.0) point.longitude = CLLocationDegrees(portline.lon ?? 0.0)
SharingData.map.portLine.append(point) SharingData.map.portLine.append(point)
} }
SharingData.map.portLine = MapViewController.checkStraddleMeridian(SharingData.map.portLine)
} }
SharingData.map.starboardLine = [] SharingData.map.starboardLine = []
...@@ -61,6 +63,7 @@ class MonitoringRoute { ...@@ -61,6 +63,7 @@ class MonitoringRoute {
point.longitude = CLLocationDegrees(starboardline.lon ?? 0.0) point.longitude = CLLocationDegrees(starboardline.lon ?? 0.0)
SharingData.map.starboardLine.append(point) SharingData.map.starboardLine.append(point)
} }
SharingData.map.starboardLine = MapViewController.checkStraddleMeridian(SharingData.map.starboardLine)
} }
} }
case .failure(let errorCode): case .failure(let errorCode):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment