Commit f1b96f97 authored by sugita mamoru's avatar sugita mamoru

マップ表示処理追加

parent 86fc559a
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "swFinishBack.png",
"idiom" : "universal",
"resizing" : {
"cap-insets" : {
"bottom" : 5,
"left" : 5,
"right" : 5,
"top" : 5
},
"center" : {
"height" : 1,
"mode" : "tile",
"width" : 1
},
"mode" : "9-part"
},
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "swNoticeBack.png",
"idiom" : "universal",
"resizing" : {
"cap-insets" : {
"bottom" : 5,
"left" : 5,
"right" : 5,
"top" : 5
},
"center" : {
"height" : 1,
"mode" : "tile",
"width" : 1
},
"mode" : "9-part"
},
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "swStartBack.png",
"idiom" : "universal",
"resizing" : {
"cap-insets" : {
"bottom" : 5,
"left" : 5,
"right" : 5,
"top" : 5
},
"center" : {
"height" : 1,
"mode" : "tile",
"width" : 1
},
"mode" : "9-part"
},
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -10,7 +10,7 @@ import CoreLocation
struct RegisteredEca {
var id: UInt32 = 0
var isEnable: Bool = false //ECA有効
var isEnable: Bool = true //ECA有効
var isRunning: Bool = false //ECA実行中
var name: String = "" //ECA名称
var swNotice: Float = 6 //ECA通知[NM]
......
......@@ -344,18 +344,6 @@ class LocationCalculation{
}
}
///
///自船の周囲5NMより外にいるか
///外→true
///内→false
static func isOutOf5nm(lat: Double, lon: Double) -> Bool {
let myLat = SharingData.My.location?.latitude ?? 0
let mylon = SharingData.My.location?.longitude ?? 0
let distance = distance(posAlat: lat, posAlon: lon, posBlat: myLat, posBlon: mylon)
return distance/nm > 5
}
///時計回りか
///return: 1 -> 時計回り
/// -1 -> 反時計回り
......
......@@ -10,4 +10,6 @@ import Foundation
enum LayerEnum: String{
case OwnShip
case EcaLine
case SwitchingLine
case SwLineLabel
}
......@@ -19,9 +19,18 @@ struct MapRepresentable: UIViewControllerRepresentable{
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
if let ecaArea = sharingData.ecaArea.map{ $0.1 }.filter{ $0.isRunning }.first{
let ecaArea = sharingData.ecaArea.map{ $0.1 }.filter{ $0.isRunning }.first
if let ecaArea = ecaArea{
mapVC.updateEcaLine(line: ecaArea.points)
}
if let mylocation = sharingData.location {
mapVC.updateOwnShip(location: mylocation, bearing: sharingData.bearing)
if let ecaArea = ecaArea{
mapVC.updateEcaSwitchingLine(center: mylocation, notice: ecaArea.swNotice, start: ecaArea.swStart, finish: ecaArea.swFinish)
}
}
}
}
......@@ -31,6 +40,8 @@ class MapViewController : UIViewController{
var ownShipSymbol = MapSource(layer: .OwnShip)
var ecaLine = MapSource(layer: .EcaLine)
var ecaSwitchingLine = MapSource(layer: .SwitchingLine)
var ecaSwLineLabel = MapSource(layer: .SwLineLabel)
override func viewDidLoad() {
super.viewDidLoad()
......@@ -51,9 +62,26 @@ class MapViewController : UIViewController{
}
func addImage(){
do{
if let image = UIImage(named: "account"){
try mapView.mapboxMap.style.addImage(image, id: IconImage.OwnShip.rawValue)
}
if let image = UIImage(named: "swNoticeBack"){
try mapView.mapboxMap.style.addImage(image, id: IconImage.SwNoticeBack.rawValue)
}
if let image = UIImage(named: "swStartBack"){
try mapView.mapboxMap.style.addImage(image, id: IconImage.SwStartBack.rawValue)
}
if let image = UIImage(named: "swFinishBack"){
try mapView.mapboxMap.style.addImage(image, id: IconImage.SwFinisheBack.rawValue)
}
}catch{}
}
func addLayers(){
try! mapView.mapboxMap.style.addImage(UIImage(named: "account")!, id: IconImage.OwnShip.rawValue)
addImage()
let point = Point(LocationCoordinate2D(latitude: 0, longitude: 0))
var feature = Feature(geometry: point)
......@@ -87,14 +115,108 @@ class MapViewController : UIViewController{
try! mapView.mapboxMap.style.addSource(ecaLine.source, id: ecaLine.sourceId)
try? mapView.mapboxMap.style.addLayer(ecaLineLayer)
ecaSwitchingLine.source.data = .featureCollection(FeatureCollection(features: []))
var ecaSwitchingLineLayer = LineLayer(id: ecaSwitchingLine.layerId)
ecaSwitchingLineLayer.source = ecaSwitchingLine.sourceId
ecaSwitchingLineLayer.lineColor = .expression(Exp(.get) {
PropertyKey.Color.rawValue
})
ecaSwitchingLineLayer.lineDasharray = .constant([2,1])
try! mapView.mapboxMap.style.addSource(ecaSwitchingLine.source, id: ecaSwitchingLine.sourceId)
try? mapView.mapboxMap.style.addLayer(ecaSwitchingLineLayer)
ecaSwLineLabel.source.data = .featureCollection(FeatureCollection(features: []))
var ecaSwLabelLayer = SymbolLayer(id: ecaSwLineLabel.layerId)
ecaSwLabelLayer.source = ecaSwLineLabel.sourceId
ecaSwLabelLayer.textField = .expression(Exp(.get) {
PropertyKey.Text.rawValue
})
ecaSwLabelLayer.iconImage = .expression(Exp(.get) {
PropertyKey.IconImage.rawValue
})
ecaSwLabelLayer.iconColor = .expression(Exp(.get) {
PropertyKey.Color.rawValue
})
ecaSwLabelLayer.iconTextFit = .constant(.both)
ecaSwLabelLayer.iconTextFitPadding = .constant([0,6,0,6])
try! mapView.mapboxMap.style.addSource(ecaSwLineLabel.source, id: ecaSwLineLabel.sourceId)
try? mapView.mapboxMap.style.addLayer(ecaSwLabelLayer)
}
func updateOwnShip(location: CLLocationCoordinate2D){
var geoJSON = Feature(geometry: Point(location))
geoJSON.properties = [PropertyKey.Bearing.rawValue: .number(90),
PropertyKey.IconImage.rawValue: .string(IconImage.OwnShip.rawValue)]
try! self.mapView.mapboxMap.style.updateGeoJSONSource(withId: self.ownShipSymbol.sourceId,
geoJSON: .feature(geoJSON))
func updateOwnShip(location: CLLocationCoordinate2D, bearing: Double){
do {
var geoJSON = Feature(geometry: Point(location))
geoJSON.properties = [PropertyKey.Bearing.rawValue: .number(bearing),
PropertyKey.IconImage.rawValue: .string(IconImage.OwnShip.rawValue)]
try self.mapView.mapboxMap.style.updateGeoJSONSource(withId: self.ownShipSymbol.sourceId, geoJSON: .feature(geoJSON))
}catch{}
}
func updateEcaSwitchingLine(center: CLLocationCoordinate2D, notice: Float, start: Float, finish: Float){
do{
var switchingLines : [Feature] = []
var switchingLabels : [Feature] = []
let circlePoints_notice = getCirclePoints(center: center, radiusKm: LocationCalculation.nm2km(nm: Double(notice)))
var noticeLine = Feature(geometry: LineString(circlePoints_notice))
noticeLine.properties = [PropertyKey.Color.rawValue: .string("#62AB28")]
switchingLines.append(noticeLine)
if let point = circlePoints_notice.first{
var label = Feature(geometry: Point(point))
label.properties = [PropertyKey.Text.rawValue: .string("Advance Notice"),
PropertyKey.IconImage.rawValue: .string(IconImage.SwNoticeBack.rawValue),
PropertyKey.Color.rawValue: .string("#62AB28")]
switchingLabels.append(label)
}
let circlePoints_start = getCirclePoints(center: center, radiusKm: LocationCalculation.nm2km(nm: Double(start)))
var startLine = Feature(geometry: LineString(circlePoints_start))
startLine.properties = [PropertyKey.Color.rawValue: .string("#ECD932")]
switchingLines.append(startLine)
if let point = circlePoints_start.first{
var label = Feature(geometry: Point(point))
label.properties = [PropertyKey.Text.rawValue: .string("Switching Start"),
PropertyKey.IconImage.rawValue: .string(IconImage.SwStartBack.rawValue),
PropertyKey.Color.rawValue: .string("#ECD932")]
switchingLabels.append(label)
}
let circlePoints_finish = getCirclePoints(center: center, radiusKm: LocationCalculation.nm2km(nm: Double(finish)))
var finishLine = Feature(geometry: LineString(circlePoints_finish))
finishLine.properties = [PropertyKey.Color.rawValue: .string("#EF6135")]
switchingLines.append(finishLine)
if let point = circlePoints_finish.first{
var label = Feature(geometry: Point(point))
label.properties = [PropertyKey.Text.rawValue: .string("Switching Finish"),
PropertyKey.IconImage.rawValue: .string(IconImage.SwFinisheBack.rawValue),
PropertyKey.Color.rawValue: .string("#EF6135")]
switchingLabels.append(label)
}
var lineGeoJson = FeatureCollection(features: switchingLines)
var labelGeoJson = FeatureCollection(features: switchingLabels)
try self.mapView.mapboxMap.style.updateGeoJSONSource(withId: ecaSwitchingLine.sourceId, geoJSON: .featureCollection(lineGeoJson))
try self.mapView.mapboxMap.style.updateGeoJSONSource(withId: ecaSwLineLabel.sourceId, geoJSON: .featureCollection(labelGeoJson))
}catch{}
}
///円の位置情報を返す
private func getCirclePoints(center: CLLocationCoordinate2D, radiusKm: Double) -> [CLLocationCoordinate2D]{
var circlePoints : [CLLocationCoordinate2D] = []
for deg in stride(from: 0, through: 360, by: 6) {
let point = LocationCalculation.findPointAtDistanceFrom(
startPointLat: center.latitude,
startPointLon: center.longitude,
initialBearing: Double(deg),
distanceKilometers: radiusKm
)
circlePoints.append(point)
}
return circlePoints
}
......@@ -104,9 +226,7 @@ class MapViewController : UIViewController{
geoJson.properties = [PropertyKey.Color.rawValue: .string(Color.blue.description)]
try self.mapView.mapboxMap.style.updateGeoJSONSource(withId: ecaLine.sourceId, geoJSON: .feature(geoJson))
}catch{
}
}catch{}
}
......@@ -116,10 +236,14 @@ class MapViewController : UIViewController{
case IconImage
case Bearing
case Color
case Text
}
enum IconImage: String, CaseIterable{
case OwnShip
case SwNoticeBack
case SwStartBack
case SwFinisheBack
}
}
......@@ -10,19 +10,18 @@ import CoreLocation
class SharingData: ObservableObject{
static let shared = SharingData()
class My{
static var location: CLLocationCoordinate2D? = nil
static var speedKnot: Double = 0.0
static var bearing: Double = 0.0 // 自船進行方向
static var compass: Double? = nil // 端末の方位
@Published var location: CLLocationCoordinate2D? = CLLocationCoordinate2D(latitude: 0, longitude: 0)//nil
@Published var speedKnot: Double = 0.0
@Published var bearing: Double = 0.0 // 自船進行方向
@Published var compass: Double? = nil // 端末の方位
static func reset() {
location = nil
speedKnot = 0.0
bearing = 0.0
}
func reset() {
location = nil
speedKnot = 0.0
bearing = 0.0
}
/**
* Eca
*/
......
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